# Getting Started with Netlify Edge Functions and Serverless Redis

> **Source:** https://upstash.com/blog/netlify-edge-redis
> **Date:** 2022-05-03
> **Author(s):** Enes Akar
> **Reading time:** 2 min read
> **Tags:** serverless, redis, edge, netlify
> **Format:** text/markdown — machine-readable content for agents and LLMs

---

Recently, Netlify
announced [Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions/)
where you can run your code at edge locations on Deno runtime with globally low
latency. In this post, we will build a simple app which runs Netlify Edge
functions and accesses Upstash Redis® as a data store. Upstash Redis® is a perfect
match for Netlify Edge Functions because:

- Upstash Redis has Global database type where the Redis replicas are
  distributed all over the world. So your edge function will access to the
  closest region with low latency.
- Upstash Redis has a built-in REST API and SDK which is free from any
  connection issues common in serverless runtimes.
- Upstash Redis has a [JS SDK](https://github.com/upstash/upstash-redis) which
  is built and tested with Deno runtime

### Project Setup

_You can check
out [this folder](https://github.com/upstash/redis-examples/tree/master/netlify-edge-with-redis)
if you want to skip the below steps._

![](/blog/netlify-edge/project.png)

Create an empty Node project (`npm init`) and create `hello.js`
under `netlify>edge-functions` as below:

```js title="hello.js"
import { Redis } from "https://deno.land/x/upstash_redis@v1.3.2/mod.ts";

export default async () => {
  const redis = Redis.fromEnv();
  const counter = await redis.incr("edge_counter");
  return new Response(counter);
};
```

Create a netlify.toml file in your project folder

```toml:netlify.toml
[[edge_functions]]
path = "/test"
function = "hello"
```

Create an `.env` file in your project folder

```text:.env
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
```

Now, create a Redis database
from [Upstash Console](https://console.upstash.com/). Select the Global database
to minimize the latency from your edge functions. Copy the REST_URL and
REST_TOKEN from Upstash dashboard and paste to the `.env`.

![](/blog/netlify-edge/upstash.png)

### Test and Deploy

You can run the application locally via:
`netlify dev` and check `http://localhost:8888/test`

Also, you can deploy your app
using [Netlify dashboard](https://app.netlify.com/). You need to set Upstash URL
and Token as an environment variable in Netlify.

![](/blog/netlify-edge/dashboard.png)

## Closing Words

In this article, we have showcased how to use Upstash Redis in Netlify Edge
Functions.

Feel free to reach out us on
[Discord](https://upstash.com/discord)
and [Twitter](https://twitter.com/upstash) for any issues or comments.