Redis Grammar: hashs

Time:2020-8-16

KV mode unchanged, single V is a key value pair

1、 Increase

127.0.0.1:6379 > hset user name bin // set the name for the key user
(integer) 1
127.0.0.1:6379 > hmset user age 23 sex male // batch setting of multiple keys
OK
127.0.0.1:6379> hmget user name age sex
1) "bin"
2) "23"
3) "male"
127.0.0.1:6379 > hsetnx user age 40 // if the age does not exist, it will be set. If the age does not exist, 0 is returned
(integer) 0

2、 Delete

127.0.0.1:6379 > HDEL user name // delete the name key
(integer) 1

3、 Reform

0.0.1:6379 > hincrby user age 3 // increase the value of age
127.0.0.1:6379> hset user score 91.3
(integer) 1
127.0.0.1:6379 > hincrbyfloat user score 0.5 // increase the floating point number value
"91.8"

3、 Check

127.0.0.1:6379 > hget user name // obtain the value of a single key name
127.0.0.1:6379 > hmget user name age sex // get multiple key values
1) "bin"
2) "23"
3) "male"
127.0.0.1:6379 > hgetall user // get the key value pair of this user hash
1) "name"
2) "bin"
3) "age"
4) "23"
5) "sex"
6) "male"
127.0.0.1:6379 > hkeys user // get all the keys under user
1) "age"
2) "sex"
127.0.0.1:6379 > hvals user // get all the values under user
1) "23"
2) "male"
127.0.0.1:6379 > hex user age // determine whether the age key exists
(integer) 1