Redis Decr Command

Redis String

The Redis Decr command decrements the numeric value stored in the key by one.

If the key does not exist, the key's value will first be initialized to 0, and then the DECR operation will be performed.

If the value is of the wrong type, or a string-type value cannot be represented as a number, an error is returned.

The value of this operation is limited to a 64-bit signed number representation.

Syntax

The basic syntax of the Redis Decr command is as follows:

redis 127.0.0.1:6379> DECR KEY_NAME 

Available Versions

>= 1.0.0

Return Value

The value of the key after executing the command.

Example

# 对存在的数字值 key 进行 DECR

redis> SET failure_times 10
OK

redis> DECR failure_times
(integer) 9


# 对不存在的 key 值进行 DECR

redis> EXISTS count
(integer) 0

redis> DECR count
(integer) -1


# 对存在但不是数值的 key 进行 DECR

redis> SET company YOUR_CODE_SUCKS.LLC
OK

redis> DECR company
(error) ERR value is not an integer or out of range

Redis String

Other Extensions