Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Hincrby Command

Redis Hincrby Command

Redis Hash

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

The increment can also be negative, which is equivalent to subtracting from the specified field.

If the hash key 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 holding a string value will cause an error.

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

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