Memcached set command
The Memcached set command is used to storevalue (data value)in the specifiedkey.
If the key of set already exists, this command can update the original data corresponding to that key, thereby achieving the update function.
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 find the cached value.
- flags: an integer parameter that can include key-value pairs; the client uses it to store additional 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 directly understood as the value in the key-value structure)
Example
In the following example we set:
- key → example
- flag → 0
- exptime → 900 (in seconds)
- bytes → 9 (number of bytes for data storage)
- value → memcached
set example 0 900 9 memcached STORED get example VALUE example 0 9 memcached END
Output
If the data is set successfully, the output is:
STORED
Description of output information:
- STORED: output when saved successfully.
- ERROR: output when saving fails.