Redis Decr command
The Redis Decr command decrements the numeric value stored in key by one.
If the key does not exist, its value is first initialized to 0, then the DECR operation is performed.
If the value holds the wrong type, or a string value cannot be represented as a number, an error is returned.
The value of this operation is limited to a 64-bit signed integer representation.
Syntax
The basic syntax of the redis Decr command is as follows:
redis 127.0.0.1:6379> DECR KEY_NAME
Available Version
= 1.0.0
Return Value
The value of key after the command is executed.
Example
# DECR the existing numeric value key
redis> SET failure_times 10
OK
redis> DECR failure_times
(integer) 9
# DECR non-existent key
redis> EXISTS count
(integer) 0
redis> DECR count
(integer) -1
# DECR key that exists but is not a number
redis> SET company YOUR_CODE_SUCKS.LLC
OK
redis> DECR company
(error) ERR value is not an integer or out of range
Redis string