HINCRBY command in redis

HINCRBY key field value

Increment the number stored at the field in the hash at key by value. If the key does not exist, a new key holding a hash is created. If the field does not exist or holds a string, the value is set to 0 before applying the operation.

TIME COMPLEXITY: O(1)

The range of values supported by HINCRBY is limited to 64-bit signed integers.

RETURN VALUE: Integer reply - The new value at the field after the increment operation.

Syntax:

HINCRBY KEY_NAME FIELD_NAME VALUE

Example 1: When the value is an integer.

redis:6379> HSET myhash field 100
(integer) 1
redis:6379> HINCRBY myhash field 100
(integer) 200

Output

200

Example 2: When the value of the key is a String

redis:6379> HSET myhash2 field "hello"
(integer) 1
redis:6379> HINCRBY myhash2 field 10
(error) hash value is not an integer

Output

(error) the hash value is not an integer


No comments:

Post a Comment