import os | |
from fastapi import APIRouter | |
from dotenv import load_dotenv | |
from clients.redis_client import redis_client as r | |
load_dotenv() | |
router = APIRouter() | |
def get_cached_articles_by_category(category: str, limit: int): | |
try: | |
article_ids = list(r.smembers(f"category:{category}"))[:limit] | |
articles = [] | |
for article_id in article_ids: | |
article_data = r.hgetall(f"article:{article_id}") | |
if article_data: | |
articles.append(article_data) | |
return articles | |
except Exception as e: | |
print(f"[ERROR] Failed to fetch cached articles: {e}") | |
return {"error": "Failed to fetch articles from cache."} | |
async def root(): | |
return {"message": "LucidFeed backend is up and running!"} |