Memcached - Prepend Data
Memcached prepend command is similar to append command which is used to add some data in an existing key. But, append command adds new data after existing data and prepend command add new data before existing data.
key: It is the key of the data stored and retrieved from memcached.
flags: flags is the 32-bit unsigned integer that the server stores with the data (which is provided by the user), and returns along with the data when the item is retrieved.
exptime: exptime is expiration time in seconds. 0 means no delay. If it is more than 30 days, memcached uses it as UNIX timestamp for expiration.
bytes: bytes is the number of bytes in the data block that requires to be stored. This is the length of the data that is stored in memcached.
noreply: It is an optional parameter. It is used to inform the server to not to send any reply.
value: value is the data that have to be stored. The data needs to be passed on the new line after executing the command with the above options.
This command will return the following value:
Example in Ubuntu
Let's see an example for prepend command. Here, we try to add some data that does not exist. Therefore, it returns NOT_STORED. After this, we set a key and append data into it.
Example in Windows
Prepend data using Java Application
Consider that memcached server is running on host 127.0.0.1 and port 11211. Here, we will use prepend() method to prepend data in memcached server.
Connection to server successfully set status:true Get from Cache:bangalore Prepend to cache:true Get from Cache:delhibangalore