Redis Hash command

HVALS

HVALS key

#Example

redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HVALS myhash
1) "Hello"
2) "World"

Get all the values in a hash

HSTRLEN

HSTRLEN key field

#Example

redis> HMSET myhash f1 HelloWorld f2 99 f3 -256
"OK"
redis> HSTRLEN myhash f1
(integer) 10
redis> HSTRLEN myhash f2
(integer) 2
redis> HSTRLEN myhash f3
(integer) 4

Get the length of the value of a hash field

HSETNX

HSETNX key field value

#Example

redis> HSETNX myhash field "Hello"
(integer) 1
redis> HSETNX myhash field "World"
(integer) 0
redis> HGET myhash field
"Hello"

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

HSET

HSET key field value [field value ...]

#Example

redis> HSET myhash field1 "Hello"
(integer) 1
redis> HGET myhash field1
"Hello"

Set the string value of a hash field

HMSET

HMSET key field value [field value ...]

#Example

redis> HMSET myhash field1 "Hello" field2 "World"
"OK"
redis> HGET myhash field1
"Hello"
redis> HGET myhash field2
"World"

Set multiple hash fields to multiple values

HMGET

HMGET key field [field ...]

#Example

redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HMGET myhash field1 field2 nofield
1) "Hello"
2) "World"
3) (nil)

Get the values of all the given hash fields

HLEN

HLEN key

#Example

redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HLEN myhash
(integer) 2

Get the number of fields in a hash

HKEYS

HKEYS key

#Example

redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HKEYS myhash
1) "field1"
2) "field2"

Get all the fields in a hash

HINCRBYFLOAT

HINCRBYFLOAT key field increment

#Example

redis> HSET mykey field 10.50
(integer) 1
redis> HINCRBYFLOAT mykey field 0.1
"10.6"
redis> HINCRBYFLOAT mykey field -5
"5.6"
redis> HSET mykey field 5.0e3
(integer) 0
redis> HINCRBYFLOAT mykey field 2.0e2
"5200"

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

HINCRBY

HINCRBY key field increment

#Example

redis> HSET myhash field 5
(integer) 1
redis> HINCRBY myhash field 1
(integer) 6
redis> HINCRBY myhash field -1
(integer) 5
redis> HINCRBY myhash field -10
(integer) -5

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

HGETALL

HGETALL key

#Example

redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HGETALL myhash
1) "field1"
2) "Hello"
3) "field2"
4) "World"

Get all the fields and values in a hash

HGET

HGET key field

#Example

redis> HSET myhash field1 "foo"
(integer) 1
redis> HGET myhash field1
"foo"
redis> HGET myhash field2
(nil)

Get the value of a hash field

HEXISTS

HEXISTS key field

#Example

redis> HSET myhash field1 "foo"
(integer) 1
redis> HEXISTS myhash field1
(integer) 1
redis> HEXISTS myhash field2
(integer) 0

Determine if a hash field exists

HDEL

HDEL key field [field ...]

#Example

redis> HSET myhash field1 "foo"
(integer) 1
redis> HDEL myhash field1
(integer) 1
redis> HDEL myhash field2
(integer) 0

Delete one or more hash fields

Comments