Redis (3): Hash common commands for data structure

Hash in Redis is first used as HashMap<String,String> in JAVA

1. hset-set the value of the field in the HashMap corresponding to the key

127.0.0.1:6379> hset map1 name ermu
(integer) 1
127.0.0.1:6379> hmset map1 age 22 height 170 
OK

2.hsetnx 

127.0.0.1:6379> hsetnx map1 name ermu1
(integer) 0
127.0.0.1:6379> hsetnx map1 selfinfo "hellow word!"
(integer) 1

3.hexists 

127.0.0.1:6379> hexists map1 name
(integer) 1
127.0.0.1:6379> hexists map1 other
(integer) 0

4. hget-Get the value of the field in the HashMap corresponding to the key

127.0.0.1:6379> hget map1 name
"ermu"

5. hgetall-get the value of all fields in the HashMap corresponding to the key

127.0.0.1:6379> hgetall map1
1) "name"
2) "ermu"
3) "age"
4) "22"
5) "height"
6) "170"

6. HDEL

127.0.0.1:6379> hgetall map1
1) "name"
2) "ermu"
3) "age"
4) "22"
5) "height"
6) "170"
7) "selfinfo"
8) "hellow word!"
127.0.0.1:6379> hdel map1 selfinfo
(integer) 1
127.0.0.1:6379> hgetall map1 
1) "name"
2) "ermu"
3) "age"
4) "22"
5) "height"
6) "170"
127.0.0.1:6379> hdel map1 other
(integer) 0

7. hlen--returns the number of fields in the HashMap corresponding to the key

127.0.0.1:6379> hlen map1
(integer) 3

8. The length of hstrlen key->field->value

127.0.0.1:6379> HSTRLEN map1 name
(integer) 4
127.0.0.1:6379> HSTRLEN map1 age
(integer) 2

9、hincrby 

127.0.0.1:6379> HINCRBY map1 age 20
(integer) 42

10、hincrbyfloat 

127.0.0.1:6379> HINCRBYFLOAT map1 height 2.1
"172.10000000000000001"
127.0.0.1:6379> HSET map1 number 22.44
(integer) 1
127.0.0.1:6379> HINCRBYFLOAT map1 number 2.3
"24.74"

11、HKEYS

127.0.0.1:6379> HKEYS map1
1) "name"
2) "age"
3) "height"
4) "number"

12 、 WHALE

127.0.0.1:6379> HVALS map1
1) "ermu"
2) "42"
3) "172.10000000000000001"
4) "24.74"

 

Guess you like

Origin blog.csdn.net/qq_22420441/article/details/87529864