码迷,mamicode.com
首页 > 其他好文 > 详细

Redis(2.8.3) 命令学习 - Hashs

时间:2015-09-24 22:40:39      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:

HDEL key field [field ...]

Delete one or more hash fields

127.0.0.1:6379> HSET book.1 title helloworld
(integer) 0
127.0.0.1:6379> HEXISTS book.1 title
(integer) 1
127.0.0.1:6379> HDEL book.1 title
(integer) 1
127.0.0.1:6379> HEXISTS book.1 title
(integer) 0

 

HEXISTS key field

Determine if a hash field exists

127.0.0.1:6379> HSET book.1 title helloworld
(integer) 1
127.0.0.1:6379> HEXISTS book.1 title
(integer) 1
127.0.0.1:6379> HEXISTS book.1 title2
(integer) 0
127.0.0.1:6379> HEXISTS book.2 title
(integer) 0

 

HGET key field

Get the value of a hash field

127.0.0.1:6379> HSET book.1 title helloworld
(integer) 0
127.0.0.1:6379> HSET book.1 author Mr.404
(integer) 1
127.0.0.1:6379> HGET book.1 title
"helloworld"
127.0.0.1:6379> HGET book.1 author
"Mr.404"

 

HGETALL key

Get all the fields and values in a hash

127.0.0.1:6379>  HSET book.1 title helloworld
(integer) 1
127.0.0.1:6379> HSET book.1 author Mr.404
(integer) 1
127.0.0.1:6379> HGETALL book.1
1) "title"
2) "helloworld"
3) "author"
4) "Mr.404"

 

HINCRBY key field increment

Increment the integer value of a hash field by the given number

127.0.0.1:6379> HSET book.1 price 30
(integer) 1
127.0.0.1:6379> HINCRBY book.1 price 10
(integer) 40
127.0.0.1:6379> HINCRBY book.1 price -5
(integer) 35

 

HINCRBYFLOAT key field increment

Increment the float value of a hash field by the given amount

127.0.0.1:6379> HSET book.1 price 30
(integer) 0
127.0.0.1:6379> HINCRBYFLOAT book.1 price 9.99
"39.99"
127.0.0.1:6379> HINCRBYFLOAT book.1 price -4.5
"35.49"

 

HKEYS key

Get all the fields in a hash

127.0.0.1:6379> HSET book.1 title helloworld
(integer) 0
127.0.0.1:6379> HSET book.1 author Mr.404
(integer) 0
127.0.0.1:6379> HKEYS book.1
1) "title"
2) "author"

 

HLEN key

Get the number of fields in a hash

127.0.0.1:6379> HSET book.1 title helloworld
(integer) 0
127.0.0.1:6379> HSET book.1 author Mr.404
(integer) 0
127.0.0.1:6379> HLEN book.1
(integer) 2


HMGET key field [field ...]

Get the values of all the given hash fields

127.0.0.1:6379> HSET book.1 title helloworld
(integer) 0
127.0.0.1:6379> HSET book.1 author Mr.404
(integer) 0
127.0.0.1:6379> HMGET book.1 author title
1) "Mr.404"
2) "helloworld

 

HMSET key field value [field value ...]

Set multiple hash fields to multiple values

127.0.0.1:6379> HMSET book.1 title helloworld author Mr.404
OK
127.0.0.1:6379> HGET book.1 title
"helloworld"
127.0.0.1:6379> HGET book.1 author
"Mr.404"

 

HSET key field value

Set the string value of a hash field

127.0.0.1:6379> HSET book.1 title helloworld
(integer) 0
127.0.0.1:6379> HSET book.1 author Mr.404
(integer) 1
127.0.0.1:6379> HGET book.1 title
"helloworld"
127.0.0.1:6379> HGET book.1 author
"Mr.404"

 

HSETNX key field value

Set the value of a hash field, only if the field does not exist

127.0.0.1:6379> HSETNX book.1 title helloworld
(integer) 1
127.0.0.1:6379> HSETNX book.1 title hellopython
(integer) 0
127.0.0.1:6379> HGET book.1 title
"helloworld"

 

HSTRLEN key field

Get the length of the value of a hash field

More: http://redis.io/commands/hstrlen

 

HVALS key
  Get all the values in a hash

127.0.0.1:6379> HSETNX book.1 title helloworld
(integer) 0
127.0.0.1:6379> HSET book.1 author Mr.404
(integer) 1
127.0.0.1:6379> HVALS book.1
1) "helloworld"
2) "Mr.404"

 

HSCAN key cursor [MATCH pattern] [COUNT count]

Incrementally iterate hash fields and associated values

More: http://redis.io/commands/hscanhttp://www.redis.cn/commands/hscan.html

 

Redis(2.8.3) 命令学习 - Hashs

标签:

原文地址:http://www.cnblogs.com/huey/p/4345500.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!