R
Railway15mo 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
Percy15mo ago
Project ID: N/A
Iceman
Iceman15mo ago
N/A
Brody
Brody15mo ago
show a screenshot of your service variables please
Iceman
Iceman15mo ago
No description
Brody
Brody15mo ago
and show me the code that connects to the redis database please
Iceman
Iceman15mo ago
There's a lot but it's currently failing when it tries to cache the username and channel
No description
Brody
Brody15mo 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
Iceman15mo 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
Brody15mo 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
Iceman15mo ago
Okay, got it working. Thanks for the pointers!
Brody
Brody15mo ago
no problem!
Want results from more Discord servers?
Add your server