Redis 命令 - Hashs

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

More: http://redis.io/commands/hdelhttp://www.redis.cn/commands/hdel.html

 

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

More: http://redis.io/commands/hexistshttp://www.redis.cn/commands/hexists.html

 

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"

More: http://redis.io/commands/hgethttp://www.redis.cn/commands/hget.html

 

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"

More: http://redis.io/commands/hgetallhttp://www.redis.cn/commands/hgetall.html

 

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

More: http://redis.io/commands/hincrbyhttp://www.redis.cn/commands/hincrby.html

 

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"

More: http://redis.io/commands/hincrbyfloathttp://www.redis.cn/commands/hincrbyfloat.html

 

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"

More: http://redis.io/commands/hkeyshttp://www.redis.cn/commands/hkeys.html

 

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

More: http://redis.io/commands/hlenhttp://www.redis.cn/commands/hlen.html


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

More: http://redis.io/commands/hmgethttp://www.redis.cn/commands/hmget.html

 

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"

More: http://redis.io/commands/hmsethttp://www.redis.cn/commands/hmset.html

 

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"

More: http://redis.io/commands/hsethttp://www.redis.cn/commands/hset.html

 

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"

More: http://redis.io/commands/hsetnxhttp://www.redis.cn/commands/hsetnx.html

 

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"

More: http://redis.io/commands/hvalshttp://www.redis.cn/commands/hvals.html 

 

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

 

posted on 2015-09-24 21:00  huey2672  阅读(313)  评论(0编辑  收藏  举报