English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Hincrby Command

Redis Hashes (Hash)

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

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

If the hash table key 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 string values will cause an error.

The value of this operation is limited to 64 It is represented by a signed number within the range of bits.

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 Version

>= 2.0.0

Return Value

The value of the field in the hash table after executing the HINCRBY command.

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

Redis Hashes (Hash)