Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Config(BaseSettings):
DATABASE_POOL_PRE_PING: bool = True

REDIS_URL: RedisDsn
REDIS_HEALTH_CHECK_INTERVAL: int = 30

SITE_DOMAIN: str = "myapp.com"

Expand Down
10 changes: 6 additions & 4 deletions src/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
pool = aioredis.ConnectionPool.from_url(
str(settings.REDIS_URL),
max_connections=settings.REDIS_MAX_CONNECTIONS,
health_check_interval=settings.REDIS_HEALTH_CHECK_INTERVAL,
socket_keepalive=True,
decode_responses=True,
)
redis_client = aioredis.Redis(connection_pool=pool)
Expand Down Expand Up @@ -64,10 +66,10 @@ async def add_memes_to_queue_by_key(
key: str, memes: list[dict], expire: int = 3600
) -> None:
jsoned_memes = [orjson.dumps(meme) for meme in memes]
p = await redis_client.pipeline(transaction=True)
await p.sadd(key, *jsoned_memes)
await p.expire(key, expire)
await p.execute(raise_on_error=True)
async with redis_client.pipeline(transaction=True) as pipe:
await pipe.sadd(key, *jsoned_memes)
await pipe.expire(key, expire)
await pipe.execute(raise_on_error=True)


def get_user_info_key(user_id: int) -> str:
Expand Down
Loading