本指南介绍如何使用 Redis 键值存储。关于 RedisStore 的全部功能与配置,请参阅 API 参考

Overview

RedisStoreByteStore 的一种实现,会将所有数据存放在 Redis 实例中。

Integration details

ClassPackageLocalJS supportDownloadsVersion
RedisStorelangchain-communityPyPI - DownloadsPyPI - Version

设置

首先需要部署 Redis,可本地安装或使用云服务,详见Redis 指南

安装

该集成位于 langchain-community 包:
pip install -qU langchain-community redis

实例化

创建 ByteStore:
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 文档
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.