redis里面操作hash类型相关的常用命令,hash类型跟java里面的map差不多,也是存放的键值对:
hset map1 map1_key1 map1_value1:一次只能为map1添加一个键值对
hmset map2 size 1234 name xx_tb:一次性多个赋值
hget map1 map1_key1 :得到hash类型的map1里面以map1_key1为键的值
hgetall map1:得到map1这个hash的所有键值对
hdel map2 size :删除size
hexists map2 size :判断size是否存在
hlen map2:获取map2中的键个数
hkeys map1:获得所有的键
hvals map2:获得所有的值
添加与获取,hset一次只能添加一个键值对,如果添加多个的话,就会报错:
192.168.23.112:6379> hset person name zhao age 28 status sadly (error) ERR wrong number of arguments for 'hset' command 192.168.23.112:6379> hmset person name zhao age 28 status sadly OK 192.168.23.112:6379> hget person name "zhao" 192.168.23.112:6379> hgetall person 1) "name" 2) "zhao" 3) "age" 4) "28" 5) "status" 6) "sadly"
获取person中键值对的个数:
192.168.23.112:6379> hlen person (integer) 3
判断某个键是否在person这个hash中存在,hexists可以实现这个功能,存在返回1,否则返回0
192.168.23.112:6379> hexists person status (integer) 1 192.168.23.112:6379> hexists person sex (integer) 0
908

被折叠的 条评论
为什么被折叠?



