# DECR

> Subtract 1 from the integer stored at a key.

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

```
DECR key
```

- Group: String
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`DECR` subtracts 1 from the number stored at `key` and returns the new value.
A missing key counts as `0`, so the first `DECR` creates it with `-1`. The
value must be the decimal text of a signed 64-bit integer, 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 the stored value is not
  an integer.
- `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 stock 3
OK
127.0.0.1:6379> DECR stock
(integer) 2
127.0.0.1:6379> DECR fresh
(integer) -1
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[DECRBY](https://docs.hotkv.com/commands/decrby/index.md), [INCR](https://docs.hotkv.com/commands/incr/index.md),
[INCRBY](https://docs.hotkv.com/commands/incrby/index.md)