127.0.0.1:6379> hset hash_name jack"Jack Sparrow"
(integer) 1
127.0.0.1:6379> hset hash_name gump"Forrest Gump"
(integer) 1
127.0.0.1:6379> hlen hash_name
(integer) 2
9、hexists
hexists key field
查看哈希表key中,给定域field是否存在。
时间复杂度:
O(1)
返回值:
如果哈希表含有给定域,返回1。
如果哈希表不含有给定域,或key不存在,返回0。
127.0.0.1:6379> hexists phone myphone
(integer) 0
?
127.0.0.1:6379> hset phone myphone nokia-1110
(integer) 1
?
127.0.0.1:6379> hexists phone myphone
(integer) 1
10、hincrby
hincrby key field increment
为哈希表key中的域field的值加上增量increment。
如果key不存在,一个新的哈希表被创建并执行hincrby命令。
如果域field不存在,或域已有的字符串值不能表示为数字,那么在执行命令前,域的值被设置为0。
本操作的值限制在64位(bit)有符号数字表示之内。
时间复杂度:
O(1)
返回值:
执行hincrby命令之后,哈希表key中域field的值。
127.0.0.1:6379> hexists hash_count page_views
(integer) 0
?
127.0.0.1:6379> hincrby hash_count page_views 200
(integer) 200
?
127.0.0.1:6379> hincrby hash_count page_views 10
(integer) 210
11、hkeys
hkeys key
返回哈希表key中的所有域。
时间复杂度:
O(N),N为哈希表的大小。
返回值:
一个包含哈希表中所有域的表。
当key不存在时,返回一个空表。
# 情况1:哈希表非空
127.0.0.1:6379> hmset website google www.google.com yahoowww.yahoo.com
OK
127.0.0.1:6379> hkeys website
1) "google"
2) "yahoo"
# 情况2:空哈希表/key不存在
127.0.0.1:6379>exists fake_key
(integer) 0
127.0.0.1:6379> hkeys fake_key
(empty list or set)
12、hvals
hvals key
返回哈希表key中的所有值。
时间复杂度:
O(N),N为哈希表的大小。
返回值:
一个包含哈希表中所有值的表。
当key不存在时,返回一个空表。
# 情况1:非空哈希表
127.0.0.1:6379> hmset website google www.google.com yahoowww.yahoo.com
OK
?
127.0.0.1:6379> hvals website
1) "www.google.com"
2) "www.yahoo.com"
# 情况2:空哈希表/不存在的key
127.0.0.1:6379> exists not_exists
(integer) 0
127.0.0.1:6379> hvals not_exists
(empty list or set)
=