# Bun Redis with Upstash (/docs/guides/ecosystem/upstash)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 639 · updated: 2026-07-28 -->
Related: [Build an app with Astro and Bun](/docs/guides/ecosystem/astro.md), [Create a Discord bot](/docs/guides/ecosystem/discordjs.md), [Containerize a Bun application with Docker](/docs/guides/ecosystem/docker.md), [Use Drizzle ORM with Bun](/docs/guides/ecosystem/drizzle.md), [Use Gel with Bun](/docs/guides/ecosystem/gel.md), [Build an HTTP server using Elysia and Bun](/docs/guides/ecosystem/elysia.md)

[Upstash](https://upstash.com/) is a fully managed Redis database as a service. It works with the Redis® API, so you can connect with Bun's native Redis client.

<Note>
  TLS is enabled by default for all Upstash Redis databases.
</Note>

***

<Steps>
  <Step title="Create a new project">
    Create a new project with `bun init`:

    ```sh terminal icon="terminal"
    bun init bun-upstash-redis
    cd bun-upstash-redis
    ```
  </Step>

  <Step title="Create an Upstash Redis database">
    Go to the [Upstash dashboard](https://console.upstash.com/) and create a new Redis database. After completing the [getting started guide](https://upstash.com/docs/redis/overall/getstarted), you'll see your database page with connection information.

    The database page displays two connection methods: HTTP and TLS. For Bun's Redis client, you need the **TLS** connection details; the URL starts with `rediss://`.

    <Frame>
      ![Upstash Redis database page](/docs/_assets/1c558fd215a7b26747ac73591f2e4652767000b41d49dbf6b3b6039fde21e8b1)
    </Frame>
  </Step>

  <Step title="Connect using Bun's Redis client">
    Set the `REDIS_URL` environment variable in your `.env` file using the Redis endpoint (not the REST URL):

    ```ini .env icon="settings"
    REDIS_URL=rediss://********@********.upstash.io:6379
    ```

    Bun's Redis client reads connection information from `REDIS_URL` by default:

    ```ts index.ts icon="/icons/typescript.svg"
    import { redis } from "bun";

    // Reads from process.env.REDIS_URL automatically
    await redis.set("counter", "0"); // [!code ++]
    ```

    Alternatively, create a custom client with `RedisClient`:

    ```ts index.ts icon="/icons/typescript.svg"
    import { RedisClient } from "bun";

    const redis = new RedisClient(process.env.REDIS_URL); // [!code ++]
    ```
  </Step>

  <Step title="Use the Redis client">
    Use the Redis client to read and write keys in your Upstash database:

    ```ts index.ts icon="/icons/typescript.svg"
    import { redis } from "bun";

    // Get a value
    let counter = await redis.get("counter");

    // Set a value if it doesn't exist
    if (!counter) {
    	await redis.set("counter", "0");
    }

    // Increment the counter
    await redis.incr("counter");

    // Get the updated value
    counter = await redis.get("counter");
    console.log(counter);
    ```

    ```txt
    1
    ```

    The Redis client handles connections automatically. You don't need to connect or disconnect manually for basic operations.
  </Step>
</Steps>
