feat: adds authentication to redisadapter
This commit is contained in:
parent
3faeee7631
commit
5399b54b54
3 changed files with 16 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from functools import lru_cache
|
||||
|
||||
from typing import Optional
|
||||
|
||||
class CacheConfig(BaseSettings):
|
||||
"""
|
||||
|
|
@ -18,6 +18,8 @@ class CacheConfig(BaseSettings):
|
|||
shared_kuzu_lock: bool = False
|
||||
cache_host: str = "localhost"
|
||||
cache_port: int = 6379
|
||||
cache_username: Optional[str] = None
|
||||
cache_password: Optional[str] = None
|
||||
agentic_lock_expire: int = 240
|
||||
agentic_lock_timeout: int = 300
|
||||
|
||||
|
|
@ -29,6 +31,8 @@ class CacheConfig(BaseSettings):
|
|||
"shared_kuzu_lock": self.shared_kuzu_lock,
|
||||
"cache_host": self.cache_host,
|
||||
"cache_port": self.cache_port,
|
||||
"cache_username": self.cache_username,
|
||||
"cache_password": self.cache_password,
|
||||
"agentic_lock_expire": self.agentic_lock_expire,
|
||||
"agentic_lock_timeout": self.agentic_lock_timeout,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ config = get_cache_config()
|
|||
def create_cache_engine(
|
||||
cache_host: str,
|
||||
cache_port: int,
|
||||
cache_username: str,
|
||||
cache_password: str,
|
||||
lock_key: str,
|
||||
agentic_lock_expire: int = 240,
|
||||
agentic_lock_timeout: int = 300,
|
||||
|
|
@ -23,6 +25,8 @@ def create_cache_engine(
|
|||
-----------
|
||||
- cache_host: Hostname or IP of the cache server.
|
||||
- cache_port: Port number to connect to.
|
||||
- cache_username: Username to authenticate with.
|
||||
- cache_password: Password to authenticate with.
|
||||
- lock_key: Identifier used for the locking resource.
|
||||
- agentic_lock_expire: Duration to hold the lock after acquisition.
|
||||
- agentic_lock_timeout: Max time to wait for the lock before failing.
|
||||
|
|
@ -37,6 +41,8 @@ def create_cache_engine(
|
|||
return RedisAdapter(
|
||||
host=cache_host,
|
||||
port=cache_port,
|
||||
username=cache_username,
|
||||
password=cache_password,
|
||||
lock_name=lock_key,
|
||||
timeout=agentic_lock_expire,
|
||||
blocking_timeout=agentic_lock_timeout,
|
||||
|
|
@ -53,6 +59,8 @@ def get_cache_engine(lock_key: str) -> CacheDBInterface:
|
|||
return create_cache_engine(
|
||||
cache_host=config.cache_host,
|
||||
cache_port=config.cache_port,
|
||||
cache_username=config.cache_username,
|
||||
cache_password=config.cache_password,
|
||||
lock_key=lock_key,
|
||||
agentic_lock_expire=config.agentic_lock_expire,
|
||||
agentic_lock_timeout=config.agentic_lock_timeout,
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@ from cognee.infrastructure.databases.cache.cache_db_interface import CacheDBInte
|
|||
|
||||
|
||||
class RedisAdapter(CacheDBInterface):
|
||||
def __init__(self, host, port, lock_name, timeout=240, blocking_timeout=300):
|
||||
def __init__(self, host, port, lock_name, username=None, password=None, timeout=240, blocking_timeout=300):
|
||||
super().__init__(host, port, lock_name)
|
||||
self.redis = redis.Redis(host=host, port=port)
|
||||
|
||||
self.redis = redis.Redis(host=host, port=port, username=username, password=password)
|
||||
self.timeout = timeout
|
||||
self.blocking_timeout = blocking_timeout
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue