INCRBY key integer
Increment the number stored at the key by the given value. 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 increment or decrement operation.
TIME COMPLEXITY: O(1)
Note: INCRBY 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 increment or decrement.
Syntax:
INCRBY KEY_NAME VALUE
Example 1: When the value is in the range of 64-bit.
redis:6379> SET MY_KEY 100"OK"redis:6379> INCRBY MY_KEY 100(integer) 200
Output
200
Example 2: When the value is not an integer.
redis:6379> SET MY_KEY 100.717"OK"redis:6379> INCRBY MY_KEY 100(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 is out of range of 64-bit
redis:6379> SET MY_KEY 1.8446744e+20"OK"redis:6379> INCRBY MY_KEY 100(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