Memcached set Command
The Memcached set command is used to store value (data value) in the specified key it.
If the key for set already exists, this command can update the original data corresponding to the key, that is, it achieves an update.
Syntax:
The basic syntax format of the set command is as follows:
set key flags exptime bytes [noreply]
value
The parameters are described as follows:
- **key:** the key in the key-value structure, used to look up the cached value.
- flags: can include an integer parameter of the key-value pair, which the client uses to store extra information about the key-value pair .
- exptime: the length of time to keep the key-value pair in the cache (in seconds, 0 means forever)
- bytes: the number of bytes stored in the cache
- noreply (optional): this parameter tells the server that it does not need to return data
- value: the stored value (always on the second line) (can be understood directly as the value in the key-value structure)
Example
In the following example we set:
- key → runoob
- flag → 0
- exptime → 900 (in seconds)
- bytes → 9 (number of bytes of stored data)
- value → memcached
set runoob 0 900 9
memcached
STORED
get runoob
VALUE runoob 0 9
memcached
END
Output
If the data is set successfully, it outputs:
STORED
Description of the output information:
- STORED: output after a successful save.
- ERROR: output after a failed save.