Deployment
We support various platforms, such as nodejs, cloudflare and fastly. Platforms
differ slightly when it comes to environment variables and their fetch
api.
Please use the correct import when deploying to special platforms.
Node.js / Browser
Examples: Vercel, Netlify, AWS Lambda
If you are running on nodejs you can set UPSTASH_REDIS_REST_URL
and
UPSTASH_REDIS_REST_TOKEN
as environment variable and create a redis instance
like this:
import { Redis } from "@upstash/redis"
const redis = new Redis({
url: <UPSTASH_REDIS_REST_URL>,
token: <UPSTASH_REDIS_REST_TOKEN>,
})
// or load directly from env
const redis = Redis.fromEnv()
If you are running on nodejs v17 and earlier, fetch
will not be natively
supported. Platforms like Vercel, Netlify, Deno, Fastly etc. provide a polyfill
for you. But if you are running on bare node, you need to either specify a
polyfill yourself or change the import path slightly:
import { Redis } from "@upstash/redis/with-fetch";
Cloudflare Workers
Cloudflare handles environment variables differently than Node.js. Please add
UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
using
wrangler secret put ...
or in the cloudflare dashboard.
Afterwards you can create a redis instance:
import { Redis } from "@upstash/redis/cloudflare"
const redis = new Redis({
url: <UPSTASH_REDIS_REST_URL>,
token: <UPSTASH_REDIS_REST_TOKEN>,
})
// or load directly from global env
// service worker
const redis = Redis.fromEnv()
// module worker
export default {
async fetch(request: Request, env: Bindings) {
const redis = Redis.fromEnv(env)
// ...
}
}
Fastly
Fastly introduces a concept called
backend. You
need to configure a backend in your fastly.toml
. An example can be found
here.
Until the fastly api stabilizes we recommend creating an instance manually:
import { Redis } from "@upstash/redis/fastly"
const redis = new Redis({
url: <UPSTASH_REDIS_REST_URL>,
token: <UPSTASH_REDIS_REST_TOKEN>,
backend: <BACKEND_NAME>,
})
Deno
Examples: Deno Deploy, Netlify Edge
import { Redis } from "https://deno.land/x/upstash_redis/mod.ts"
const redis = new Redis({
url: <UPSTASH_REDIS_REST_URL>,
token: <UPSTASH_REDIS_REST_TOKEN>,
})
// or
const redis = Redis.fromEnv();
Was this page helpful?