emilhe / dash-extensions

The dash-extensions package is a collection of utility functions, syntax extensions, and Dash components that aim to improve the Dash development experience

Home Page:https://www.dash-extensions.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connecting to a Redis instance that isn't hosted locally

0xAtomist opened this issue · comments

Hi guys,

Love your work, getting really nice results when working locally but struggling to push this into the cloud. Even hosting the app locally I cannot get the RedisStore to redirect to a seperate URL. There is no documentation for this and I have attempted several different ways. The main problem I think being that you must initialise the app with the transforms=[ServersideOutputTransform(backend=RedisStore())] before any config variables can be set on flask_caching's Cache(). Therefore I cannot configure the Cache() before feeding it into RedisStore().

Error is always Error 61 connecting to localhost:6379. Connection refused. - because I am not hosting the Redis server locally.

Any help is greatly appreciated.

Thanks! You can pass keyword arguments to the underlying RedisCache object via the RedisStore constructor. See the details here,

https://github.com/pallets-eco/flask-caching/blob/6bb58967091f6d6b337933c0c7f72ac063ccd452/src/flask_caching/backends/rediscache.py#L40

Thanks for the quick response, although I'm still missing something obviously.

Loading app as so:
from flask_caching.backends import RedisCache
from dash_extensions.enrich import DashProxy, ServersideOutputTransform, RedisStore

app = DashProxy( __name__, transforms=[ServersideOutputTransform(backend=RedisStore(RedisCache(host='url.com', port=25061, password='password')))])

Arguments don't seem to be picked up by RedisCache object at all.

Ah, so what I meant was passing the arguments directly, so something like this,

rs = RedisStore(host='url.com', port=25061, password='password')
app = DashProxy( __name__, transforms=[ServersideOutputTransform(backend=rs)])

I see, thanks! Sorry the confusion on my part.

FYI, for any others, I am using a TLS secured managed Redis service. As such I have also had to add the following arguments:

RedisStore(ssl=True, ssl_cert_reqs="none")