Latest web development tutorials

Redis Decr command

Redis string (string)

Redis Decr command key stored digital value minus one.

If the key is not present, then the value of the key will first be initialized to 0, and then perform operations DECR.

If the value type or string type containing the error can not be expressed as a number, it returns an error.

This operation is limited to the value of 64-bit (bit) signed within the digital representation.

grammar

redis Decr basic command syntax is as follows:

redis 127.0.0.1:6379> DECR KEY_NAME 

Available versions

> = 1.0.0

return value

After executing the command key value.

Examples

# 对存在的数字值 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 (string)