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
Project ID:
N/A
N/A
show a screenshot of your service variables please
and show me the code that connects to the redis database please
There's a lot but it's currently failing when it tries to cache the username and channel
I don't see anywhere in that code that it's using environment variables, you aren't even importing
os
to read any environment variablesI 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)
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
Okay, got it working. Thanks for the pointers!
no problem!