Memcached add Command

The Memcached add command is used tovalue (data value)store in the specifiedkeyin.

If the key of add already exists, the data will not be updated (expired keys will be updated), the previous value will remain the same, and you will get a response.NOT_STORED。

Syntax:

The basic syntax format of the add command is as follows:

add key flags exptime bytes [noreply]
value

The parameter descriptions are 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 save 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 → new_key
  • flag → 0
  • exptime → 900 (in seconds)
  • bytes → 10 (number of bytes for data storage)
  • value → data_value
add new_key 0 900 10
data_value
STORED
get new_key
VALUE new_key 0 10
data_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 saving fails.
Other extensions