R
Railway10mo ago
Iceman

Redis not configured properly for Django

Hi, I'm trying to use Redis with Django and Channels. I keep getting this error message which seems to be suggesting that Redis isn't configured for running redis-py commands. I've tried to change the channel layer settings and not got anywhere. I don't know whether I'm supposed to be adding some sort of default setting for Redis itself. - got no idea why it's trying to connect to localhost. Anyone have any idea how to fix this? r.hset(self.scope['user'].username, mapping={'channel' : self.channel_name}) File "/opt/venv/lib/python3.11/site-packages/redis/commands/core.py", line 5019, in hset return self.execute_command("HSET", name, *items) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/venv/lib/python3.11/site-packages/redis/client.py", line 505, in execute_command conn = self.connection or pool.get_connection(command_name, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/venv/lib/python3.11/site-packages/redis/connection.py", line 1073, in get_connection connection.connect() File "/opt/venv/lib/python3.11/site-packages/redis/connection.py", line 265, in connect raise ConnectionError(self._error_message(e)) redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
11 Replies
Percy
Percy10mo ago
Project ID: N/A
Iceman
Iceman10mo ago
N/A
Brody
Brody10mo ago
show a screenshot of your service variables please
Iceman
Iceman10mo ago
No description
Brody
Brody10mo ago
and show me the code that connects to the redis database please
Iceman
Iceman10mo ago
There's a lot but it's currently failing when it tries to cache the username and channel
No description
Brody
Brody10mo ago
I don't see anywhere in that code that it's using environment variables, you aren't even importing os to read any environment variables
Iceman
Iceman10mo ago
I ran all this locally and it worked is it supposed to be set up like this on the server: r = redis.Redis(host='localhost', port=6379, decode_responses=True)
Brody
Brody10mo ago
yes but now you are on railway, you need to use the railway provided environment variables, otherwise you are just trying to connect to localhost
Iceman
Iceman10mo ago
Okay, got it working. Thanks for the pointers!
Brody
Brody10mo ago
no problem!