Redis common commands (3) - Hash

HDEL

格式:HDEL key field [field ...]

Role: Delete one or more fields in the hash table.

Return value: The number of deleted domains.

 

HEXISTS

格式:HEXISTS key field

Function: Determine whether the hash table contains a field field.

Return value: return 1 if it is included, return 0 if it is not included.

 

HGET

Format: HGET key field

Role: Returns the value of the field field in the hash table

Return value: The value of the field field. Returns nil if the field does not exist, or if the hash table does not exist.

 

HGETALL

Format: HGETALL key

Function: Returns all fields and values ​​in the hash table key.

Return value: Field and value in list form.

Example:

192.168.1.100:6379> hset testkey a 1

(integer) 1

192.168.1.100:6379> hset testkey b 2

(integer) 1

192.168.1.100:6379> hgetall testkey

1) "a"

2) "1"

3) "b"

4) "2"

 

HINCRBY

格式:HINCRBY key field increment

Function: Increment the field field in the hash table key. If the hash table does not exist, it is created. If the field does not exist, it is created and initialized to 0, and the operation is performed.

Return value: The value of the field after the operation.

 

HINCRBYFLOAT

格式:HINCRBYFLOAT key field increment

Role: Similar to HINCRBY, but the number of operations is a floating-point number.

Return value: The value of the field after the operation.

 

HKEYS

Format: HKEYS key

Function: Returns all fields in the hash table key.

Return value: All fields in key. Returns an empty list if key does not exist.

Example:

192.168.1.100:6379> hset testkey a 1

(integer) 1

192.168.1.100:6379> hset testkey b 2

(integer) 1

192.168.1.100:6379> hkeys testkey

1) "a"

2) "b"

 

HLEN

Format: HLEN key

Function: Returns the number of fields in the hash table key.

Return value: the number of domains, or 0 if the key does not exist.

 

HMGET

Format: HMGET key field [field ...]

Function: Returns the values ​​of multiple fields in the hash table.

Return value: the values ​​of multiple fields. If the field does not exist, the return value is nil. If the key does not exist, the returned list is all nil.

Example:

192.168.1.100:6379> hmget testkey abc

1) "1"

2) "2"

3) (nil)

192.168.1.100:6379> hmget testkey100 a b c

1) (nil)

2) (nil)

3) (nil)

 

HMSET

格式:HMSET key field value [field value ...]

Role: Set the value of multiple fields in the hash table key.

Return value: return OK on success

 

HSET

Format: HSET key field value

Role: Set the value of the field field in the hash table key.

Return value: If the field does not exist, it will return 1 if the setting is successful, and if the field exists, it will return 0 if the setting is successful.

 

HSETNX

Format: HSETNX key field value

Function: When the field field does not exist in the hash table, create the field field and set the value to value. If the field field already exists, no action is performed.

Return value: set successfully, return 1, otherwise return 0

 

WHALE

Format: HVALS key

Function: Returns the values ​​of all fields in the hash table key.

Return value: The value of all fields. If the key does not exist, return an empty table.

 

Original address: http://caiguoqing.org/post/105

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326724400&siteId=291194637