decr
DECR
Decrement by 1
Decrements the number by 1.
If the key does not exist, it uses 0 as the base, subtracts 1, and returns -1.
Example
| Command> | decr key
|
| Result> | -1
|
| Command> | decr key
|
| Result> | -2
|
| Command> | set key 10
|
| Result> | OK
|
| Command> | decr key
|
| Result> | 9
|
View animation
Error
An error occurs if you run decr on a string, or if the result of decr exceeds the integer range.
Redis integers are 64-bit signed integers. The range is
-9,223,372,036,854,775,808(264) ~ 9,223,372,036,854,775,807(263-1).
Example
| Command> | set key Hello
|
| Result> | OK
|
| Command> | decr key
|
| Result> | ERR value is not an integer or out of range
|
| Command> | set key -234293482390480948029348230948 This is not a number; it is stored as a string |
| Result> | OK
|
| Command> | decr key
|
| Result> | ERR value is not an integer or out of range
|
| Command> | set key -9223372036854775808 Smallest negative integer -264 |
| Result> | OK |
| Command> | decr key |
| Result> | ERR increment or decrement would overflow |
Syntax
DECR key
- Available since version 1.0.0.
- Time complexity is O(1).