Redis的Hash操作

常用命令

127.0.0.1:6379> hset user:1001 id 1     												 ##存值
(integer) 1
127.0.0.1:6379> hset user:1001 name zhangsan                        ##存值
(integer) 1
127.0.0.1:6379> hset user:1001 age 22	                                       ##存值
(integer) 1
127.0.0.1:6379> hget user:1001 id                                             ##取值
"1"
127.0.0.1:6379> hget user:1001 name                                   ##取值
"zhangsan"
127.0.0.1:6379> hget user:1001 age                                  ##取值
"22"
127.0.0.1:6379> 
------------------------------------
127.0.0.1:6379> hsetnx user:1003 x1 v1##当某个field不存在才允许添加
(integer) 1
127.0.0.1:6379> hsetnx user:1003 age 33
(integer) 0
127.0.0.1:6379> 

-------------------------------------
127.0.0.1:6379> hmset user:1003 id 2 name lisi age 23##批量插入
OK
127.0.0.1:6379> hget user:1003 id
"2"
127.0.0.1:6379> hget user:1003 name
"lisi"
127.0.0.1:6379> hget user:1003 age
"23"
127.0.0.1:6379>
-------------------------------------------------------
127.0.0.1:6379> hexists user:1003 gender##返回某个field是否存在
(integer) 0
127.0.0.1:6379> hexists user:1003 age
(integer) 1
127.0.0.1:6379> 
--------------------------------------------------
127.0.0.1:6379> hkeys user:1003##查看某个key的所有field
1) "id"
2) "name"
3) "age"
127.0.0.1:6379> 
-----------------------------------------------
127.0.0.1:6379> hvals user:1003##查看某个key的所有field的值
1) "2"
2) "lisi"
3) "23"
127.0.0.1:6379> 
----------------------------------------------
127.0.0.1:6379> hincrby user:1003 age 5##增加某个field的值
(integer) 28
127.0.0.1:6379> hget user:1003 age
"28"
127.0.0.1:6379> 
-------------------------------------------------



上一篇:1003 我要通过! (20 分) c语言实现


下一篇:1003 我要通过! (20 分)