diff options
| author | 2022-01-17 19:41:55 +0100 | |
|---|---|---|
| committer | 2022-01-17 19:41:55 +0100 | |
| commit | 5a38ebf365bfa0718dcbd7ab013af5f2da4610f6 (patch) | |
| tree | 72d762c3f0e081c24239522a6281425789e2e608 /ttun_server/redis.py | |
| parent | 46af86f8ace136dd1d1d94590d3423e6b12e3f7b (diff) | |
| download | server-5a38ebf365bfa0718dcbd7ab013af5f2da4610f6.tar.gz server-5a38ebf365bfa0718dcbd7ab013af5f2da4610f6.tar.bz2 server-5a38ebf365bfa0718dcbd7ab013af5f2da4610f6.zip | |
Added scaling support via redisv1.1.0-rc1
Diffstat (limited to 'ttun_server/redis.py')
| -rw-r--r-- | ttun_server/redis.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ttun_server/redis.py b/ttun_server/redis.py new file mode 100644 index 0000000..344c107 --- /dev/null +++ b/ttun_server/redis.py | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | import os | ||
| 2 | |||
| 3 | from aioredis import ConnectionPool, Redis | ||
| 4 | |||
| 5 | |||
| 6 | class RedisConnectionPool(): | ||
| 7 | instance: 'RedisConnectionPool' = None | ||
| 8 | |||
| 9 | def __init__(self): | ||
| 10 | self.pool = ConnectionPool.from_url(os.environ.get('REDIS_URL')) | ||
| 11 | |||
| 12 | def __del__(self): | ||
| 13 | self.pool.disconnect() | ||
| 14 | |||
| 15 | @classmethod | ||
| 16 | def get_connection(cls) -> Redis: | ||
| 17 | if cls.instance is None: | ||
| 18 | cls.instance = RedisConnectionPool() | ||
| 19 | |||
| 20 | return Redis(connection_pool=cls.instance.pool) | ||
