This commit is contained in:
Shrinit Goyal 2025-10-03 14:11:23 +02:00 committed by GitHub
commit 80c04e26d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -31,10 +31,12 @@ class RedisKVStoreConfig(CommonConfig):
type: Literal["redis"] = KVStoreType.redis.value
host: str = "localhost"
port: int = 6379
db: int = 0
ttl: int = None
@property
def url(self) -> str:
return f"redis://{self.host}:{self.port}"
return f"redis://{self.host}:{self.port}/{self.db}"
@classmethod
def pip_packages(cls) -> list[str]:

View file

@ -26,6 +26,9 @@ class RedisKVStoreImpl(KVStore):
async def set(self, key: str, value: str, expiration: datetime | None = None) -> None:
key = self._namespaced_key(key)
if self.config.ttl:
await self.redis.set(key, value, ex=self.config.ttl)
else:
await self.redis.set(key, value)
if expiration:
await self.redis.expireat(key, expiration)