UK ['dɪkr] US ['dɪkr]

abbr.decrease reduce; become less; decrement(al)(ly) reduce; decrease

redis DECR command syntax

Function:Decrease the numerical value stored in key by one.

Syntax:DECR key

Description:If key does not exist, the value of key will be initialized to 0 first, and then DECR will be executed operate. If the value contains the wrong type, or a value of type string cannot be represented as a number, an error is returned. The value of this operation is limited to 64-bit signed number representation.

Available versions:>= 1.0.0

Time complexity:O(1)

Return:The value of key after executing the DECR command.

redis DECR 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