DECRBY command in redis

DECRBY key integer

Decrement the number stored at the key by a given number. If the key does not exist or contains a value of the wrong type, set the key to the value of "0" before performing the decrement operation.

TIME COMPLEXITY: O(1)

Note: DECRBY  commands are limited to 64-bit signed integers.

RETURN VALUE: Integer reply, this command will reply with the new value of the key after the decrement.

Syntax: DECRBY KEY_NAME value

SET redisKey 100

Example 1: When the value of the key is an integer and in the range of 64-bit.

redis:6379> SET redisKey 100
"OK"
redis:6379> DECRBY redisKey 10
(integer) 90

Output:

90

Example 2: When the value of the key is not an integer.

redis:6379> SET redisKey1 100.89
"OK"
redis:6379> DECRBY redisKey1 10
(error) value is not an integer or out of range

Output:

(error) value is not an integer or out of range


Example 3: When the value of the key is out of range of 64-bit.

redis:6379> SET redisKey2 1.8446744e+21
"OK"
redis:6379> DECRBY redisKey2 10
(error) value is not an integer or out of range

Output:

(error) value is not an integer or out of range


No comments:

Post a Comment