Unable to connect to Managed Redis instance

I’ve created a dedicated Redis instance in Fly using it, but when I try to connect to the Redis instance from my workers, I get the following error:

Could not connect to Redis instance: Connection closed by server. Retrying in 60 seconds..

I’m using RQ with Django on Python 3.8. Any ideas on what’s going on here?

1 Like

Having a similar problem with the rqworker command connecting to an upstash redis instance:

Traceback (most recent call last):
File "/app/manage.py", line 22, in <module>
File "/app/manage.py", line 18, in main
"/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
"/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
"/opt/venv/lib/python3.10/site-packages/django_rq/management/commands/rqworker.py", line 122, in handle
w = get_worker(*args, **worker_kwargs)
"/opt/venv/lib/python3.10/site-packages/django_rq/workers.py", line 51, in get_worker
return worker_class(queues,
File "/opt/venv/lib/python3.10/site-packages/rq/worker.py", line 228, in __init__
self.ip_address = [
IndexError: list index out of range

I’ve tried connecting with the resolved ipv6 address and got the same exception.

Weird thing is, Django’s redis cache works fine, just the worker failing.

@ibutiti For this error, there’s a patch for that. Add this to your requirement.txt


This will use the latest version of rq which has a fix.

1 Like

Following up on this, any ideas why this may not be working?

Can you post how you’re connecting to Redis? Something like conn2 = Redis('yours.upstash.io', 6379)

@jsierles Yeah, this is in my settings.py

    "default": {
        "URL": os.getenv("REDIS_URL", "redis://localhost:6379/0"),
        "DEFAULT_TIMEOUT": 600,
    "high": {
        "URL": os.getenv("REDIS_URL", "redis://localhost:6379/0"),
        "DEFAULT_TIMEOUT": 180,

This was working fine on Heroku and I made a Redis cluster on Render and it worked there as well. REDIS_URL is the value of my Upstash URL that was provided.

Are you appending the /0 database as well? Another thing to consider is the Upstash IPs are IPv6 addresses. That doesn’t seem like it should cause problems, but worth noting in case something specific is needed to make that work with Python.

UPDATE: I tried this using the redis library required by rq:

import redis
r = redis.Redis.from_url(“redis://default:mypass@fly-myhost.upstash.io”)
r.set(‘a’, 1)

I’m not appending /0 to the URL as well, is that necessary?

I’m also using django-rq, I wonder if there’s an issue there? I’d have expected it to work regardless, tbh. Let me try again and see what happens.

It worked! Thank you!