#!/usr/bin/env python from datetime import datetime from zlib import adler32 import memcache #TODO: Support other lib import getset_bson from store_stub import * memcache.serverHashFunction = adler32 getset_bson.monkey_patch(memcache.Client) class SessionStore(object): #TODO: allow to use an existing connection def __init__(self, host=None, port=None, key_prefix=None, **kwargs): self.host = host or '127.0.0.1' self.port = port or 11211 self.key_prefix = key_prefix or 'soullive.session-' @property def conn(self): try: return self._conn except: self._conn = memcache.Client([self.host + ':' + str(self.port)]) return self._conn
#!/usr/bin/env python from datetime import datetime import redis import getset_bson from store_stub import * getset_bson.monkey_patch(redis.Redis) class SessionStore(object): #TODO: allow to use an existing connection def __init__(self, host=None, port=None, key_prefix=None, **kwargs): self.host = host or '127.0.0.1' self.port = port or 6379 self.key_prefix = key_prefix or 'soullive.session-' @property def conn(self): try: return self._conn except: self._conn = redis.Redis(host=self.host, port=self.port, db=0) return self._conn def get_data(self, id): sdat = self.conn.bson_get(self.key_prefix + id)