Tuesday 23 August 2016

Memcached: Add data

Add command is used to ADD new <key, value> pair, if the key doesn’t exist. Don’t confuse with SET command, ADD is to only work when a key doesn't already exist, while SET is there to update the value, regardless of whether it already exists.

Syntax
add key flags exptime bytes [noreply] value

Following table summarizes the arguments of set command.

Argument
Description
key
Name of the key.
flags
It is 32-bit unsigned integer, stored along with the data in the server and retrieved when you get the <key value> pair.
exptime
Expiry time of the data stored in cache. It is represented in seconds.
bytes
length of the data in bytes that needs to be stored in Memcached.
noreply
It is optional, when you pass this parameter, server don’t send any reply back to you.
value
Value to be stored in Memcached server.

Open new terminal and use telnet to connect to memcached server.
telnet <hostname> <port>


By default memcached server listen on port 11211.
$ telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
add E529512 0 900 11 
harikrishna
STORED
add E432123 0 900 4
gopi
STORED
get E529512
VALUE E529512 0 11
harikrishna
END


Just try to override the data associated with key E529512 by using add command. You can able to get NOT_STORED error.
add E529512 0 900 11 
Ramakrishna
NOT_STORED


You can able to override the data by using set command.
get E529512
VALUE E529512 0 11
harikrishna
END
set E529512 0 900 11 
Ramakrishna
STORED
get E529512
VALUE E529512 0 11
Ramakrishna
END




Previous                                                 Next                                                 Home

No comments:

Post a Comment