跳到主要內容

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 參考文檔: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://langchain-python.dev.org.tw/api_reference/community/storage/langchain_community.storage.upstash_redis.UpstashRedisByteStore.html


此頁面是否對您有幫助?