Redis Decrby Command

Redis String (string)

The Redis Decrby command subtracts the specified decrement from the value stored at key.

If the key does not exist, the value of the key is first initialized to 0, and then the DECRBY operation is performed.

If the value contains an incorrect type, or 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 representation.

Syntax

The basic syntax of the redis Decrby command is as follows:

redis 127.0.0.1:6379> DECRBY KEY_NAME DECREMENT_AMOUNT

Available Versions

>= 1.0.0

Return Value

The value of key after subtracting the specified decrement.

Example

# 对已存在的 key 进行 DECRBY

redis> SET count 100
OK

redis> DECRBY count 20
(integer) 80


# 对不存在的 key 进行DECRBY

redis> EXISTS pages
(integer) 0

redis> DECRBY pages 10
(integer) -10

Redis String (string)

Other Extensions