Which Python module to use for Memcached?

I am implementing caching for my Python application and I want to use memcached. Which module do you suggest me to use? There are so many that I don’t know which one to choose.

Thanks, Boda Sido.

+4
source share
3 answers

I am using python-memcached and there are good tips for using the source code referenced in this answer .

Use the third parameter to set the expiration date.

From the linked memcached.html help file:

 set(self, key, val, time=0, min_compress_len=0) 

So

 mc.set(key, val, time) 

More info and exmaples here

+4
source

I use cmemcache, which is more efficient (but no more mantained). As the developer suggests, you can switch to http://code.google.com/p/python-libmemcached .

+2
source

I use python-memcache because:

from the memcached.py header:

  import memcache mc = memcache.Client(['127.0.0.1:11211'], debug=0) mc.set("some_key", "Some value") value = mc.get("some_key") mc.set("another_key", 3) mc.delete("another_key") mc.set("key", "1") # note that the key used for incr/decr must be a string. mc.incr("key") mc.decr("key") 

or use as part of the Django framework: ( details here )

 >>> from django.core.cache import cache >>> cache.set('my_key', 'hello, world!', 30) >>> cache.get('my_key') 'hello, world!' 
+1
source

Source: https://habr.com/ru/post/1305234/


All Articles