Important Utility Commands in Redis
Learn about the common utility commands used in Redis.
We'll cover the following...
Let’s explore a few utility commands provided by Redis to perform operations on the data stored.
The DECR and DECRBY commands
As the name suggests, the DECR command is used to decrement a value by one. On the other hand, the DECBY command is used to decrement the value by the number specified in the command. Both commands can be performed on string values, which can be converted to integers. If the key specified doesn’t exist, each of the commands creates a key-value pair with the value 0 and then performs the decrement operation. Both commands return the value after performing the decrement operation.
Syntax and example
The syntax of the DECR and DECRBY commands is shown below:
DECR keyDECRBY key decrement_value
An example to decrement the value for the key price by 1 and to decrement the value of the key offer by 20 is given below:
DECR priceDECRBY offer 20
The commands above return the values after decrementing them by 1 and 20, respectively.
The INCR and INCRBY commands
Similar to the decrement operation, the INCR command is used to increment a value by one. On the other hand, the INCRBY command is used to increment a value by the number specified in the command. Both commands can be performed on string values, which can be converted to integers. If the key specified doesn’t exist, each of the commands creates a key-value pair with the value 0 and then performs the ...