w3resource

Redis Hash: HINCRBY

HINCRBY key field increment

Redis HINCRBY command is used to increment the number stored at the field in the hash stored at key by increment. If the key does not exist, a new key holding a hash is created. If the field does not exist the value is set to 0 before the operation is performed.

Syntax:

HINCRBY KEY_NAME FIELD_NAME INCR_BY_NUMBER 

Available since

2.0.0.

Return Value

Integer reply, the value at the field after the increment operation.

Return Value Type

Integer

Example: Redis HINCRBY

127.0.0.1:6379> HSET langhash lang1 10
(integer) 1
127.0.0.1:6379> HINCRBY langhash lang1 1
(integer) 11
127.0.0.1:6379> HINCRBY langhash lang1 -1
(integer) 10

Example: Redis HINCRBY another example

127.0.0.1:6379> HSET user visits 5
(integer) 1
127.0.0.1:6379> HINCRBY user visits 15
(integer) 20
127.0.0.1:6379> HINCRBY user visits -25
(integer) -5

Previous: HGETALL
Next: HINCRBYFLOAT



Follow us on Facebook and Twitter for latest update.