2024-04-19 08:50:50 +00:00
|
|
|
import json
|
2024-01-25 09:25:52 +00:00
|
|
|
import logging
|
|
|
|
|
2024-04-18 10:47:01 +00:00
|
|
|
from services.logger import root_logger as logger
|
2024-04-19 07:47:16 +00:00
|
|
|
from services.rediscache import redis
|
2023-10-04 20:42:39 +00:00
|
|
|
|
2024-01-23 20:13:49 +00:00
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
|
2023-10-04 20:42:39 +00:00
|
|
|
|
2024-04-19 08:22:57 +00:00
|
|
|
async def get_all_authors():
|
2024-04-19 07:47:16 +00:00
|
|
|
authors = []
|
|
|
|
redis_key = "user:*"
|
2023-11-06 16:25:28 +00:00
|
|
|
|
2024-04-19 08:22:57 +00:00
|
|
|
result = await redis.execute("GET", redis_key)
|
2024-04-19 07:47:16 +00:00
|
|
|
if isinstance(result, str):
|
|
|
|
authors = json.loads(result)
|
2023-12-19 08:25:06 +00:00
|
|
|
|
2024-04-19 07:47:16 +00:00
|
|
|
return authors
|
2023-12-19 17:19:16 +00:00
|
|
|
|
2023-11-22 12:09:24 +00:00
|
|
|
|
2024-04-19 08:22:57 +00:00
|
|
|
async def get_author_by_user(user: str):
|
2024-04-19 07:47:16 +00:00
|
|
|
author = None
|
|
|
|
redis_key = f"user:{user}"
|
|
|
|
|
2024-04-19 08:22:57 +00:00
|
|
|
result = await redis.execute("GET", redis_key)
|
2024-04-19 07:47:16 +00:00
|
|
|
if isinstance(result, str):
|
|
|
|
author = json.loads(result)
|
2023-12-19 08:25:06 +00:00
|
|
|
|
2024-04-19 07:47:16 +00:00
|
|
|
return author
|
2023-10-04 20:42:39 +00:00
|
|
|
|
2023-10-11 19:12:55 +00:00
|
|
|
|
2024-04-19 11:28:21 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2024-04-19 08:22:57 +00:00
|
|
|
async def get_author_followed(author_id: int):
|
2024-04-19 07:47:16 +00:00
|
|
|
authors = []
|
|
|
|
redis_key = f"author:{author_id}:follows-authors"
|
2023-10-11 19:12:55 +00:00
|
|
|
|
2024-04-19 08:22:57 +00:00
|
|
|
result = await redis.execute("GET", redis_key)
|
2024-04-19 07:47:16 +00:00
|
|
|
if isinstance(result, str):
|
|
|
|
authors = json.loads(result)
|
2023-11-22 12:09:24 +00:00
|
|
|
|
2024-04-19 07:47:16 +00:00
|
|
|
return authors
|