R
Railway

✋|help

Problem with Flask-Caching/ Redis

LL9/18/2023
I'm trying to setup a simple caching mecanism to my Plotly Dash (Flask) application deployed to railway. I'm not being able to setup it correctly. Is this the correct implementation? Project ID: eda27a88-d8f4-495f-b917-1fd2269f5764
No description
BBrody9/18/2023
please setup a MONGO_URL and a REDIS_URL reference variable in your service variables https://docs.railway.app/develop/variables#reference-variables once done please provide a screenshot of your service variables
LL9/18/2023
Ok.
LL9/18/2023
Something like this?
No description
BBrody9/18/2023
please use reference variables, remove them, and have a look at the docs section I linked
LL9/18/2023
My mongo DB must be in the same project?
No description
BBrody9/18/2023
yes it does need to be
LL9/18/2023
I apologize for my knowledge level.
No description
BBrody9/18/2023
no worries, that looks good now now use those variables in your code when connecting to the database
LL9/18/2023
ok. I should use like this: variable = ${{MongoDB.MONGO_URL}} or variable = MONGO_URL of course option 1, good?
BBrody9/18/2023
neither of those options are python related I think for python it's os.getenv() but definitely read the docs for that
LL9/19/2023
I will do it. Thanks for you fast and incredible help, really impressed by this support. It looks like its working. Any way I can assure the redis caching is working?
BBrody9/19/2023
do something in your app that would put something in the cache, then use the data tab of redis to see if you have any cache entries
LL9/19/2023
Unfortunately no logs and no data saved.
BBrody9/19/2023
and you dont have any database connection errors?
LL9/19/2023
Only a warning on redis db log
LL9/19/2023
No description
BBrody9/19/2023
im talking about in your own service
LL9/19/2023
I'm getting no errors in my service (https://heatmapteste2-production.up.railway.app/)
BBrody9/19/2023
make sure you are either logging a success message or an error message for your database connections
LL9/19/2023
No description
LL9/19/2023
Looks good
BBrody9/19/2023
can you show me the database connection code?
LL9/19/2023
No description
BBrody9/19/2023
you are still hard coding database variables, please use environment variables
LL9/19/2023
i will try to comment line 21
BBrody9/19/2023
and you also aren't logging any success or error messages for the database connections
LL9/19/2023
No description
BBrody9/19/2023
okay thats looking much better
LL9/19/2023
Here is the updated code logging sucess or error mesages. And the variables arent hard coded
BBrody9/19/2023
well done
LL9/19/2023
Thanks for your advice.
BBrody9/19/2023
can i assume you have added the new variables to the service variables? can i see a screenshot?
LL9/19/2023
No description
BBrody9/19/2023
looking good and you arent getting any errors in the deployment logs?
LL9/19/2023
all good
No description
BBrody9/19/2023
how do you run this app locally?
LL9/19/2023
I didnt tried to run locally with the caching mechanism I would have to change the cache_type to something local aswell
BBrody9/19/2023
you can still use the railway redis and mongo databases locally install the railway cli https://docs.railway.app/develop/cli#installation once you have that all setup and your service linked you can run railway run <the command you use to start the app locally> this will run the given command with the railway service variables available note: do not use any .env files for this, the variables in the .env file will overwrite the variables injected by railway run this way you could work out any bugs in your code locally without having to deploy to railway for every change
LL9/19/2023
Ok, tks for advice I will run it
BBrody9/19/2023
👍
LL9/19/2023
Damn, I got some data on Redis running locally with railway CLI
LL9/19/2023
No description
BBrody9/19/2023
awsome, now go to your railway services settings and disable private networking
LL9/19/2023
done
LL9/19/2023
No description
BBrody9/19/2023
now do more stuff with the railway hosted app and see if you get more data in redis
LL9/19/2023
yeah thats working means its solved... i believe
BBrody9/19/2023
awsome!
LL9/19/2023
Brody, you are a monster... I wish I had 10% of your knowledge. Awesome job! Kiss on your cheek and my regards from Brazil. I can't be thankfull enought. So its a good practice to build using railway CLI and railway env variables
BBrody9/19/2023
it sure is, now you have no need for an .env file since you can safely store everything in your service variables
LL9/19/2023
stonks are a monster of computing
BBrody9/19/2023
thank you 🙂
LL9/19/2023
sorry to bother again, but why private networking was blocking my redis db?
BBrody9/19/2023
good question, private networking takes 2 seconds to initialize and if your database connection timeout isnt set high enough funky things can happen, you wernt using private networking so the easiest option was simply disabling it
LL9/19/2023
tks! you would do a great teacher. You can consider this ticket closed. Tks a lot again.

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Worker Killed IssueI'm getting the attached error when I try to request my app from a React frontend, whereas I wasn't Need help with deploymentSubject: Seeking Guidance on Loading Environment Variables in Railway for My Go API Deployment Hi ebun: command not foundHello, I'm trying to migrate my project to bun to make TS easier, and I'm when deploying, the logs Metrics on Number of Web RequestsI just deployed a web API and would like to keep track of the number of requests made to the API. DoIs there a timeout on my api functions when deploying a nextjs app?I coudnt find anything about this on google or the docs, Thanks for helpingI have problems with the database when I do a deploy.I have a mongo DB database that is connected to a node js, to connect to mongo I use the url that moI have problems with the database when I do a deploy.I have a mongo DB database that is connected to a node js, to connect to mongo I use the url that moError comunicate with internal servicecsI'm trying to make a post on a route that is in an internal service on railway = api-ecompleto.railwUnchanged repo fails to deploy on env var change.I had this exact setup running last night, and this morning when I changed an environment variable iIs it possible to host Unity project?I have a unity game development project which runs C# Since I already use railway for my other projCan't see organizations reposTitle.Please my images are not displaying after deploying on railway. I am new in web development.Please I am new to web development and first time deploying to railway. I have django drf backend wiISO 27001Hi this might be a dumb question but does Railway have the ISO 27001 certification or is that irreledeploying react with viteI've deployed a react app with vite, exposing network ip but I can't access it - says Application faOpenSSL error when using Bun + PrismaGetting an error when using Bun and prisma together. Prisma requires node to work, so start command Server isnt workingThe server suddenly stopped working. Could anyone explain what is going on?...How to deploy a project with multiple dockerfiles?Have project that has one `Dockerfile` for the backend service and another one `Dockerfile.celery` fWildcard DNS let user custom there domainI would like to know how to let's my users custom domain with CNAME to my domain DNS my DOMAIN CNABun with turborepo supportHey guys, Just switched over to bun from fastify but having some trouble setting it up properly to How does pro plan upgrade works for application? particularly Spring boot app...Hi all, I find it difficult to understand how pro plan upgrade works. I upgraded my Spring boot app