mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Some checks failed
Docs / docs (push) Has been cancelled
Test / ruff-format (push) Has been cancelled
Test / ruff-lint (push) Has been cancelled
Test / build (3.10) (push) Has been cancelled
Test / build (3.11) (push) Has been cancelled
Test / build (3.12) (push) Has been cancelled
Test / build (3.13) (push) Has been cancelled
Test / build (3.14) (push) Has been cancelled
Test / build (3.8) (push) Has been cancelled
Test / build (3.9) (push) Has been cancelled
* Added async logic * Added tests and fixed async deadlock on aset * Used abstract base class for backend to simplify code coverage * Reordered try except block * Added explicit thread safety * Fixed linting error * Worked on redis init block * Fixed async test setup * Added tests for redis instantiation * Fixed linting errors
28 lines
733 B
Python
28 lines
733 B
Python
# 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:
|
|
def set(self, key, value):
|
|
_shared_store[key] = value
|
|
|
|
def get(self, key, default=None):
|
|
return _shared_store.get(key, default)
|
|
|
|
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]
|