English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

The Redis Decr command

Redis Strings (string)

The Redis Decr command will subtract one from the numeric value stored in the key.

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

If the value contains an incorrect type, or if the string type value cannot be represented as a number, an error is returned.

The value of this operation is limited to 64 Within the range of signed numbers represented by bits.

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 Values

The value of the key after executing the command.

Online Examples

# Decrement for existing numeric value keys
redis> SET failure_times 10
OK
redis> DECR failure_times
(integer) 9
# Decrement for non-existing key values
redis> EXISTS count
(integer) 0
redis> DECR count
(integer) -1
# Decrement for keys that exist but are not numbers
redis> SET company YOUR_CODE_SUCKS.LLC
OK
redis> DECR company
(error) ERR value is not an integer or out of range

Redis Strings (string)