Easy Tutorial
❮ Strings Getrange Sorted Sets Zrangebyscore ❯

Redis Hincrby Command

Redis Hashes

The Redis Hincrby command is used to increment the value of a field in a hash by a specified increment value.

The increment can also be negative, which is equivalent to performing a subtraction operation on the specified field.

If the key for the hash does not exist, a new hash is created and the HINCRBY command is executed.

If the specified field does not exist, its value is initialized to 0 before the command is executed.

Executing the HINCRBY command on a field that stores a string value will result in an error.

The value of this operation is limited to a 64-bit signed number.

Syntax

The basic syntax for 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 after the HINCRBY command is executed.

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
redis>

Redis Hashes

❮ Strings Getrange Sorted Sets Zrangebyscore ❯