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