> ## Documentation index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Ask it with GET https://upstash.com/docs/ask?q=<keywords or question>. Short keywords rank best.
> Use these to discover all available pages before exploring further.
> Feature requests: https://upstash.com/docs/common/help/feature-requests.md lists what users asked for and how to vote for a request or add one.
> Page rating: `GET https://upstash.com/docs/feedback?path=/docs/redis/quickstarts/deno-deploy&helpful={true|false}&comment={comment}` records whether this page helped. The `comment` (URL-encoded, at most 500 characters) says what helped, or what was missing or wrong; a `helpful=false` rating needs it. It is anonymous and needs no key. Comments hold no code, secrets or personal data.

# Upstash Redis with Deno Deploy

> Build a view counter on Deno Deploy that stores its count in Upstash Redis using @upstash/redis.

This is a step-by-step guide on how to use Upstash Redis to create a view
counter in your Deno Deploy project.

### 1. Create a database

Create a Redis database using [Upstash Console](https://console.upstash.com) or
[Upstash CLI](https://github.com/upstash/cli). Select the global to minimize the
latency from all edge locations. Copy the `UPSTASH_REDIS_REST_URL` and
`UPSTASH_REDIS_REST_TOKEN` from the **Connect** section of your database for the
next steps.

<Frame>
  <img src="/img/redis-deno/connect.png" alt="Connect Deno Deploy to Upstash Redis" />
</Frame>

### 2. Create a Deno Deploy playground

Go to [https://console.deno.com](https://console.deno.com), open your
organization's **Applications** page and click **New Playground**. This creates
a "Hello World" playground with a browser editor.

<Frame>
  <img src="/img/redis-deno/playground.png" alt="Deno Deploy playground with Upstash Redis" />
</Frame>

### 3. Set the environment variables

Click **Env Variables** in the top bar of the playground and add the
`UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` variables. You can add
them one by one with **Add variable**, or paste both lines you copied from the
Upstash Console into **Import from .env file** and click **Import Variables**.

<Frame>
  <img src="/img/redis-deno/env-variables.png" alt="Redis environment variables in Deno Deploy" />
</Frame>

### 4. Edit the handler function

Paste the following code into the browser editor:

```ts
import { Redis } from "npm:@upstash/redis";

const redis = new Redis({
  url: Deno.env.get("UPSTASH_REDIS_REST_URL")!,
  token: Deno.env.get("UPSTASH_REDIS_REST_TOKEN")!,
});

Deno.serve(async (req: Request) => {
  if (new URL(req.url).pathname === "/favicon.ico") {
    return new Response(null, { status: 404 });
  }

  const counter = await redis.incr("deno-counter");
  return new Response(JSON.stringify({ counter }), {
    status: 200,
    headers: { "Content-Type": "application/json" },
  });
});
```

### 5. Deploy and run

Click **Deploy** in the top bar. Once the build finishes, open the playground
URL to see the counter increase on every refresh.
