Redis hash table related instructions

1. Summary

The value in redis can be a hash table, and the underlying implementation of the hash table can be a HASH_TABLE or ZIP_LIST. The redis command can create and delete hash tables, single-insert, multiple-insert, single-delete, and multiple-delete key-value pairs of hash tables, as well as obtain hash tables, all keys of hash tables, and all values ​​of hash tables.

Two, code example

127.0.0.1:6379> HSET test a 1
(integer) 1
127.0.0.1:6379> HGET test a
"1"
127.0.0.1:6379> HSET test a 1
(integer) 1
127.0.0.1:6379> HSET test b 2
(integer) 1
127.0.0.1:6379> HGET test a
"1"
127.0.0.1:6379> HGET test c
(nil)
127.0.0.1:6379> HGETALL test
1) "a"
2) "1"
3) "b"
4) "2"
127.0.0.1:6379> HKEYS test
1) "a"
2) "b"
127.0.0.1:6379> HVALS test
1) "1"
2) "2"
127.0.0.1:6379> HINCRBY test b 10
(integer) 12
127.0.0.1:6379> HLEN test
(integer) 2
127.0.0.1:6379> HGET test b
"2"
127.0.0.1:6379> DEL test
(integer) 1
127.0.0.1:6379> HMSET c 3 d 4 e 5
(error) ERR wrong number of arguments for HMSET
127.0.0.1:6379> HMSET test c 3 d 4 e 5
OK
127.0.0.1:6379> HGETALL test
 1) "a"
 2) "1"
 3) "b"
 4) "2"
 5) "c"
 6) "3"
 7) "d"
 8) "4"
 9) "e"
10) "5"
127.0.0.1:6379> HMGET test a b c e
1) "1"
2) "2"
3) "3"
4) "5"

Guess you like

Origin blog.csdn.net/gamekit/article/details/107592995