From 5399b54b549c779daabac8870cfdb79cfbdcaca1 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Tue, 14 Oct 2025 13:54:23 +0200 Subject: [PATCH] feat: adds authentication to redisadapter --- cognee/infrastructure/databases/cache/config.py | 6 +++++- cognee/infrastructure/databases/cache/get_cache_engine.py | 8 ++++++++ .../infrastructure/databases/cache/redis/RedisAdapter.py | 5 +++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cognee/infrastructure/databases/cache/config.py b/cognee/infrastructure/databases/cache/config.py index b399e0259..9ca3c5e64 100644 --- a/cognee/infrastructure/databases/cache/config.py +++ b/cognee/infrastructure/databases/cache/config.py @@ -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, } diff --git a/cognee/infrastructure/databases/cache/get_cache_engine.py b/cognee/infrastructure/databases/cache/get_cache_engine.py index 92186f877..1d22b3e30 100644 --- a/cognee/infrastructure/databases/cache/get_cache_engine.py +++ b/cognee/infrastructure/databases/cache/get_cache_engine.py @@ -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, diff --git a/cognee/infrastructure/databases/cache/redis/RedisAdapter.py b/cognee/infrastructure/databases/cache/redis/RedisAdapter.py index b0d0e6886..7b4e9802d 100644 --- a/cognee/infrastructure/databases/cache/redis/RedisAdapter.py +++ b/cognee/infrastructure/databases/cache/redis/RedisAdapter.py @@ -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