Skip to main content
Open In Colab在 GitHub 上打开

UpstashRedisByteStore 字节存储

这将帮助您开始使用 Upstash redis 键值存储。有关所有UpstashRedisByteStore功能和配置可参考 API 参考

概述

UpstashRedisStoreByteStore将所有内容存储在 Upstash 托管的 Redis 实例中。

使用基础RedisStore相反,请参阅本指南

集成详细信息

本地化JS 支持软件包下载最新包装
UpstashRedisByteStorelangchain_communityPyPI - DownloadsPyPI - Version

设置

您首先需要注册一个 Upstash 帐户。接下来,您需要创建一个要连接的 Redis 数据库。

凭据

创建数据库后,获取数据库 URL(不要忘记https://!)和 token:

from getpass import getpass

URL = getpass("Enter your Upstash URL")
TOKEN = getpass("Enter your Upstash REST token")

安装

LangChain Upstash 集成位于langchain_community包。您还需要安装upstash-redispackage 作为对等依赖项:

%pip install -qU langchain_community upstash-redis

实例

现在我们可以实例化我们的字节存储:

from langchain_community.storage import UpstashRedisByteStore
from upstash_redis import Redis

redis_client = Redis(url=URL, token=TOKEN)
kv_store = UpstashRedisByteStore(client=redis_client, ttl=None, namespace="test-ns")

用法

您可以使用mset方法:

kv_store.mset(
[
["key1", b"value1"],
["key2", b"value2"],
]
)

kv_store.mget(
[
"key1",
"key2",
]
)
[b'value1', b'value2']

您可以使用mdelete方法:

kv_store.mdelete(
[
"key1",
"key2",
]
)

kv_store.mget(
[
"key1",
"key2",
]
)
[None, None]

API 参考

有关所有UpstashRedisByteStore功能和配置,请前往 API 参考:https://python.langchain.com/api_reference/community/storage/langchain_community.storage.upstash_redis.UpstashRedisByteStore.html