May 17, 2021 Memcached
The Memcached incr and decr commands are used to self-increase or subtract the numeric values of existing keys.
The data operated by the incr and decr commands must be a decal 32-bit unsigned integer.
If key does not NOT_FOUND, if the value of the key is not a number, CLIENT_ERROR returns and other errors return ERROR.
The basic syntax format of the incr command is as follows:
incr key increment_value
The parameters are described below:
In the following example, we use visitors as key, with an initial value of 10, followed by plus 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 information description:
The basic syntax format of the decr command is as follows:
decr key decrement_value
The parameters are described below:
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 key, with an initial value of 10, followed by minus 5.
Output information description: