UpstashRedisByteStore
这将帮助您开始使用 Upstash redis 键值存储。有关所有UpstashRedisByteStore功能和配置的详细文档,请访问API 参考。
概览
UpstashRedisStore 是一种 ByteStore 的实现,它将所有内容存储在您托管于 Upstash 的 Redis 实例中。
要使用基础 RedisStore,请参阅本指南。
集成细节
| Class | 包 | 本地 | JS支持 | Package downloads | Package 最新版本 |
|---|---|---|---|---|---|
| UpstashRedisByteStore | langchain_community | ❌ | ✅ |
设置
您首先需要注册一个Upstash账户。接下来,您需要创建一个Redis数据库进行连接。
Credentials
创建数据库后,请获取您的数据库 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
Instantiation
现在我们可以实例化我们的字节存储了:
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 参考: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
相关
- 键值存储 概念指南