Memcached set Command
The Memcached set command is used to store a value in the specified key.
If the key already exists, this command can update the original data associated with that key, thus serving an update function.
Syntax:
The basic syntax format for the set command is as follows:
set key flags exptime bytes [noreply]
value
Parameter descriptions are as follows:
key: The key in the key-value structure used to look up the cached value.
flags: An integer parameter that the client can use to store additional information about the key-value pair.
exptime: The duration for which the key-value pair is stored in the cache (in seconds, 0 means forever).
bytes: The number of bytes stored in the cache.
noreply (optional): This parameter informs the server that no response is needed.
value: The value to be stored (always on the second line), directly understood as the value in the key-value structure.
Example
In the following example, we set:
key → tutorialpro
flag → 0
exptime → 900 (in seconds)
bytes → 9 (number of bytes of data stored)
value → memcached
set tutorialpro 0 900 9 memcached STORED get tutorialpro VALUE tutorialpro 0 9 memcached END
Output
If the data is set successfully, the output will be:
STORED
Output information explanation:
STORED: Output after successful save.
ERROR: Output after a failed save.