> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Deno Deploy

<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](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.
</Tip>

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="https://mintcdn.com/upstash/e_ExbfXm6rSK53Ef/img/redis-deno/connect.png?fit=max&auto=format&n=e_ExbfXm6rSK53Ef&q=85&s=fcea71e9c6f6d649b35f52eeb01568c0" width="1748" height="560" data-path="img/redis-deno/connect.png" />
</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="https://mintcdn.com/upstash/e_ExbfXm6rSK53Ef/img/redis-deno/playground.png?fit=max&auto=format&n=e_ExbfXm6rSK53Ef&q=85&s=875fb0f8f1b3ce693d3a7334e32258f6" width="2556" height="1972" data-path="img/redis-deno/playground.png" />
</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="https://mintcdn.com/upstash/e_ExbfXm6rSK53Ef/img/redis-deno/env-variables.png?fit=max&auto=format&n=e_ExbfXm6rSK53Ef&q=85&s=9da6de783bfa323725a61f31dac2d96e" width="1152" height="1224" data-path="img/redis-deno/env-variables.png" />
</Frame>

### 4. Edit the handler function

Paste the following code into the browser editor:

```ts theme={"system"}
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.
