ZINCRBY
ZINCRBY key increment member
- Group
- Sorted set
- Complexity
- O(log(N)) where N is the size of the sorted set
- 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
ZINCRBY adds increment to the score of member in the sorted set at key
and returns the new score. A missing member is added with increment as its
score, and a missing key is created. Use a negative increment to subtract.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Bulk string: the new score | Double: the new score |
Errors:
WRONGTYPEifkeyholds a value that is not a sorted set.ERR value is not a valid floatifincrementis not a number.ERR resulting score is not a number (NaN)if the sum would be NaN (for example adding-infto a score ofinf). Nothing changes in that case.
Examples
Section titled “Examples”127.0.0.1:6379> ZADD board 100 "alice"(integer) 1127.0.0.1:6379> ZINCRBY board 15 "alice""115"127.0.0.1:6379> ZINCRBY board -2.5 "bob""-2.5"Compatibility
Section titled “Compatibility”Same replies as Redis 7.4 and Valkey 8. HotKV checks the key’s type before the
increment, so a bad increment on a key of another type replies WRONGTYPE
rather than the float error.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.