DECR key
Decrement the number stored at key by one. 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: DECR 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: DECR KEY_NAME
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>redis:6379> DECR redisKey(integer) 99
Output:
99
Example 2: When the value of the key is not an integer.
redis:6379> SET redisKey1 100.99"OK"redis:6379> DECR redisKey1(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+20"OK"redis:6379>redis:6379> DECR redisKey2(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