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
Percy17mo ago
Project ID: N/A
muzammil7524
muzammil7524OP17mo ago
N/A
Brody
Brody17mo ago
please show me a screenshot of your service variables
muzammil7524
muzammil7524OP17mo 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
Brody17mo ago
please show me a screenshot of your service variables
muzammil7524
muzammil7524OP17mo ago
muzammil7524
muzammil7524OP17mo ago
I have already setup as variable reference, just fyi i am using dockerfile to run my application
muzammil7524
muzammil7524OP17mo ago
I have done that but still my code is giving me this
muzammil7524
muzammil7524OP17mo 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
Brody17mo ago
please show me a screenshot of your service variables
muzammil7524
muzammil7524OP17mo ago
muzammil7524
muzammil7524OP17mo ago
can you please eloborate what I am wrong?
Brody
Brody17mo ago
start by reading the docs links i have sent
muzammil7524
muzammil7524OP17mo 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
Brody17mo ago
carefully read what i am about to say please add all database variables to your service variables keyword: all
muzammil7524
muzammil7524OP17mo ago
like this
Brody
Brody17mo ago
yes, now use them all in code or just use one if your redis client supports REDIS_URL
muzammil7524
muzammil7524OP17mo 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
Brody17mo ago
im just gonna stop here and ask, why are you ignoring almost everthing i say?
muzammil7524
muzammil7524OP17mo 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
Brody17mo ago
use all redis variables in code, unless your redis client supports REDIS_URL if so, just use REDIS_URL instead
muzammil7524
muzammil7524OP17mo 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
Brody17mo ago
please use the correct variable names in code https://docs.railway.app/databases/redis#connect
muzammil7524
muzammil7524OP17mo ago
variable names are also correct
Brody
Brody17mo ago
they are not
muzammil7524
muzammil7524OP17mo ago
I have updated them in my code
muzammil7524
muzammil7524OP17mo ago
Brody
Brody17mo ago
and show me how you are using those variables to connect
muzammil7524
muzammil7524OP17mo ago
this is my function
Brody
Brody17mo ago
at first glance that looks fine, show me the most recent error please
muzammil7524
muzammil7524OP17mo ago
getting this logs
Brody
Brody17mo ago
log all the variables see what's going on
muzammil7524
muzammil7524OP17mo ago
okay doing it
muzammil7524
muzammil7524OP17mo ago
not getting this
Brody
Brody17mo ago
^
muzammil7524
muzammil7524OP17mo ago
okay
muzammil7524
muzammil7524OP17mo 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
Brody17mo ago
full uncropped screenshot please
muzammil7524
muzammil7524OP17mo ago
muzammil7524
muzammil7524OP17mo ago
Brody
Brody17mo 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
muzammil7524OP17mo ago
Yes
Brody
Brody17mo ago
i hate to ask, but could you prove it?
muzammil7524
muzammil7524OP17mo ago
this is screenshot of repo in github
Brody
Brody17mo ago
are you sure this is a deployment from the railway service that you have setup the redis service variables in?
muzammil7524
muzammil7524OP17mo ago
Yes this is deployment, I am using github repo to get the code , you can also verify by name of repo
Brody
Brody17mo ago
can i see screenshots of both those services, service variables?
muzammil7524
muzammil7524OP17mo ago
muzammil7524
muzammil7524OP17mo ago
Brody
Brody17mo ago
looks good can you share your repo?
muzammil7524
muzammil7524OP17mo ago
it is private rn
muzammil7524
muzammil7524OP17mo ago
GitHub
GitHub - MuzammilMeh/2303-capstone-group-C
Contribute to MuzammilMeh/2303-capstone-group-C development by creating an account on GitHub.
Brody
Brody17mo ago
what branch are you deploying to railway?
muzammil7524
muzammil7524OP17mo ago
main
Brody
Brody17mo ago
just do a print(os.environ) instead
muzammil7524
muzammil7524OP17mo ago
okay just push the changes
Brody
Brody17mo ago
show me a screenshot when you get the logs
muzammil7524
muzammil7524OP17mo ago
Brody
Brody17mo ago
and you dont see any redis variables?
muzammil7524
muzammil7524OP17mo 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
Brody17mo 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
muzammil7524OP17mo ago
getting this issue in vs code ENV must have two variable
Brody
Brody17mo ago
one sec fixed, my bad
muzammil7524
muzammil7524OP17mo ago
pushed the changes
muzammil7524
muzammil7524OP17mo ago
muzammil7524
muzammil7524OP17mo 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
muzammil7524OP17mo ago
Brody
Brody17mo ago
let me know if you see the port logged in the build logs
muzammil7524
muzammil7524OP17mo ago
not able to see redis port
Brody
Brody17mo ago
keywords: build logs
muzammil7524
muzammil7524OP17mo ago
Brody
Brody17mo ago
just go look for it lol
muzammil7524
muzammil7524OP17mo ago
FOUND IT
muzammil7524
muzammil7524OP17mo ago
RUN echo 5937
Brody
Brody17mo ago
thats a port alright so something you are doing is removing the redis variables looks like you got some debugging to do
muzammil7524
muzammil7524OP17mo ago
what would that be, do you have any idea?
Brody
Brody17mo ago
im sorry i have no idea
muzammil7524
muzammil7524OP17mo ago
somehow port is not able to be added in environment variable
Brody
Brody17mo ago
its added, but you are erasing them somewhere
muzammil7524
muzammil7524OP17mo ago
okay let me debug, thank you for all the help Brody, I really appreciate it
Brody
Brody17mo ago
no problem, let me know how it goes
muzammil7524
muzammil7524OP17mo ago
and for bearing with me for sure
Want results from more Discord servers?
Add your server