custom-encoder-fix-2
This commit is contained in:
@@ -21,20 +21,20 @@ DEFAULT_FOLLOWS = {
|
||||
|
||||
|
||||
async def set_author_cache(author: dict, ttl=25 * 60 * 60):
|
||||
payload = json.dumps(author)
|
||||
await redis.execute('SET', f'user:{author.get("user")}:author', ttl, payload, cls=CustomJSONEncoder)
|
||||
await redis.execute('SET', f'id:{author.get("id")}:author', ttl, payload, cls=CustomJSONEncoder)
|
||||
payload = json.dumps(author, cls=CustomJSONEncoder)
|
||||
await redis.execute('SET', f'user:{author.get("user")}:author', ttl, payload)
|
||||
await redis.execute('SET', f'id:{author.get("id")}:author', ttl, payload)
|
||||
|
||||
|
||||
async def update_author_followers_cache(author_id: int, followers, ttl=25 * 60 * 60):
|
||||
payload = json.dumps(followers)
|
||||
await redis.execute('SET', f'author:{author_id}:followers', ttl, payload, cls=CustomJSONEncoder)
|
||||
payload = json.dumps(followers, cls=CustomJSONEncoder)
|
||||
await redis.execute('SET', f'author:{author_id}:followers', ttl, payload)
|
||||
|
||||
|
||||
async def set_follows_topics_cache(follows, author_id: int, ttl=25 * 60 * 60):
|
||||
try:
|
||||
payload = json.dumps(follows)
|
||||
await redis.execute('SET', f'author:{author_id}:follows-topics', ttl, payload, cls=CustomJSONEncoder)
|
||||
payload = json.dumps(follows, cls=CustomJSONEncoder)
|
||||
await redis.execute('SET', f'author:{author_id}:follows-topics', ttl, payload)
|
||||
except Exception as exc:
|
||||
logger.error(exc)
|
||||
import traceback
|
||||
@@ -45,9 +45,9 @@ async def set_follows_topics_cache(follows, author_id: int, ttl=25 * 60 * 60):
|
||||
|
||||
async def set_follows_authors_cache(follows, author_id: int, ttl=25 * 60 * 60):
|
||||
try:
|
||||
payload = json.dumps(follows)
|
||||
payload = json.dumps(follows, cls=CustomJSONEncoder)
|
||||
await redis.execute(
|
||||
'SET', f'author:{author_id}:follows-authors', ttl, payload, cls=CustomJSONEncoder
|
||||
'SET', f'author:{author_id}:follows-authors', ttl, payload
|
||||
)
|
||||
except Exception:
|
||||
import traceback
|
||||
|
@@ -145,7 +145,7 @@ class SearchService:
|
||||
|
||||
# Use Redis as cache with TTL
|
||||
redis_key = f'search:{text}'
|
||||
await redis.execute('SETEX', redis_key, REDIS_TTL, json.dumps(results), cls=CustomJSONEncoder)
|
||||
await redis.execute('SETEX', redis_key, REDIS_TTL, json.dumps(results, cls=CustomJSONEncoder))
|
||||
return []
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user