Memcached prepend command
May 17, 2021
Memcached
The Memcached prepend command is used to
append data before the value
(data value) of an existing
key .
Grammar:
The basic syntax format of the prepend command is as follows:
prepend 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
Here's an example:
-
First we store a key w3cschool in Memcached, which has a value of memcached.
-
We then use the get command to retrieve the value.
-
Then, we use the
prepend command
to append "redis" after the key for the value of w3cschool.
-
Finally, we use the get command to retrieve the value.
set w3cschool 0 900 9
memcached
STORED
get w3cschool
VALUE w3cschool 0 14
memcached
END
prepend w3cschool 0 900 5
redis
STORED
get w3cschool
VALUE w3cschool 0 14
redismemcached
END
Output
If the data is added successfully, the output:
STORED
Output information description:
-
STORED:
The output after the successful save.
-
NOT_STORED:
The key does not exist on Memcached.
-
CLIENT_ERROR:
Execution error.