Easy Tutorial
❮ Server Command Getkeys Strings Incr ❯

Redis Decr Command

Redis Strings

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

If the key does not exist, the value of the key is initially set to 0 before performing the DECR operation.

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

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

Syntax

The basic syntax for 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 the command is executed.

Examples

# DECR on an existing numeric key

redis> SET failure_times 10
OK

redis> DECR failure_times
(integer) 9


# DECR on a non-existing key

redis> EXISTS count
(integer) 0

redis> DECR count
(integer) -1


# DECR on an existing key that is not a number

redis> SET company YOUR_CODE_SUCKS.LLC
OK

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

Redis Strings

❮ Server Command Getkeys Strings Incr ❯