这篇文章给大家分享的是有关Redis哈希Hash怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
KV模式不变,但V是一个键值对
hset:添加
hget: 获取
hmset: 批量添加
hgetall: 获取key中所有键值信息
hdel: 删除key中某属性
127.0.0.1:9736> hset user id 11 (integer) 1 127.0.0.1:9736> hget user id "11" 127.0.0.1:9736> hset user name blue sex man (integer) 2 127.0.0.1:9736> hget user name sex (error) ERR wrong number of arguments for 'hget' command 127.0.0.1:9736> hget user name "blue" 127.0.0.1:9736> hget user sex "man" 127.0.0.1:9736> hmset customer id 11 name li4 age 26 OK 127.0.0.1:9736> hmget customer id name age 1) "11" 2) "li4" 3) "26" 127.0.0.1:9736> HGETALL customer 1) "id" 2) "11" 3) "name" 4) "li4" 5) "age" 6) "26" 127.0.0.1:9736> hdel user sex (integer) 1 127.0.0.1:9736> HGETALL user 1) "id" 2) "11" 3) "name" 4) "blue"
127.0.0.1:9736> HLEN user (integer) 2 127.0.0.1:9736> HLEN customer (integer) 3
127.0.0.1:9736> HGETALL user 1) "id" 2) "11" 3) "name" 4) "blue" 127.0.0.1:9736> hgetall customer 1) "id" 2) "11" 3) "name" 4) "li4" 5) "age" 127.0.0.1:9736> HEXISTS user id (integer) 1 127.0.0.1:9736> HEXISTS customer age (integer) 1
127.0.0.1:9736> HKEYS customer 1) "id" 2) "name" 3) "age" 127.0.0.1:9736> HVALS customer 1) "11" 2) "li4" 3) "26"
127.0.0.1:9736> HGETALL customer 1) "id" 2) "11" 3) "name" 4) "li4" 5) "age" 6) "36" 127.0.0.1:9736> HINCRBYfloat customer age 0.1 "36.1" 127.0.0.1:9736> HINCRBYFLOAT customer age 0.4 "36.5" 127.0.0.1:9736> HGETALL customer 1) "id" 2) "11" 3) "name" 4) "li4" 5) "age" 6) "36.5"
如果不存在则添加 key value ,否则不添加
127.0.0.1:9736> HSETNX customer email 2@1 (integer) 1 127.0.0.1:9736> HGETALL customer 1) "id" 2) "11" 3) "name" 4) "li4" 5) "age" 6) "36.5" 7) "email" 8) "2@1"
感谢各位的阅读!关于“Redis哈希Hash怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。