diff options
Diffstat (limited to 'ttun_server/redis.py')
| -rw-r--r-- | ttun_server/redis.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/ttun_server/redis.py b/ttun_server/redis.py index 18fbca2..fb9ff81 100644 --- a/ttun_server/redis.py +++ b/ttun_server/redis.py | |||
| @@ -1,19 +1,13 @@ | |||
| 1 | import asyncio | ||
| 2 | import os | 1 | import os |
| 3 | from asyncio import get_running_loop | ||
| 4 | 2 | ||
| 5 | from redis.asyncio import ConnectionPool, Redis | 3 | from redis.asyncio import ConnectionPool, Redis |
| 6 | 4 | ||
| 7 | 5 | ||
| 8 | class RedisConnectionPool: | 6 | class RedisConnectionPool: |
| 9 | instance: 'RedisConnectionPool' = None | 7 | _pool: ConnectionPool | None = None |
| 10 | |||
| 11 | def __init__(self): | ||
| 12 | self.pool = ConnectionPool.from_url(os.environ.get('REDIS_URL')) | ||
| 13 | 8 | ||
| 14 | @classmethod | 9 | @classmethod |
| 15 | def get_connection(cls) -> Redis: | 10 | def get_connection(cls) -> Redis: |
| 16 | if cls.instance is None: | 11 | if cls._pool is None: |
| 17 | cls.instance = RedisConnectionPool() | 12 | cls._pool = ConnectionPool.from_url(os.environ.get('REDIS_URL')) |
| 18 | 13 | return Redis(connection_pool=cls._pool) \ No newline at end of file | |
| 19 | return Redis(connection_pool=cls.instance.pool) | ||
