Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

DECRBY

Last updated
DECRBY key decrement
Group
String
Complexity
O(1)
Arity
3 (exactly, counting the command name)
Flags
write, fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

DECRBY subtracts decrement from the number stored at key and returns the new value. A missing key counts as 0. Both the stored value and decrement must be signed 64-bit integers, and the key keeps its time to live.

Case RESP2 RESP3
Always Integer: the value after the decrement Integer

Errors:

  • ERR value is not an integer or out of range when decrement or the stored value is not an integer.
  • ERR decrement would overflow when decrement is the smallest 64-bit integer (-9223372036854775808), which cannot be negated.
  • ERR increment or decrement would overflow when the result does not fit in a signed 64-bit integer.
  • WRONGTYPE when the key holds a value that is not a string.
127.0.0.1:6379> SET balance 100
OK
127.0.0.1:6379> DECRBY balance 30
(integer) 70
127.0.0.1:6379> DECRBY balance -5
(integer) 75

Same as Redis 7 and Valkey 8.

DECR, INCRBY, INCRBYFLOAT