Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Memcached replace command


May 17, 2021 Memcached



The Memcached replace command replaces the value of the key (key) that already exists.

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

Grammar:

The basic syntax of the replace command is as follows:

replace key flags exptime bytes [noreply]
value

The parameters are described below:

  • Key: Key in the key-value structure to find cached values.
  • flags: You can include integer parameters for key value pairs, which the client uses to store additional information about key value pairs.
  • exptime: The length of time (in seconds, 0 means forever) to save key pairs in the cache
  • Bytes: The number of bytes stored in the cache
  • Noreply (optional): This parameter tells the server that no data needs to be returned
  • value: Stored value (always on the second row) (can be understood directly as value in key-value structure)

Instance

In the following example we set:

  • key → mykey
  • flag → 0
  • exptime → 900 (in seconds)
  • Bytes → 10 (bytes of data storage)
  • value → data_value

In the following example we use the key bit 'mykey' and store the corresponding value data_value. After execution we replace the value of the same key as '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:

STORED

Output information description:

  • STORED: The output after the successful save.
  • NOT_STORED: Output after replacement failure.