Skip to main content

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_communityโŒโœ…PyPI - 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/v0.2/api_reference/community/storage/langchain_community.storage.upstash_redis.UpstashRedisByteStore.html


Was this page helpful?


You can also leave detailed feedback on GitHub.