Latest web development tutorials

Memcached add command

Memcached add command is used tovalue (data value) stored in the specified key (key).

If you add the key already exists, the data is not updated, the previous value will remain the same, and you will get a responseNOT_STORED.

grammar:

The basic syntax add command is as follows:

add key flags exptime bytes [noreply]
value

Parameters are as follows:

  • key: key key-value structure key, it is used to find the cache value.
  • flags: may include a key-value pair of integer parameter, the client uses it to store additional information about the key-value pairs.
  • exptime: save key-value pairs in the cache the length of time (in seconds, 0 means forever)
  • bytes: number of bytes stored in the cache
  • noreply (optional): This parameter tells the server does not need to return data
  • value: the value stored (always located in the second row) (can be directly understood as key-value structure value)

Examples

We set the following examples:

  • key → new_key
  • flag → 0
  • exptime → 900 (in seconds)
  • bytes → 10 (the number of bytes of 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

Export

If the data is added successfully, the output:

STORED

Output information Description:

  • STORED: After successfully saved output.
  • NOT_STORED: After the failure to maintain output.