Easy Tutorial
❮ Memcached Cas Memcached Delete Key ❯

Memcached replace Command

The Memcached replace command is used to replace the value of an existing key.

If the key does not exist, the replacement fails, and you will receive the response NOT_STORED.

Syntax:

The basic syntax format for the replace command is as follows:

replace key flags exptime bytes [noreply]
value

Parameter descriptions are as follows:

Example

In the following example, we set:

In this 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 descriptions are as follows:

❮ Memcached Cas Memcached Delete Key ❯