inbox/services/core.py
2024-04-19 14:28:21 +03:00

52 lines
1.1 KiB
Python

import json
import logging
from services.logger import root_logger as logger
from services.rediscache import redis
logger.setLevel(logging.DEBUG)
async def get_all_authors():
authors = []
redis_key = "user:*"
result = await redis.execute("GET", redis_key)
if isinstance(result, str):
authors = json.loads(result)
return authors
async def get_author_by_user(user: str):
author = None
redis_key = f"user:{user}"
result = await redis.execute("GET", redis_key)
if isinstance(result, str):
author = json.loads(result)
return author
async def get_author_by_id(author_id: int):
author = None
redis_key = f"author:{author_id}"
result = await redis.execute("GET", redis_key)
if isinstance(result, str):
author = json.loads(result)
return author
async def get_author_followed(author_id: int):
authors = []
redis_key = f"author:{author_id}:follows-authors"
result = await redis.execute("GET", redis_key)
if isinstance(result, str):
authors = json.loads(result)
return authors