image-20220817214700975

What Redis data structures look like(opens new window)

STRING

二、数据类型 - 图2

  1. > set hello world
  2. OK
  3. > get hello
  4. "world"
  5. > del hello
  6. (integer) 1
  7. > get hello
  8. (nil)

LIST

二、数据类型 - 图3

  1. > rpush list-key item
  2. (integer) 1
  3. > rpush list-key item2
  4. (integer) 2
  5. > rpush list-key item
  6. (integer) 3
  7. > lrange list-key 0 -1
  8. 1) "item"
  9. 2) "item2"
  10. 3) "item"
  11. > lindex list-key 1
  12. "item2"
  13. > lpop list-key
  14. "item"
  15. > lrange list-key 0 -1
  16. 1) "item2"
  17. 2) "item"

SET

二、数据类型 - 图4

  1. > sadd set-key item
  2. (integer) 1
  3. > sadd set-key item2
  4. (integer) 1
  5. > sadd set-key item3
  6. (integer) 1
  7. > sadd set-key item
  8. (integer) 0
  9. > smembers set-key
  10. 1) "item"
  11. 2) "item2"
  12. 3) "item3"
  13. > sismember set-key item4
  14. (integer) 0
  15. > sismember set-key item
  16. (integer) 1
  17. > srem set-key item2
  18. (integer) 1
  19. > srem set-key item2
  20. (integer) 0
  21. > smembers set-key
  22. 1) "item"
  23. 2) "item3"

ZSET

二、数据类型 - 图5

  1. > zadd zset-key 728 member1
  2. (integer) 1
  3. > zadd zset-key 982 member0
  4. (integer) 1
  5. > zadd zset-key 982 member0
  6. (integer) 0
  7. > zrange zset-key 0 -1 withscores
  8. 1) "member1"
  9. 2) "728"
  10. 3) "member0"
  11. 4) "982"
  12. > zrangebyscore zset-key 0 800 withscores
  13. 1) "member1"
  14. 2) "728"
  15. > zrem zset-key member1
  16. (integer) 1
  17. > zrem zset-key member1
  18. (integer) 0
  19. > zrange zset-key 0 -1 withscores
  20. 1) "member0"
  21. 2) "982"