hash of redis data type

Redis's hash is a mapping table of string type fields and values, and hash is especially suitable for storing objects.
Each hash in Redis can store 232 - 1 key-value pairs (more than 4 billion).

[b]Create hash table user and set fields[/b]
redis 127.0.0.1:6379> hmset user name "zhangshan" age "25" sex "man"     
OK
[b]
Hgetall get all fields and values ​​in the hash table[/b]
redis 127.0.0.1:6379> hgetall user
1) "name"
2) "zhangshan"
3) "age"
4) "25"
5) "sex"
6) "man"



[b]hkeys get all the keys in the hash table[/b]
redis 127.0.0.1:6379> hkeys user
1) "age"
2) "sex"



[b]The Hdel command is used to delete one or more specified fields in the hash table key, and the fields that do not exist will be ignored[/b]

redis 127.0.0.1:6379> hdel user name //Delete the name field in the hash table user
(integer) 1
redis 127.0.0.1:6379> hgetall user //Check the fields and values ​​in the hash table again, note: the name field and its value are gone
1) "age"
2) "25"
3) "sex"
4) "man"

[b]hexists determine whether the fields in the hash table exist[/b]

redis 127.0.0.1:6379> hexists user name
(integer) 0 // just deleted so it doesn't exist anymore


[b]hget obtains the value of the specified field in the hash table[/b]
redis 127.0.0.1:6379> hset dog colore red //For example, set the field colore to red in the hash table dog
(integer) 1
redis 127.0.0.1:6379> hget dog colore //Get the value of the colore field of the hash table dog
"red"

[b]hlen gets the number of fields in the hash table[/b]
redis 127.0.0.1:6379> hlen user
(integer) 2

[b]
Hvals get all the values ​​in the hash table[/b]
redis 127.0.0.1:6379> whale user
1) "25"
2) "man"

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326756364&siteId=291194637