Tuesday 23 August 2016

Memcached: Replace Data

REPLACE command is used to replace the value of an existing key. If the key don’t exists, then it return ‘NOT_STORED’.

Syntax
replace key flags exptime bytes [noreply] value

Following table summarizes the arguments of replace 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 '^]'.
set 1 0 900 11
harikrishna
STORED
get 1
VALUE 1 0 11
harikrishna
END
replace 1 0 900 4
gopi
STORED
get 1
VALUE 1 0 4
gopi
END


Now to try to replace a value, where key don’t exist, you will get error like ‘NOT_STORED’.
get 2
END
replace 2 0 900 4
gopi
NOT_STORED



Previous                                                 Next                                                 Home

No comments:

Post a Comment