Memcached Set Operation with Python Example


Set is most used command in Memcached. Its store data. If the data exists it will be over written. New data is always added at the top of the LRU. LRU means Last Recently Used.  Syntax of the set is like below.

set key flags expiretime size 
value

Now we will add and url  with set operation.

set poftut 0 1000 4 
test 
STORED
  • set is the operation
  • poftut is the key to find data
  • is the flag so there is no flag
  • 1000 is the seconds to hold value in Memcached. After that value is deleted
  • is the size of the value
  • test is the value we want to save
  • STORE means it is saved successfully

Let’s check the value we have saved. Keep in mind that we have 1000 seconds to check after that time the value will not exists.

get poftut 
VALUE poftut 0 4 
test 
END

Python Application

import memcache 
client=memcache.Client([('127.0.0.1',11211)]) 
samp={"poftut":"test"} 
client.set("poftut",samp,time=1000)

LEARN MORE  Python Modules Tutorial With Examples

Leave a Comment