def setup_memcache(*args, **kwargs): '''Configures the app engine memcache interface with a set of regular memcache servers. All arguments are passed to the memcache.Client constructor. Example: setup_memcache(["localhost:11211"]) ''' client = memcache.Client(*args, **kwargs) # The appengine memcache interface has some methods that aren't # currently available in the regular memcache module (at least # in version 1.4.4). Fortunately appstats doesn't use them, but # the setup_client function expects them to be there. client.add_multi = None client.replace_multi = None client.offset_multi = None # Appengine adds a 'namespace' parameter to many methods. Since # appstats.recording uses both namespace and key_prefix, just drop # the namespace. (This list of methods is not exhaustive, it's just # the ones appstats uses) for method in ('set_multi', 'set', 'add', 'delete', 'get', 'get_multi'): def wrapper(old_method, *args, **kwargs): # appstats.recording always passes namespace by keyword if 'namespace' in kwargs: del kwargs['namespace'] return old_method(*args, **kwargs) setattr(client, method, functools.partial(wrapper, getattr(client, method))) appengine_memcache.setup_client(client)
def init_memcache(): client = pylibmc.Client([keys.get('redis_memcache_endpoint')], binary=True, username='******', password=keys.get('redis_memcache_password')) # Non-existent functions necessary to adhere to the memcache API expected by gae_memcache's setup_client() client.set_servers = None client.forget_dead_hosts = None client.debuglog = None client.replace_multi = None client.offset_multi = None if gae_memcache: # Try to use this redis memcache for all GAE stuff seamlessly gae_memcache.setup_client(client) return client
def SetupClient(): """Sets memcache wrapper. See module level doc.""" memcache.setup_client(_WrapperClient())