Redis哈希表相关指令

一、概要

redis里值可以是一个哈希表,哈希表底层实现可以是一个HASH_TABLE或ZIP_LIST。redis命令可以创建、删除哈希表,单插入、多插入、单删除、多删除哈希表的键值对,也可以获取哈希表、哈希表的所有键、哈希表的所有值。

二、代码示例

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"

你可能感兴趣的:(Redis,redis哈希表,redis哈希表命令)