Redis Hincrby Command
The Redis Hincrby command is used to add the specified increment value to the value of a field in a hash table.
The increment can also be a negative number, which is equivalent to performing a subtraction operation on the specified field.
If the key of the hash table does not exist, a new hash table is created and the HINCRBY command is executed.
If the specified field does not exist, the value of the field is initialized to 0 before executing the command.
Executing the HINCRBY command on a field that stores a string value will cause an error.
The value of this operation is limited to a 64-bit signed number representation.
Syntax
The basic syntax of the redis Hincrby command is as follows:
redis 127.0.0.1:6379> HINCRBY KEY_NAME FIELD_NAME INCR_BY_NUMBER
Available Versions
>= 2.0.0
Return Value
The value of the field in the hash table after executing the HINCRBY command.
Examples
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 redis>Other Extensions
Redis Hash