YouTip LogoYouTip

Memcached Add Data

# Memcached add Command The Memcached add command is used to store a **value (data value)** in a specified **key**. If the key for the add command already exists, the data will not be updated (an expired key will be updated). The previous value will remain the same, and you will receive a **NOT_STORED** response. ### Syntax: The basic syntax format for the add command is as follows: add key flags exptime bytes value The parameters are explained as follows: * **key:** The key in the key-value structure, used to look up 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 (in seconds) to keep the key-value pair in the cache (0 means forever). * **bytes:** The number of bytes to store in the cache. * **noreply (optional):** This parameter tells the server that no response is needed. * **value:** The value to store (always on the second line) (can be 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 will be: STORED Output message explanation: * **STORED:** Output after a successful save. * **NOT_STORED:** Output after a failed save.
← Memcached Delete KeyMemcached Get Data β†’