Memcache Common methods
Storage command: set/add/replace/append/prepend/
Get command: Get/gets
Other commands: Delete/stats
Add method: Adds a key value pair, if key exists, repeat add will error
Replace method: Replace modifies the value of a key, or the exception if key does not exist.
Import MEMCACHEMC = Memcache. Client ([(' 192.168.88.102:11211 ')],debug=true) #add (key,value) mc.add ("Name5", "Cnblogs") Print Mc.get ("Name5") # Replacemc.replace ("Name5", "Hello World") print Mc.get ("Name5") Mc.set ("K2", "V2") Print Mc.get ("K2")
Operation Result:
Cnblogshello Worldv2
Set and Set_multi methods
Set: Sets a key-value pair, if key does not exist, is created if key exists, then modified;
Set_multi: Sets multiple key-value pairs, if key does not exist, is created and modified if key exists.
Import MEMCACHEMC = Memcache. Client ([(' 192.168.88.102:11211 ')],debug=true) Mc.set_multi ({"k100": "V100", "k101": "v101", "k102": "v102"}) Print Mc.get_multi (["K100", "k101", "k102"])
Operation Result:
{' k100 ': ' v100 ', ' k101 ': ' v101 ', ' k102 ': ' v102 '}
Import MEMCACHEMC = Memcache. Client ([(' 192.168.88.102:11211 ')],debug=true) Mc.set_multi ({"Test1": "Vale2", "test2": "value2", "test3": "Value3", " Test4 ":" Value4 ",}) print Mc.get_multi ([" Test1 "," Test2 "," Test3 "," test4 "]) mc.delete (" Test1 ") Mc.delete_multi ([" Test2 "," Test3 "]) print Mc.get_multi ([" Test1 "," Test2 "," Test3 "," test4 "]) Run Result: {' test1 ': ' Vale2 ', ' test3 ': ' Value3 ', ' Test2 ': ' value2 ', ' test4 ': ' Value4 '} {' test4 ': ' Value4 '}
Append and prepend method append: Modifies the value of the specified key, appends the value to it, and prepend: Modifies the value of the specified key to insert the contents before the value. MC = Memcache. Client ([(' 192.168.88.102:11211 ')],debug=true) Mc.set_multi ({"Test1": "Vale2", "test2": "value2", "test3": "Value3", " Test4 ":" Value4 ",}) Mc.append (" Test1 "," Ling ") print Mc.get (" Test1 ") mc.prepend (" Test2 "," Hello ") print mc.get (" Test2 ") Running Result: vale2linghellovalue2
(vii) Common methods of 7-4memcache