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

# 對(duì)存在的數(shù)字值 key 進(jìn)行 DECR
redis> SET failure_times 10
OK
redis> DECR failure_times
(integer) 9
# 對(duì)不存在的 key 值進(jìn)行 DECR
redis> EXISTS count
(integer) 0
redis> DECR count
(integer) -1
# 對(duì)存在但不是數(shù)值的 key 進(jìn)行 DECR
redis> SET company YOUR_CODE_SUCKS.LLC
OK
redis> DECR company
(error) ERR value is not an integer or out of range