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:

Get hands-on with 1200+ tech skills courses.