Skip to content

Commit

Permalink
Merge pull request #640 from openchatai/fix/redis
Browse files Browse the repository at this point in the history
adding core redis library
  • Loading branch information
codebanesr authored Feb 19, 2024
2 parents 1ee8be1 + 298ece4 commit 9d639dc
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions llm-server/models/repository/powerup_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from langchain.schema import HumanMessage, SystemMessage
from langchain.pydantic_v1 import BaseModel, Field
from langchain.output_parsers import PydanticOutputParser
import aioredis
from utils.llm_consts import redis_client

SessionLocal = sessionmaker(bind=engine)

Expand Down Expand Up @@ -123,16 +123,9 @@ async def get_regex_for_dynamic_params(url: str) -> str:


async def cache_result(key: str, value: str, ttl: int):
redis = await aioredis.create_redis_pool("redis://localhost")
await redis.setex(key, ttl, value)
redis.close()
await redis.wait_closed()
await redis_client.setex(key, ttl, value)


async def get_cached_result(key: str) -> str:
redis = await aioredis.create_redis_pool("redis://localhost")
cached_result = await redis.get(key)
redis.close()
await redis.wait_closed()

return cached_result.decode() if cached_result else None
cached_result = await redis_client.get(key)
return cached_result

0 comments on commit 9d639dc

Please sign in to comment.