...

/

Important Redis Commands

Important Redis Commands

Learn about the common utility commands used in Redis.

Let’s explore a few more utility commands provided by Redis to perform operations on the data stored.

Mathematical operations

We will discuss four mathematical operations performed on integer data in Redis.

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 DECRBY 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 key
DECRBY key decrement_value
Syntax of the DECR and DECRBY commands

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 price
DECRBY offer 20
Example of the DECR and DECRBY commands

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 ...