redis redis中的hash結構【八】

哎呀我的天吶發表於2015-08-19

點選(此處)摺疊或開啟

  1. 127.0.0.1:6379> hset user1 name lisi
  2. (integer) 1
  3. 127.0.0.1:6379> hset user1 age 20
  4. (integer) 1
  5. 127.0.0.1:6379> hset user1 sal 8000
  6. (integer) 1
  7. 127.0.0.1:6379> hset user1 empno 2349
  8. (integer) 1
  9. 127.0.0.1:6379> hgetall user1
  10. 1) "name"
  11. 2) "lisi"
  12. 3) "age"
  13. 4) "20"
  14. 5) "sal"
  15. 6) "8000"
  16. 7) "empno"
  17. 8) "2349"

點選(此處)摺疊或開啟

  1. 127.0.0.1:6379> hmset scott empno 7788 sal 8000 emono 2232 deptno 10
  2. OK
  3. 127.0.0.1:6379> hgetall scott
  4. 1) "empno"
  5. 2) "7788"
  6. 3) "sal"
  7. 4) "8000"
  8. 5) "emono"
  9. 6) "2232"
  10. 7) "deptno"
  11. 8) "10"


點選(此處)摺疊或開啟

  1. 127.0.0.1:6379> hmget scott sal deptno
  2. 1) "8000"
  3. 2) "10"
刪除hash key:

點選(此處)摺疊或開啟

  1. 127.0.0.1:6379> hdel user1 age
  2. (integer) 1

判斷有幾個field和這個field是否存在:

點選(此處)摺疊或開啟

  1. 127.0.0.1:6379> hlen user1
  2. (integer) 3
  3. 127.0.0.1:6379> hlen scott
  4. (integer) 4
  5. 127.0.0.1:6379> hexists user age
  6. (integer) 0
  7. 127.0.0.1:6379> hexists user1 age
  8. (integer) 0
  9. 127.0.0.1:6379> hexists user1 deptno
  10. (integer) 0
  11. 127.0.0.1:6379> hexists user1 empno
  12. (integer) 1
 增加處理:

點選(此處)摺疊或開啟

  1. 127.0.0.1:6379> hgetall user2
  2. 1) "age"
  3. 2) "1"
  4. 127.0.0.1:6379> hincrby user2 age 1
  5. (integer) 2
  6. 127.0.0.1:6379> hgetall user2
  7. 1) "age"
  8. 2) "2"
浮點增加:

點選(此處)摺疊或開啟

  1. 127.0.0.1:6379> hincrbyfloat user2 age 0.5
  2. "2.5"
  3. 127.0.0.1:6379> hgetall user2
  4. 1) "age"
  5. 2) "2.5"
返回field或者values

點選(此處)摺疊或開啟

  1. 127.0.0.1:6379> hkeys user1
  2. 1) "name"
  3. 2) "sal"
  4. 3) "empno"
  5. 127.0.0.1:6379> hvals user1
  6. 1) "lisi"
  7. 2) "8000"
  8. 3) "2349"

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29990276/viewspace-1776461/,如需轉載,請註明出處,否則將追究法律責任。

相關文章