redis数据类型-hash类型

HSET:设置HASH值

HGET:获取HASH值

HGETALL:获取所有的HASH值

192.168.2.120:6379> HSET shouji name iphone

(integer) 1

192.168.2.120:6379> HSET shouji color red

(integer) 1

192.168.2.120:6379> HSET shouji price 8888

(integer) 1

192.168.2.120:6379> HGET shouji name

"iphone"

192.168.2.120:6379> HGET shouji

(error) ERR wrong number of arguments for 'hget' command

192.168.2.120:6379> HGET shouji color

"red"

192.168.2.120:6379> HGET shouji price

"8888"

192.168.2.120:6379> HGETall shouji

1) "name"

2) "iphone"

3) "color"

4) "red"

5) "price"

6) "8888"

 

 

192.168.2.120:6379> HSET car name auto

(integer) 1

192.168.2.120:6379> HSET car price 30

(integer) 1

192.168.2.120:6379> HSET car mode 2.4T

(integer) 1

192.168.2.120:6379> HGETALL cat

1) "color"

2) "red"

192.168.2.120:6379> HGETALL car

1) "name"

2) "auto"

3) "price"

4) "30"

5) "mode"

6) "2.4T"

 

192.168.2.120:6379> HSET diannao model "hehehehe"

(integer) 1

192.168.2.120:6379> HGET diannao model

"hehe hehe"

 

 

HMSET:一次设置多个KEY-VALUE

HMGET:一次获取多个KEY-VALUE

192.168.2.120:6379> HMSET diannao name thinkpad colorblack price 30

OK

192.168.2.120:6379> HMGET diannao name

1) "thinkpad"

192.168.2.120:6379> HMGET diannao name color price

1) "thinkpad"

2) "black"

3) "30"

 

HDEL:删除指定的key

192.168.2.120:6379> HDEL diannao model

(integer) 1

192.168.2.120:6379> HGETALL diannao

1) "name"

2) "thinkpad"

3) "color"

4) "black"

5) "price"

6) "30"

192.168.2.120:6379>

 

HEXISTS:判断key的字段值是否存在

192.168.2.120:6379> HEXISTS diannao name

(integer) 1

 

192.168.2.120:6379> EXISTS diannao       #判断KEY是否存在

(integer) 1

 

 

 

 

 

 

 

 

 

 

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS