您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。