autogen_ext.cache_store.redis#
- pydantic model RedisStoreConfig[source]#
基类:
BaseModelRedisStore 的配置
显示 JSON 模式
{ "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" } } }
- 字段:
- 类 RedisStore(redis_instance: Redis)[source]#
基类:
CacheStore[T],Component[RedisStoreConfig]一个使用 Redis 作为底层存储的类型化 CacheStore 实现。有关用法示例,请参见
ChatCompletionCache。此实现提供以下内容的自动序列化和反序列化: - Pydantic 模型(使用 model_dump_json/model_validate_json) - 基本类型(字符串、数字等)
- 参数:
cache_instance – redis.Redis 的实例。用户负责管理 Redis 实例的生命周期。
- component_config_schema#
- component_provider_override: ClassVar[str | None] = 'autogen_ext.cache_store.redis.RedisStore'#
覆盖组件的提供者字符串。这应该用于防止内部模块名称成为模块名称的一部分。
- get(key: str, default: T | None = None) T | None[source]#
从 Redis 缓存中检索值。
此方法处理原始值和复杂对象: - Pydantic 模型自动从 JSON 反序列化 - 原始值(字符串、数字等)按原样返回 - 如果反序列化失败,则返回原始值或默认值
- 参数:
key – 要检索的键
default – 如果键不存在,则返回的值
- 返回:
如果找到并正确反序列化,则为该值;否则为默认值
- set(key: str, value: T) None#
在 Redis 缓存中存储值。
此方法处理原始值和复杂对象: - Pydantic 模型自动序列化为 JSON - 包含 Pydantic 模型的列表序列化为 JSON - 原始值(字符串、数字等)按原样存储
- 参数:
key – 存储值的键
value – 要存储的值
- _to_config() RedisStoreConfig[source]#
转储创建与此实例配置匹配的组件新实例所需的配置。
- 返回:
T – 组件的配置。
- classmethod _from_config(config: RedisStoreConfig) Self[source]#
从配置对象创建组件的新实例。
- 参数:
config (T) – 配置对象。
- 返回:
Self – 组件的新实例。