Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis Notes-Hash data Type (3)

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Hash is a mapping table for field and value of type string. Its add and delete operations are both 0 (1) (average). Hash is particularly suitable for storing objects. Compared to storing each field of an object as a single string type, storing an object in a hash type takes up less memory and makes it easier to access the entire object.

Hset

Set hash field to the specified value. If key does not exist, create it first.

127.0.0.1 lijie 6379 > hset user:001 name lijie (integer) 1127.0.0.1 hget user:001 name "lijie" hsetnx

Set hash field to the specified value, and create it first if key does not exist. Returns 0 if it exists

127.0.0.1 hset user:001 name lijie (integer) 1127.0.0.1 hget user:001 name "lijie" 127.0.0.1 hget user:001 name 6379 > hset user:001 sex men (integer) 1127.0.0.1 hget user:001 name 6379 > hset user:001 sex women (integer)

Set multiple field of hash simultaneously

Hmget user:002 name1) "chenxl" 127.0.0.1 sex menOK127.0.0.1:6379 > hmget user:002 name age sex1) "chenxl" 2) "30" 3) "men" hget

Get a field in the hash table

127.0.0.1 hmget 6379 > hget user:002 name "chenxl"

Gets the values of all specified multiple hash field

127.0.0.1 men 6379 > hmget user:002 name age sex1) "chenxl" 2) "30" 3) "men" hincrby

Specified hash field plus specified value

127.0.0.1 25hexists 6379 > hincrby user:002 age-5 (integer)

Test whether the specified field exists

127.0.0.1 hexists user:002 sex 6379 > hexists user:002 wang (integer) 0127.0.0.1 hexists user:002 sex (integer) 1hlen

Returns the number of field of the specified hash

127.0.0.1 3hdel 6379 > hlen user:002 (integer)

Delete the field of the specified hash

127.0.0.1 hget user:002 age 6379 > hget user:002 age "25" 127.0.0.1 integer 6379 > hget user:002 age (nil) hkeys

Returns all field of hash

127.0.1 sex 6379 > hkeys user:0021) "name" 2) "sex" hvals

Returns all value of hash

127.0.1 men 6379 > hvals user:0021) "chenxl" 2) "men" hgetall

Get all the field and value of a hash

127.0.1 chenxl 6379 > hgetall user:0021) "name" 2) "chenxl" 3) "sex" 4) "men"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report