autogen.cache.redis_cache.RedisCache
RedisCache
Implementation of AbstractCache using the Redis database.
This class provides a concrete implementation of the AbstractCache
interface using the Redis database for caching data.
Attributes:
seed (Union[str, int]): A seed or namespace used as a prefix for cache keys.
cache (redis.Redis): The Redis client used for caching.
Methods:
init(self, seed, redis_url): Initializes the RedisCache with the given seed and Redis URL.
_prefixed_key(self, key): Internal method to get a namespaced cache key.
get(self, key, default=None): Retrieves an item from the cache.
set(self, key, value): Sets an item in the cache.
close(self): Closes the Redis client.
enter(self): Context management entry.
exit(self, exc_type, exc_value, traceback): Context management exit.
Initialize the RedisCache instance.
Name | Description |
---|---|
seed | Type: str | int |
redis_url | Type: str |
Instance Methods
close
Close the Redis client.
Perform any necessary cleanup, such as closing network connections.
get
Retrieve an item from the Redis cache.
Name | Description |
---|---|
key | The key identifying the item in the cache. Type: str |
default | The default value to return if the key is not found. Defaults to None. Type: Any | None Default: None |
Type | Description |
---|---|
Any | None | The deserialized value associated with the key if found, else the default value. |
set
Set an item in the Redis cache.
Name | Description |
---|---|
key | The key under which the item is to be stored. Type: str |
value | The value to be stored in the cache. Type: Any |