autogen_ext.cache_store.redis#

class RedisStore(redis_instance: Redis)[源代码]#

基类:CacheStore[T], Component[RedisStoreConfig]

一个使用 Redis 作为底层存储的类型化 CacheStore 实现。 使用示例请参见 ChatCompletionCache

参数:

cache_instance -- redis.Redis 的实例。 用户需自行管理 Redis 实例的生命周期。

classmethod _from_config(config: RedisStoreConfig) Self[源代码]#

从配置对象创建组件的新实例。

参数:

config (T) -- 配置对象。

Returns:

Self -- 组件的新实例。

_to_config() RedisStoreConfig[源代码]#

导出当前组件实例的配置,该配置可用于创建具有相同配置的新组件实例。

Returns:

T -- 组件的配置。

component_config_schema#

RedisStoreConfig 的别名

component_provider_override: ClassVar[str | None] = 'autogen_ext.cache_store.redis.RedisStore'#

覆盖组件的provider字符串。这应该用于防止内部模块名称成为模块名称的一部分。

get(key: str, default: T | None = None) T | None[源代码]#

从存储中检索一个项目。

参数:
  • key -- 标识存储中项目的键。

  • default (optional) -- 如果未找到键时返回的默认值。 默认为 None。

Returns:

如果找到则返回与键关联的值,否则返回默认值。

set(key: str, value: T) None[源代码]#

在存储中设置一个项目。

参数:
  • key -- 用于存储项目的键。

  • value -- 要存储在存储中的值。

pydantic model RedisStoreConfig[源代码]#

基类:BaseModel

RedisStore 的配置

Show JSON schema
{
   "title": "RedisStoreConfig",
   "description": "RedisStore \u7684\u914d\u7f6e",
   "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:
field db: int = 0#
field host: str = 'localhost'#
field password: str | None = None#
field port: int = 6379#
field socket_timeout: float | None = None#
field ssl: bool = False#
field username: str | None = None#