Redis – String Decr Command

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

Redis DECR command is used to decrement the integer value of a key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned, if the key contains a value of the wrong type or contains a string that cannot be represented as an integer. This operation is limited to 64 bit signed integers.

Return Value

Integer reply, the value of the key after the increment.

Syntax

Following is the basic syntax of Redis DECR command.

redis 127.0.0.1:6379> DECR KEY_NAME

Example

redis 127.0.0.1:6379> SET visitors 1000 
OK 
redis 127.0.0.1:6379> DECR visitors 
(integer) 999 
redis 127.0.0.1:6379> SET visitors "1313131231231231231231" 
Ok 
redis 127.0.0.1:6379> DECR visitors 
ERR value is not an integer or out of range

Leave a Reply