This repository has been archived on 2024-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
2023-08-21 21:28:52 -06:00
|
|
|
from flask_caching import Cache
|
2023-08-23 01:14:19 -06:00
|
|
|
from redis import Redis
|
2023-08-21 21:28:52 -06:00
|
|
|
|
2023-08-22 00:01:32 -06:00
|
|
|
cache = Cache(config={'CACHE_TYPE': 'RedisCache', 'CACHE_REDIS_URL': 'redis://localhost:6379/0', 'CACHE_KEY_PREFIX': 'local-llm'})
|
2023-08-23 22:01:06 -06:00
|
|
|
|
|
|
|
|
|
|
|
# redis = Redis()
|
|
|
|
|
|
|
|
class RedisWrapper:
|
|
|
|
"""
|
|
|
|
A wrapper class to set prefixes to keys.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, prefix, **kwargs):
|
|
|
|
self.redis = Redis(**kwargs)
|
|
|
|
self.prefix = prefix
|
|
|
|
|
|
|
|
def set(self, key, value):
|
|
|
|
return self.redis.set(f"{self.prefix}:{key}", value)
|
|
|
|
|
|
|
|
def get(self, key):
|
|
|
|
return self.redis.get(f"{self.prefix}:{key}")
|
|
|
|
|
|
|
|
def incr(self, key, amount=1):
|
|
|
|
return self.redis.incr(f"{self.prefix}:{key}", amount)
|
|
|
|
|
|
|
|
def decr(self, key, amount=1):
|
|
|
|
return self.redis.decr(f"{self.prefix}:{key}", amount)
|
|
|
|
|
|
|
|
def flush(self):
|
|
|
|
flushed = []
|
|
|
|
for key in self.redis.scan_iter(f'{self.prefix}:*'):
|
|
|
|
flushed.append(key)
|
|
|
|
self.redis.delete(key)
|
|
|
|
return flushed
|
|
|
|
|
|
|
|
|
|
|
|
redis = RedisWrapper('local_llm')
|