Skip to content

Instantly share code, notes, and snippets.

Created November 24, 2012 02:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Django spymemcached Jython cache backend.
A memcached library for Jython. Wraps spymemcached.jar.
Very lightly tested; use at your own risk!
Depends on spymemcached (<>).
No fancy features, but it shouldn't be hard to extend.
from import InetSocketAddress
from net.spy.memcached import MemcachedClient, BinaryConnectionFactory
class SpyMemcachedClient(object):
def __init__(self, host, port):
addr = InetSocketAddress(host,port)
self.client = MemcachedClient(BinaryConnectionFactory(), [addr])
def add(self, key, value, timeout=0):
return self.client.add(key, timeout, value)
def get(self, key, default=None):
ret = self.client.get(key)
return ret if ret is not None else default
def set(self, key, value, timeout=0):
return bool(self.client.set(key, timeout, value))
def delete(self, key):
return bool(self.client.delete(key))
def get_many(self, keys):
return self.client.getBulk(keys)
def incr(self, key, delta=1):
return bool(self.client.incr(key, delta))
def decr(self, key, delta=1):
return bool(self.client.decr(key, delta))
def close(self, **kwargs):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment