autogen_ext.cache_store.redis#

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

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

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

Parameters:

cache_instanceredis.Redis 的一个实例。 用户负责管理 Redis 实例的生命周期。

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

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

Parameters:

config (T) – 配置对象。

Returns:

Self – 组件的新实例。

_to_config() RedisStoreConfig[源代码]#

导出配置,该配置将用于创建一个与此实例配置相匹配的组件新实例。

Returns:

T – 组件的配置。

component_config_schema#

别名RedisStoreConfig

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

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

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

从商店中检索一个项目。

Parameters:
  • key – 用于在存储中标识项目的键。

  • default (可选) – 如果找不到键,则返回的默认值。 默认为 None。

Returns:

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

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

在商店中设置一个项目。

Parameters:
  • key – 存储项的键。

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

pydantic model RedisStoreConfig[源代码]#

基础:BaseModel

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:
field db: int = 0#
field host: str = 'localhost'#
field password: str | = None#
field port: int = 6379#
field socket_timeout: float | = None#
field ssl: bool = False#
field username: str | = None#