Skip to main content
本文将帮助你快速上手 Redis 键值存储。有关 RedisStore 所有特性和配置的详细文档,请参阅 API 参考

概述

RedisStoreByteStore 的一个实现,将所有内容存储在你的 Redis 实例中。

集成详情

本地支持JS 支持下载量版本
RedisStorelangchain-communityPyPI - DownloadsPyPI - Version

配置

要创建 Redis 字节存储,需要先搭建一个 Redis 实例。可以在本地搭建或使用云服务提供商——详见我们的 Redis 指南

安装

LangChain RedisStore 集成位于 langchain-community 包中:
pip install -qU langchain-community redis

实例化

现在可以实例化字节存储:
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 参考:python.langchain.com/api_reference/community/storage/langchain_community.storage.redis.RedisStore.html