Black Lives Matter. Please consider donating to Black Girls Code today.

Using Redis in Dash

Hi! I am trying to use Flask-caching with redis,
and I get an error message “ConnectionRefusedError: [Errno 61] Connection refused” when I try to set the cache.

cache = Cache(app.server, config={
‘CACHE_TYPE’: ‘redis’,
‘CACHE_REDIS_URL’: os.environ.get(‘REDIS_URL’, ‘’)})

cache.set(“test”, “testing”)

How do I set and get data from cache?

Thank you!

Hi! i have redis on same machine that runs dash app with gunicorn so my working config is
app = dash.Dash(name)

‘CACHE_REDIS_URL’: os.environ.get(‘REDIS_URL’,‘localhost:6379’)


1 Like

This looks very similar to the code example/tutorial >

I found this discussion after searching for solution to this error message.

ValueError: Redis URL must specify one of the followingschemes (redis://, rediss://, unix://)

I’m not using gunicorn (roman mentioned using gunicorn) and the code example does not mention using gunicorn, so I’m a bit lost here.


Traceback (most recent call last): File “”, line 63, in cache.init_app(app.server, config=CACHE_CONFIG) File “/home/bmt/anaconda3/lib/python3.7/site-packages/flask_caching/”, line 212, in init_app self._set_cache(app, config) File “/home/bmt/anaconda3/lib/python3.7/site-packages/flask_caching/”, line 239, in _set_cache app, config, cache_args, cache_options File “/home/bmt/anaconda3/lib/python3.7/site-packages/flask_caching/backends/”, line 94, in redis kwargs[“host”] = redis_from_url(redis_url, db=kwargs.pop(“db”, None)) File “/home/bmt/anaconda3/lib/python3.7/site-packages/redis/”, line 19, in from_url return Redis.from_url(url, db, **kwargs) File “/home/bmt/anaconda3/lib/python3.7/site-packages/redis/”, line 638, in from_url connection_pool = ConnectionPool.from_url(url, db=db, **kwargs) File “/home/bmt/anaconda3/lib/python3.7/site-packages/redis/”, line 999, in from_url ‘schemes (%s)’ % valid_schemes) ValueError: Redis URL must specify one of the followingschemes (redis://, rediss://, unix://)

I actually configured my Redis server this morning and ran into the same thing. If Redis is running on a remote server, there’s a few things you can do:

  1. Update the firewall on Redis server to allow traffic to Redis port (6379)

  2. Update redis.conf to specify what IP addresses to use. By default, Redis binds to, which does not allow remote connections. You can comment out the bind, which binds all interfaces or specify exactly which IP addresses should be included in the bind. Example: #bind or bind 10.x.x.x

  3. Redis runs in protected mode by default, you can disable this by updating to protected-mode no in the redis.conf file. If you do this though, you should probably use a username and password to authenticate the connection though. Or just limit the remote connections to be from specific hosts.