You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
603 B
Python
27 lines
603 B
Python
4 years ago
|
import typing as t
|
||
2 years ago
|
from redis import asyncio as aioredis
|
||
4 years ago
|
|
||
3 years ago
|
from etebase_server.django import app_settings
|
||
4 years ago
|
|
||
|
|
||
|
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:
|
||
2 years ago
|
self.redis = await aioredis.from_url(self.redis_uri)
|
||
4 years ago
|
|
||
|
async def close(self):
|
||
3 years ago
|
if hasattr(self, "redis"):
|
||
2 years ago
|
await self.redis.close()
|
||
4 years ago
|
|
||
|
@property
|
||
|
def is_active(self):
|
||
|
return self.redis_uri is not None
|
||
|
|
||
|
|
||
|
redisw = RedisWrapper(app_settings.REDIS_URI)
|