跳到主要内容
这将帮助您开始使用 Upstash Redis 键值存储。有关所有 UpstashRedisByteStore 功能和配置的详细文档,请查阅API 参考

概览

UpstashRedisStoreByteStore 的一个实现,它将所有内容存储在您的 Upstash 托管的 Redis 实例中。 要改用基础的 RedisStore,请参阅本指南

集成详情

类别本地JS 支持下载量版本
UpstashRedisByteStorelangchain-communityPyPI - DownloadsPyPI - Version

设置

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

凭据

创建数据库后,获取您的数据库 URL(不要忘记 https://!)和令牌
from getpass import getpass

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

安装

LangChain Upstash 集成位于 langchain-community 包中。您还需要安装 upstash-redis 包作为对等依赖项
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 参考:python.langchain.com/api_reference/community/storage/langchain_community.storage.upstash_redis.UpstashRedisByteStore.html
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.