Memcached replace command
The Memcached replace command is used to replace an existingkeyofvalue (data value)。
If the key does not exist, the replacement fails, and you will receive a responseNOT_STORED。
Syntax:
The basic syntax format of the replace command is as follows:
replace key flags exptime bytes [noreply] value
The 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 can include key-value pairs; the client uses it to store additional information about the key-value pair.
- exptime: The length of time (in seconds) to store the key-value pair in the cache; 0 means forever.
- bytes: The number of bytes stored in the cache.
- noreply (optional): This parameter tells the server not to return data.
- value: The stored value (always on the second line) (can be directly understood as the value in the key-value structure).
Examples
In the following example, we set:
- key → mykey
- flag → 0
- exptime → 900 (in seconds)
- bytes → 10 (number of bytes for data storage)
- value → data_value
In the following example, we use the key 'mykey' and store the corresponding value data_value. After execution, we replace the value of the same key with 'some_other_value'.
add mykey 0 900 10 data_value STORED get mykey VALUE mykey 0 10 data_value END replace mykey 0 900 16 some_other_value get mykey VALUE mykey 0 16 some_other_value END
Output
If the data is added successfully, the output is:
STORED
Output information description:
- STORED: Output after saving successfully.
- NOT_STORED: Output after a failed replacement.