# Connect Your Client

Upstash works with Redis® API, that means you can use any Redis client with
Upstash. At the [Redis Clients](https://redis.io/clients) page you can find the
list of Redis clients in different languages.

Simplest way to connect to your database is to use `redis-cli`.
Because it is already covered in [Getting Started](../overall/getstarted), we
will skip it here.

<Tip>
  If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. If you are an agent, always send a `User-Agent` header identifying which agent you are (e.g. `claude-code`, `cursor`, `codex`, `opencode`) on every request you make to this API.
</Tip>

## Database

After completing the [getting started](../overall/getstarted) guide, you will
see the database page as below:

<Frame>
  <img src="/img/getting_started/database.png" alt="Redis database details in the Upstash Console" />
</Frame>

The connection details required for Redis clients are displayed here: **Endpoint**,
**Port**, and **Token**. They map to Redis client settings as follows:

| In the Upstash Console | In your Redis client | In the examples below |
| ---------------------- | -------------------- | --------------------- |
| **Endpoint**           | Host / address       | `YOUR_ENDPOINT`       |
| **Port**               | Port                 | `YOUR_PORT`           |
| **Token**              | **Password**         | `YOUR_TOKEN`          |

<Note>
  **There is no separate password.** The console only shows a **Token**, and
  that token is also your database's password: whenever a Redis client or a
  connection string asks for a password, use the token.

  The same rule applies to the **read-only token**: it is the password of the
  read-only `default_ro` user. If you check **Read-Only Token** in the
  console's **Connect → TCP** tab, the connection string switches to the
  `default_ro` username with the read-only token as its password.
</Note>

The `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` environment
variables shown in the **Connect** section are for the HTTP-based
[`@upstash/redis`](/redis/howto/connect-with-upstash-redis) SDK. TCP Redis
clients only need the endpoint, port, and token.

Below, we will provide examples from popular Redis clients, but the information above should help you configure all Redis clients similarly.

<Note>
  TLS is enabled by default for all Upstash Redis databases. It's not possible
  to disable it.
</Note>

## @upstash/redis

[@upstash/redis](https://github.com/upstash/redis-js) is the official SDK developed
and maintained by Upstash. It is HTTP-based, which makes it ideal for serverless
environments like Vercel and Cloudflare Workers. In highly concurrent serverless
workloads, TCP-based clients can run into connection issues.

```typescript
import { Redis } from "@upstash/redis";

const redis = new Redis({
  url: "UPSTASH_REDIS_REST_URL",
  token: "UPSTASH_REDIS_REST_TOKEN",
});

(async () => {
  try {
    const data = await redis.get("key");
    console.log(data);
  } catch (error) {
    console.error(error);
  }
})();
```

See the [Connect with @upstash/redis page](/redis/howto/connect-with-upstash-redis) for more information.

## Node.js

**Library**: [ioredis](https://github.com/luin/ioredis)

```javascript
const Redis = require("ioredis");

let client = new Redis("rediss://default:YOUR_TOKEN@YOUR_ENDPOINT:YOUR_PORT");
await client.set("foo", "bar");
let x = await client.get("foo");
console.log(x);
```

## Python

**Library**: [redis-py](https://github.com/andymccurdy/redis-py)

```python
import redis
r = redis.Redis(
host= 'YOUR_ENDPOINT',
port= 'YOUR_PORT',
password= 'YOUR_TOKEN',
ssl=True)
r.set('foo','bar')
print(r.get('foo'))
```

## Java

**Library**: [jedis](https://github.com/xetorthio/jedis)

```java
Jedis jedis = new Jedis("YOUR_ENDPOINT", "YOUR_PORT", true);
jedis.auth("YOUR_TOKEN");
jedis.set("foo", "bar");
String value = jedis.get("foo");
System.out.println(value);
```

<Info>
  Jedis does not offer command level retry config by default, but you can handle
  retries using connection pool. Check [Retrying a command after a connection
  failure](https://redis.io/docs/latest/develop/clients/jedis/connect/#retrying-a-command-after-a-connection-failure)
</Info>

## PHP

**Library**: [phpredis](https://github.com/phpredis/phpredis)

```php
<?php

$redis = new Redis();

$redis->connect("YOUR_ENDPOINT", "YOUR_PORT");
$redis->auth("YOUR_TOKEN");

$redis->set("foo", "bar");

print_r($redis->get("foo"));
```

<Info>
  Phpredis supports connection level retries through `OPT_MAX_RETRIES`. However,
  for command level retries, it only supports [SCAN
  command](https://github.com/phpredis/phpredis?tab=readme-ov-file#example-29).
</Info>

## Go

**Library**: [redigo](https://github.com/gomodule/redigo)

```go
func main() {
  c, err := redis.Dial("tcp", "YOUR_ENDPOINT:YOUR_PORT", redis.DialUseTLS(true))
  if err != nil {
      panic(err)
  }

  _, err = c.Do("AUTH", "YOUR_TOKEN")
  if err != nil {
      panic(err)
  }

  _, err = c.Do("SET", "foo", "bar")
  if err != nil {
      panic(err)
  }

  value, err := redis.String(c.Do("GET", "foo"))
  if err != nil {
      panic(err)
  }

  println(value)
}
```
