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

Memcached set command


May 17, 2021 Memcached



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

If the set key already exists, the command can update the original data corresponding to the key, which is what the implementation of the update does.

Grammar:

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

set 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 → w3cschool
  • flag → 0
  • exptime → 900 (in seconds)
  • Bytes → 9 (bytes of data storage)
  • value → memcached
set w3cschool 0 900 9
memcached
STORED

get w3cschool
VALUE w3cschool 0 9
memcached

END

Output

If the data setup is successful, the output:

STORED

Output information description:

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