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.
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 …
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
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.