Map集合,key-map!这时候的集合是Map集合!本质和String,类型没有太大区别,还是一个简单的Key-value! set myhash field lilin
127.0.0.1:6379> hset myhash field1 lilin
(integer) 1
127.0.0.1:6379> hget myhash field1
"lilin"
127.0.0.1:6379> hmset myhash field1 hello field2 world
OK
127.0.0.1:6379> hmget myhash field2 fiedl2
1) "world"
2) (nil)
127.0.0.1:6379> hmget myhash field2 fiedl1
1) "world"
2) (nil)
127.0.0.1:6379> hmget myhash field1 field2
1) "hello"
2) "world"
127.0.0.1:6379> hgetall myhash
1) "field1"
2) "hello"
3) "field2"
4) "world"
127.0.0.1:6379>
127.0.0.1:6379> hdel myhash field1
(integer) 1
127.0.0.1:6379> hgetall myhash
1) "field2"
2) "world"
127.0.0.1:6379>
hexists:判断hash中指定字段是否存在!
127.0.0.1:6379> hexists myhash field2
(integer) 1
127.0.0.1:6379>
#只获得所有field #只获得所有value
127.0.0.1:6379> hkeys myhash
1) "field2"
127.0.0.1:6379> hvals myhash
1) "world"
127.0.0.1:6379>
127.0.0.1:6379> hset myhash field3 5
(integer) 1
127.0.0.1:6379> HINCRBY myhash field3 1
(integer) 6
127.0.0.1:6379> HINCRBY myhash field3 1
(integer) 7
127.0.0.1:6379> HINCRBY myhash field3 -1
(integer) 6
127.0.0.1:6379> hsetnx myhash field4 ll
(integer) 1
127.0.0.1:6379>
Hash变更得数据user name age ,尤其是用户信息之类得,经常变动的信息!,hash更适合于对象的存储,String更佳适合字符串存储!
|