Easy Tutorial
❮ Memcached Get Data Memcached Add Data ❯

Memcached incr and decr Commands

The Memcached incr and decr commands are used to increment or decrement the numeric value of an existing key.

The data operated on by the incr and decr commands must be a 32-bit unsigned decimal integer.

If the key does not exist, it returns NOTFOUND. If the value of the key is not a number, it returns CLIENTERROR. Other errors return ERROR.


incr Command

Syntax:

The basic syntax format for the incr command is as follows:

incr key increment_value

Parameter descriptions are as follows:

Example

In the following example, we use "visitors" as the key with an initial value of 10, and then perform an addition of 5.

set visitors 0 900 2
10
STORED
get visitors
VALUE visitors 0 2
10
END
incr visitors 5
15
get visitors
VALUE visitors 0 2
15
END

Output

Output information descriptions:


decr Command

The basic syntax format for the decr command is as follows:

decr key decrement_value

Parameter descriptions are as follows:

Example

set visitors 0 900 2
10
STORED
get visitors
VALUE visitors 0 2
10
END
decr visitors 5
5
get visitors
VALUE visitors 0 1
5
END

In the following example, we use "visitors" as the key with an initial value of 10, and then perform a subtraction of 5.

Output

Output information descriptions:

❮ Memcached Get Data Memcached Add Data ❯