Redis:哈希类型(Hash)


#Redis


Hash 相关命令

具体见 https://redis.io/commands#hash

  • HSET
  • HSETNX
  • HMSET
  • HGET
  • HMGET
  • HGETALL
  • HDEL
  • HLEN
  • HEXISTS
  • HINCRBY
  • HKEYS
  • HVALS
  • HSCAN

示例

Redis server v=5.0.7

示例:hset 、hgetall、hget

127.0.0.1:6379> hset xiaoming age 18
(integer) 1
127.0.0.1:6379> hgetall xiaoming
1) "age"
2) "18"
127.0.0.1:6379> hset xiaoming height 170
(integer) 1
127.0.0.1:6379> hgetall xiaoming
1) "age"
2) "18"
3) "height"
4) "170"
127.0.0.1:6379> hget xiaoming age
"18"

示例:hset、expire、hgetall

127.0.0.1:6379> hset xiaoming age 18
(integer) 1
127.0.0.1:6379> hset xiaoming height 170
(integer) 1
127.0.0.1:6379> expire xiaoming 120
(integer) 1
127.0.0.1:6379> ttl xiaoming
(integer) 117
127.0.0.1:6379> hgetall xiaoming
1) "age"
2) "18"
3) "height"
4) "170"

示例:hmset、hdel、hgetall

127.0.0.1:6379> hmset xiaoming age 18 height 170
OK
127.0.0.1:6379> hgetall xiaoming
1) "age"
2) "18"
3) "height"
4) "170"
127.0.0.1:6379> hdel xiaoming age
(integer) 1
127.0.0.1:6379> hgetall xiaoming
1) "height"
2) "170"
127.0.0.1:6379>

示例:hmset、hget、hset

127.0.0.1:6379> hmset xiaoming age 18 height 170
OK
127.0.0.1:6379> hget xiaoming age
"18"
127.0.0.1:6379> hset xiaoming age 19
(integer) 0
127.0.0.1:6379> hget xiaoming age
"19"


( 本文完 )