redis
This commit is contained in:
15
app/storage/redis/__init__.py
Normal file
15
app/storage/redis/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import os
|
||||
import redis.asyncio
|
||||
|
||||
|
||||
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
|
||||
REDIS_PASSWORD = os.getenv('REDIS_PASSWORD')
|
||||
if REDIS_PASSWORD:
|
||||
URL = f'redis://:{REDIS_PASSWORD}@{REDIS_HOST}:6379'
|
||||
else:
|
||||
URL = f'redis://{REDIS_HOST}:6379'
|
||||
|
||||
|
||||
|
||||
pool = redis.asyncio.ConnectionPool.from_url(URL)
|
||||
database = redis.Redis.from_pool(pool)
|
||||
8
app/storage/redis/lock.py
Normal file
8
app/storage/redis/lock.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import contextlib
|
||||
|
||||
from app.storage import redis
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def acquire(lock_name: str):
|
||||
return redis.database.lock(lock_name)
|
||||
Reference in New Issue
Block a user