redis cache

This commit is contained in:
Jonas Braus
2024-12-12 13:05:21 +01:00
parent ac420df1c7
commit 948210d73c
3 changed files with 27 additions and 2 deletions
+17
View File
@@ -0,0 +1,17 @@
import redis
def cache_prompt_to_redis(prompt, response):
r = redis.Redis(host="localhost", port=6379, decode_responses=True)
r.set(prompt, response)
r.close()
def load_response_from_redis(prompt):
r = redis.Redis(host="localhost", port=6379, decode_responses=True)
response = r.get(prompt)
r.close()
return response
def clear_redis():
r = redis.Redis(host="localhost", port=6379, decode_responses=True)
r.flushall()
r.close()