# DECRBY

> Subtract an integer from the integer stored at a key.

URL: https://docs.hotkv.com/commands/decrby/

```
DECRBY key decrement
```

- Group: String
- Complexity: O(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.

## Return value

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

## Examples

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

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[DECR](https://docs.hotkv.com/commands/decr/index.md), [INCRBY](https://docs.hotkv.com/commands/incrby/index.md),
[INCRBYFLOAT](https://docs.hotkv.com/commands/incrbyfloat/index.md)