Skip to main content

RedisStore

这将帮助您开始使用 Redis 键值存储。有关所有 RedisStore 功能和配置的详细文档,请访问 API 参考

概述

RedisStoreByteStore 的一种实现,它将所有内容存储在您的 Redis 实例中。

集成细节

包名本地JS 支持包下载包最新
RedisStorelangchain_communityPyPI - 下载量PyPI - 版本

设置

要创建一个 Redis 字节存储,您需要设置一个 Redis 实例。您可以在本地或通过提供商进行此操作 - 请参阅我们的 Redis 指南 以获取选项概述。

安装

LangChain RedisStore 集成位于 langchain_community 包中:

%pip install -qU langchain_community redis

实例化

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

<!--IMPORTS:[{"imported": "RedisStore", "source": "langchain_community.storage", "docs": "https://python.langchain.com/api_reference/community/storage/langchain_community.storage.redis.RedisStore.html", "title": "RedisStore"}]-->
from langchain_community.storage import RedisStore

kv_store = RedisStore(redis_url="redis://localhost:6379")

用法

您可以使用 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 参考

有关所有 RedisStore 功能和配置的详细文档,请访问 API 参考: https://python.langchain.com/api_reference/community/storage/langchain_community.storage.redis.RedisStore.html

相关


Was this page helpful?


You can also leave detailed feedback on GitHub.

扫我,入群扫我,找书