redis

I am having issues regarding connecting environment variable from redis to my two service, I have passed environment variable, but service is unable to find it.
85 Replies
Percy
Percy16mo ago
Project ID: N/A
muzammil7524
muzammil752416mo ago
N/A
Brody
Brody16mo ago
please show me a screenshot of your service variables
muzammil7524
muzammil752416mo ago
I am passing my environment variable in my code like this redis_host = os.environ.get("REDIS_HOST") redis_port = os.environ.get("REDIS_PORT") and using reference variable.
Brody
Brody16mo ago
please show me a screenshot of your service variables
muzammil7524
muzammil752416mo ago
muzammil7524
muzammil752416mo ago
I have already setup as variable reference, just fyi i am using dockerfile to run my application
muzammil7524
muzammil752416mo ago
I have done that but still my code is giving me this
muzammil7524
muzammil752416mo ago
do I need to mention env variable to dockerfile, or do I need to change my code, I am not able to understand this as I am new to this deployment.
Brody
Brody16mo ago
please show me a screenshot of your service variables
muzammil7524
muzammil752416mo ago
muzammil7524
muzammil752416mo ago
can you please eloborate what I am wrong?
Brody
Brody16mo ago
start by reading the docs links i have sent
muzammil7524
muzammil752416mo ago
sorry, but I am still not able to understand what I am doing wrong, do i need to change my code or something else.
Brody
Brody16mo ago
carefully read what i am about to say please add all database variables to your service variables keyword: all
muzammil7524
muzammil752416mo ago
like this
Brody
Brody16mo ago
yes, now use them all in code or just use one if your redis client supports REDIS_URL
muzammil7524
muzammil752416mo ago
redis_host = os.environ.get("REDIS_HOST") redis_port = os.environ.get("REDIS_PORT") is this way to getting environment variable is correct
Brody
Brody16mo ago
im just gonna stop here and ask, why are you ignoring almost everthing i say?
muzammil7524
muzammil752416mo ago
My redis client only requires host and port to run, that is why I am only mentioning this. I am sorry if I am not able to make myself clear
Brody
Brody16mo ago
use all redis variables in code, unless your redis client supports REDIS_URL if so, just use REDIS_URL instead
muzammil7524
muzammil752416mo ago
okay I will do that Hi Brody, I did everything you ask but this code is unable to find the port. it is getting none
Brody
Brody16mo ago
please use the correct variable names in code https://docs.railway.app/databases/redis#connect
muzammil7524
muzammil752416mo ago
variable names are also correct
Brody
Brody16mo ago
they are not
muzammil7524
muzammil752416mo ago
I have updated them in my code
muzammil7524
muzammil752416mo ago
Brody
Brody16mo ago
and show me how you are using those variables to connect
muzammil7524
muzammil752416mo ago
this is my function
Brody
Brody16mo ago
at first glance that looks fine, show me the most recent error please
muzammil7524
muzammil752416mo ago
getting this logs
Brody
Brody16mo ago
log all the variables see what's going on
muzammil7524
muzammil752416mo ago
okay doing it
muzammil7524
muzammil752416mo ago
not getting this
Brody
Brody16mo ago
^
muzammil7524
muzammil752416mo ago
okay
muzammil7524
muzammil752416mo ago
This issue is my code is not able to get any environment variable by redis, I have logged all the environment varible in my code none of them are from redis
Brody
Brody16mo ago
full uncropped screenshot please
muzammil7524
muzammil752416mo ago
muzammil7524
muzammil752416mo ago
Brody
Brody16mo ago
i mean thats still cropped but it showed me what i wanted to see so good enough are you sure this is a deployment from the service that you have setup the redis service variables in?
muzammil7524
muzammil752416mo ago
Yes
Brody
Brody16mo ago
i hate to ask, but could you prove it?
muzammil7524
muzammil752416mo ago
this is screenshot of repo in github
Brody
Brody16mo ago
are you sure this is a deployment from the railway service that you have setup the redis service variables in?
muzammil7524
muzammil752416mo ago
Yes this is deployment, I am using github repo to get the code , you can also verify by name of repo
Brody
Brody16mo ago
can i see screenshots of both those services, service variables?
muzammil7524
muzammil752416mo ago
muzammil7524
muzammil752416mo ago
Brody
Brody16mo ago
looks good can you share your repo?
muzammil7524
muzammil752416mo ago
it is private rn
muzammil7524
muzammil752416mo ago
GitHub
GitHub - MuzammilMeh/2303-capstone-group-C
Contribute to MuzammilMeh/2303-capstone-group-C development by creating an account on GitHub.
Brody
Brody16mo ago
what branch are you deploying to railway?
muzammil7524
muzammil752416mo ago
main
Brody
Brody16mo ago
just do a print(os.environ) instead
muzammil7524
muzammil752416mo ago
okay just push the changes
Brody
Brody16mo ago
show me a screenshot when you get the logs
muzammil7524
muzammil752416mo ago
Brody
Brody16mo ago
and you dont see any redis variables?
muzammil7524
muzammil752416mo ago
this is environment variable environ({'HOME': '/root', 'LOGNAME': 'root', 'PATH': '/usr/bin:/bin', 'SHELL': '/bin/sh', 'PWD': '/root', 'LC_CTYPE': 'C.UTF-8', 'SPARK_AUTH_SOCKET_TIMEOUT': '15', 'SPARK_BUFFER_SIZE': '65536'}) Nope
Brody
Brody16mo ago
starting on line 2 of your dockerfile add
ARG REDISPORT
ENV REDISPORT=$REDISPORT
RUN echo $REDISPORT
ARG REDISPORT
ENV REDISPORT=$REDISPORT
RUN echo $REDISPORT
and let me know if you see the port logged in the build logs
muzammil7524
muzammil752416mo ago
getting this issue in vs code ENV must have two variable
Brody
Brody16mo ago
one sec fixed, my bad
muzammil7524
muzammil752416mo ago
pushed the changes
muzammil7524
muzammil752416mo ago
muzammil7524
muzammil752416mo ago
environ({'HOME': '/root', 'LOGNAME': 'root', 'PATH': '/usr/bin:/bin', 'SHELL': '/bin/sh', 'PWD': '/root', 'LC_CTYPE': 'C.UTF-8', 'SPARK_AUTH_SOCKET_TIMEOUT': '15', 'SPARK_BUFFER_SIZE': '65536'})
muzammil7524
muzammil752416mo ago
Brody
Brody16mo ago
let me know if you see the port logged in the build logs
muzammil7524
muzammil752416mo ago
not able to see redis port
Brody
Brody16mo ago
keywords: build logs
muzammil7524
muzammil752416mo ago
Brody
Brody16mo ago
just go look for it lol
muzammil7524
muzammil752416mo ago
FOUND IT
muzammil7524
muzammil752416mo ago
RUN echo 5937
Brody
Brody16mo ago
thats a port alright so something you are doing is removing the redis variables looks like you got some debugging to do
muzammil7524
muzammil752416mo ago
what would that be, do you have any idea?
Brody
Brody16mo ago
im sorry i have no idea
muzammil7524
muzammil752416mo ago
somehow port is not able to be added in environment variable
Brody
Brody16mo ago
its added, but you are erasing them somewhere
muzammil7524
muzammil752416mo ago
okay let me debug, thank you for all the help Brody, I really appreciate it
Brody
Brody16mo ago
no problem, let me know how it goes
muzammil7524
muzammil752416mo ago
and for bearing with me for sure
Want results from more Discord servers?
Add your server