# Upstash Redis

Upstash offers developers serverless databases and messaging platforms to build powerful applications without having to worry about the operational complexity of running databases at scale.

This page covers how to use [Upstash Redis](https://upstash.com/redis) with LangChain.

## Installation and Setup
- Upstash Redis Python SDK can be installed with `pip install upstash-redis`
- A globally distributed, low-latency and highly available database can be created at the [Upstash Console](https://console.upstash.com)


## Integrations
All of Upstash-LangChain integrations are based on `upstash-redis` Python SDK being utilized as wrappers for LangChain.
This SDK utilizes Upstash Redis DB by giving UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN parameters from the console.
One significant advantage of this is that, this SDK uses a REST API. This means, you can run this in serverless platforms, edge or any platform that does not support TCP connections.


### Cache

[Upstash Redis](https://upstash.com/redis) can be used as a cache for LLM prompts and responses.

To import this cache:
```python
from langchain.cache import UpstashRedisCache
```

To use with your LLMs:
```python
import langchain
from upstash_redis import Redis

URL = "<UPSTASH_REDIS_REST_URL>"
TOKEN = "<UPSTASH_REDIS_REST_TOKEN>"

langchain.llm_cache = UpstashRedisCache(redis_=Redis(url=URL, token=TOKEN))
```

### Memory

See a [usage example](/docs/integrations/memory/upstash_redis_chat_message_history).

```python
from langchain_community.chat_message_histories import (
    UpstashRedisChatMessageHistory,
)
```
