Skip to main content
Open In ColabOpen on GitHub

UpstashRedisByteStore

This will help you get started with Upstash redis key-value stores. For detailed documentation of all UpstashRedisByteStore features and configurations head to the API reference.

Overview

The UpstashRedisStore is an implementation of ByteStore that stores everything in your Upstash-hosted Redis instance.

To use the base RedisStore instead, see this guide.

Integration details

ClassPackageLocalJS supportPackage downloadsPackage latest
UpstashRedisByteStorelangchain_communityPyPI - DownloadsPyPI - Version

Setup

You'll first need to sign up for an Upstash account. Next, you'll need to create a Redis database to connect to.

Credentials

Once you've created your database, get your database URL (don't forget the https://!) and token:

from getpass import getpass

URL = getpass("Enter your Upstash URL")
TOKEN = getpass("Enter your Upstash REST token")

Installation

The LangChain Upstash integration lives in the langchain_community package. You'll also need to install the upstash-redis package as a peer dependency:

%pip install -qU langchain_community upstash-redis

Instantiation

Now we can instantiate our byte store:

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 Reference:UpstashRedisByteStore

Usage

You can set data under keys like this using the mset method:

kv_store.mset(
[
["key1", b"value1"],
["key2", b"value2"],
]
)

kv_store.mget(
[
"key1",
"key2",
]
)
[b'value1', b'value2']

And you can delete data using the mdelete method:

kv_store.mdelete(
[
"key1",
"key2",
]
)

kv_store.mget(
[
"key1",
"key2",
]
)
[None, None]

API reference

For detailed documentation of all UpstashRedisByteStore features and configurations, head to the API reference: https://python.langchain.com/api_reference/community/storage/langchain_community.storage.upstash_redis.UpstashRedisByteStore.html


Was this page helpful?