1
0
mirror of https://github.com/etesync/server synced 2024-11-19 07:18:08 +00:00
etesync-server/etebase_server/fastapi/redis.py
Xiretza ada5181a7e fix: move django_etebase module from toplevel to under etebase_server
This is in preparation for creating a python package, which should only
occupy the "etebase_server" name in the global module namespace.
2022-05-09 17:41:16 +02:00

28 lines
627 B
Python

import typing as t
import aioredis
from etebase_server.django import app_settings
class RedisWrapper:
redis: aioredis.Redis
def __init__(self, redis_uri: t.Optional[str]):
self.redis_uri = redis_uri
async def setup(self):
if self.redis_uri is not None:
self.redis = await aioredis.create_redis_pool(self.redis_uri)
async def close(self):
if hasattr(self, "redis"):
self.redis.close()
await self.redis.wait_closed()
@property
def is_active(self):
return self.redis_uri is not None
redisw = RedisWrapper(app_settings.REDIS_URI)