Skip to main content
Open In ColabOpen on GitHub

UpstashRedisByteStore

这将帮助你开始使用 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")
API Reference:UpstashRedisByteStore

用法

你可以使用 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