Redis hash key data type of the type

 

Hash type suitable for storing objects

Set car table name = "BMW" price = "500"

127.0.0.1:6379> hset car price 500
(integer) 1
127.0.0.1:6379> hset car name BMW
(integer) 1
127.0.0.1:6379> hget car name
"BMW"
127.0.0.1:6379> hmget car  price name
1) "500"
2) "BMW"
127.0.0.1:6379> hgetall car
1) "price"
2) "500"
3) "name"
4) "BMW"

 

hset does not distinguish between insert and update operations, if we name table in the car = "BMW" price = "500" on the basis of:

0 represents the current presence hset price 600 is returned directly update

If color is added hset color write attribute representing the current returns an insert operation is

127.0.0.1:6379> hset car price 600
(integer) 0
127.0.0.1:6379> hset car color write
(integer) 1
127.0.0.1:6379> hgetall car
1) "price"
2) "600"
3) "name"
4) "BMW"
5) "color"
6) "write"

 

Value Added

600 is increased by 66 before price hincr 

127.0.0.1:6379> hincrby car price 66
(integer) 666
127.0.0.1:6379> hget car price
"666"

 

Delete field

127.0.0.1:6379> hdel car price
(integer) 1

 

Guess you like

Origin www.cnblogs.com/zoey686/p/11680311.html