How to add Redis to an existing Node app?

Hi all,

I’m feeling I missed something (new to fly.io), but I was reading docs and examples the whole day and couldn’t find a solution that felt simple enough to add Redis to an existing Node app on Fly.
I created a Node Fly app in my repository and now want to add Redis to it. Coming from Heroku, it was a simple click in the UI, and Heroku created a Redis database and automatically created the environment variable to connect to it on my app.
It seems to be a bit different on Fly: Is it correct that I need to create a separate Fly app for Redis? Technically this database wouldn’t have anything in common with my Node app, right? And then, I connect my Node app by setting the Redis connection string manually? I also assume I would need to create a separate toml file? Can I use a docker-compose to be able to recreate the same setup on my local machine with the same config?

Sorry for all of these questions, but I feel a bit lost.

Thanks,
Fabian

No problem. You have several options depending on how you want to do it. There isn’t a one-click UI option (and alas the Fly-provided Redis URL which used to be there as a free temporary cache for apps has been deprecated).

Either …

  1. Run Fly as a separate app, just like you say, and then connect to that from your Node app. Fly have written a guide for doing that: Redis on Fly

  2. Fly does not support docker compose but you can run multi-process apps. See the first post from Kurt in this thread for how: Preview: multi process apps (get your workers here!)

  3. Run Redis as a separate sibling process to node in the same Docker container using a supervisor to keep both it and node running. For that approach, see the last Dockerfile example on Run multiple services in a container | Docker Documentation and adjust accordingly. I used that approach in the past to run nginx and php-fpm together, so it should work to run Node and Redis together.

Really depends if you want one app or two. Personally I think I’d opt for 1, but up to you.

2 Likes