Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Decrby command

Redis Decrby command

Redis string

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

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

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

The value of this operation is limited to a 64-bit signed integer 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 Version

= 1.0.0

Return Value

The value of key after subtracting the specified decrement.

Example



# DECRBY existing key



redis> SET count 100

OK



redis> DECRBY count 20

(integer) 80





# DECRBY non-existent key



redis> EXISTS pages

(integer) 0



redis> DECRBY pages 10

(integer) -10

Redis string