django-constance/tests/redis_mockup.py

29 lines
733 B
Python
Raw Normal View History

# Shared storage so sync (Connection) and async (AsyncConnection) instances
# operate on the same underlying data, just like a real Redis server would.
_shared_store = {}
class Connection:
2010-08-25 12:11:26 +00:00
def set(self, key, value):
_shared_store[key] = value
def get(self, key, default=None):
return _shared_store.get(key, default)
2010-08-25 12:11:26 +00:00
def mget(self, keys):
return [_shared_store.get(key) for key in keys]
def clear(self):
_shared_store.clear()
class AsyncConnection:
async def set(self, key, value):
_shared_store[key] = value
async def get(self, key):
return _shared_store.get(key)
async def mget(self, keys):
return [_shared_store.get(key) for key in keys]