HGET key field

获取哈希表key中的field的值

127.0.0.1:6379> hget user username
"Sam"
127.0.0.1:6379> hget user phone
"15812345678"

HSET key field value

在哈希表key中设置filed的值,如果field存在会进行覆盖。

127.0.0.1:6379> hset user username Sam
(integer) 1
127.0.0.1:6379> hset user phone 15812345678
(integer) 1
127.0.0.1:6379> hset user username Kobe
(integer) 0
127.0.0.1:6379> hget user username
"Kobe"

HSETNX key field value

在哈希表key中设置filed的值,并且field不存在,如果field已存在则操作无效。

127.0.0.1:6379> hsetnx user avatar xxx
(integer) 1
127.0.0.1:6379> hsetnx user avatar xxx
(integer) 0

HGETALL key

获取哈希表key所有的field和值

127.0.0.1:6379> hgetall user
1) "username" # field
2) "Sam" # value
3) "phone"
4) "15812345678"

HKEYS key

返回哈希表key中所有的field

127.0.0.1:6379> hkeys user
1) "username"
2) "phone"

HVALS key

返回哈希表key中所有field的值

127.0.0.1:6379> hvals user
1) "Alen"
2) "15812345678"
3) "1"
4) "196"

HMSET key field value [...field value]

对哈希表key一次性设置多个field,field存在会进行覆盖。

127.0.0.1:6379> hmset user username Alen sex 1 height 196
ok
127.0.0.1:6379> hgetall user
1) "username"
2) "Alen"
3) "phone"
4) "15812345678"
5) "sex"
6) "1"
7) "height"
8) "196"

HMGET key field [...field]

获取哈希表key的多个field的值

127.0.0.1:6379> hmget user avatar sex phone
1) "xxx"
2) "1"
3) "15812345678"

HLEN key

返回哈希表key的field数量

127.0.0.1:6379> hlen user
(integer) 4
最后修改:2020 年 10 月 20 日 11 : 50 AM
如果觉得我的文章对你有用,请随意赞赏