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

Memcached add command


May 17, 2021 Memcached



The Memcached add command is used to store value (data value) in the specified key (key).

If the key of add already exists, the data is not updated, the previous values will remain the same, and you will get a response NOT_STORED.

Grammar:

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

add 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 → new_key
  • flag → 0
  • exptime → 900 (in seconds)
  • Bytes → 10 (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

Output

If the data is added successfully, the output:

STORED

Output information description:

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