Skip to main content
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 (free, no signup; 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.
Fly.io has a native integration with Upstash where the databases are hosted in Fly. You can still access a Redis from Fly to Upstash but for the best latency, we recommend creating Redis (Upstash) inside Fly platform. Check here for details.
In this tutorial, we’ll walk you through the process of deploying a Redis by Upstash and connecting it to an application hosted on Fly.io. We’ll be using Node.js and Express for our example application, but the process can be easily adapted to other languages and frameworks.

Redis Setup

Create a Redis database using Fly CLI
Upstash Redis on Fly.io offers a pay-as-you-go plan as well as fixed-size plans. See the Fly.io docs for current pricing.

Set up the Node.js application

  • Create a new folder for your project and navigate to it in the terminal.
  • Run npm init -y to create a package.json file.
  • Install Express and the Redis client: npm install express redis
  • Create an index.js file in the project folder with the following content:
This code creates a simple Express server that increments a counter in Redis and returns the visitor number.

Configure the Fly.io application

  • Run fly launch to initialize a new Fly.io application, and accept the defaults for the prompts.
  • Since the Redis URL contains your database password, store it as a secret instead of putting it in fly.toml:
Replace your-upstash-redis-url with the Redis URL from your Upstash instance. The secret is made available to your application as the REDIS_URL environment variable.

Deploy the application to Fly.io

  • Run fly deploy to build and deploy your application.
  • After the deployment is complete, run fly status to check if the application is running.
  • Visit the URL provided in the output (e.g., https://your-app-name.fly.dev) to test your application.

Conclusion

You have successfully deployed a Node.js application on Fly.io that uses an Upstash Redis instance as its data store. You can now build and scale your application as needed, leveraging the benefits of both Fly.io and Upstash.

Local Development

Your database is only reachable over your Fly organization’s private IPv6 network, so the redis://...upstash.io URL does not work from your local machine. For local development, Fly CLI can open a secure tunnel to the database.

Explore your data with redis-cli

This proxies local port 16379 to your database and opens an interactive redis-cli session, so you can inspect keys and run commands directly.

Run your application against the tunnel

To use the database from a locally running application, open a plain proxy instead:
Keep it running, and point your application at localhost:16379 using the password from your Redis URL:
Since the application already reads REDIS_URL from the environment, no code changes are needed.
The tunnel is meant for development and testing, not production. For a fully local setup, you can also run a local Redis server instead.