autogen_ext.cache_store.redis#
- pydantic model RedisStoreConfig[source]#
Bases:
BaseModel
Configuration for RedisStore
Show JSON schema
{ "title": "RedisStoreConfig", "description": "Configuration for RedisStore", "type": "object", "properties": { "host": { "default": "localhost", "title": "Host", "type": "string" }, "port": { "default": 6379, "title": "Port", "type": "integer" }, "db": { "default": 0, "title": "Db", "type": "integer" }, "username": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Username" }, "password": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Password" }, "ssl": { "default": false, "title": "Ssl", "type": "boolean" }, "socket_timeout": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": null, "title": "Socket Timeout" } } }
- Fields:
- class RedisStore(redis_instance: Redis)[source]#
Bases:
CacheStore
[T
],Component
[RedisStoreConfig
]A typed CacheStore implementation that uses redis as the underlying storage. See
ChatCompletionCache
for an example of usage.This implementation provides automatic serialization and deserialization for: - Pydantic models (uses model_dump_json/model_validate_json) - Primitive types (strings, numbers, etc.)
- Parameters:
cache_instance – An instance of redis.Redis. The user is responsible for managing the Redis instance’s lifetime.
- component_config_schema#
alias of
RedisStoreConfig
- component_provider_override: ClassVar[str | None] = 'autogen_ext.cache_store.redis.RedisStore'#
Override the provider string for the component. This should be used to prevent internal module names being a part of the module name.
- get(key: str, default: T | None = None) T | None [source]#
Retrieve a value from the Redis cache.
This method handles both primitive values and complex objects: - Pydantic models are automatically deserialized from JSON - Primitive values (strings, numbers, etc.) are returned as-is - If deserialization fails, returns the raw value or default
- Parameters:
key – The key to retrieve
default – Value to return if key doesn’t exist
- Returns:
The value if found and properly deserialized, otherwise the default
- set(key: str, value: T) None [source]#
Store a value in the Redis cache.
This method handles both primitive values and complex objects: - Pydantic models are automatically serialized to JSON - Lists containing Pydantic models are serialized to JSON - Primitive values (strings, numbers, etc.) are stored as-is
- Parameters:
key – The key to store the value under
value – The value to store
- _to_config() RedisStoreConfig [source]#
Dump the configuration that would be requite to create a new instance of a component matching the configuration of this instance.
- Returns:
T – The configuration of the component.
- classmethod _from_config(config: RedisStoreConfig) Self [source]#
Create a new instance of the component from a configuration object.
- Parameters:
config (T) – The configuration object.
- Returns:
Self – The new instance of the component.