HINCRBY
HINCRBY key field increment
- Group
- Hash
- Complexity
- O(1)
- Arity
- 4 (exactly, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
HINCRBY adds increment to the integer stored in field of the hash at
key and returns the new value. A missing key or field starts at 0. Use a
negative increment to subtract. The field keeps any time to live it already
had.
The increment and the stored value must both be signed 64-bit integers written in plain decimal form.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Integer: the value after the increment | Same |
Errors:
ERR value is not an integer or out of rangeifincrementis not an integer.WRONGTYPEifkeyholds a value that is not a hash.ERR hash value is not an integerif the field holds something that is not an integer.ERR increment or decrement would overflowif the result does not fit in a signed 64-bit integer.
Examples
Section titled “Examples”127.0.0.1:6379> HSET stats:page views 10(integer) 1127.0.0.1:6379> HINCRBY stats:page views 5(integer) 15127.0.0.1:6379> HINCRBY stats:page views -20(integer) -5127.0.0.1:6379> HINCRBY stats:page clicks 1(integer) 1Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.