pallets-eco/flask-caching

CACHE_OPTIONS has no effect if CACHE_REDIS_URL is set

dpgaspar opened this issue · 3 comments

Follow up for: #285

If not mistaken the fixed mentioned on the above issue is for Redis sentinel only

Setting the following config:

CACHE_CONFIG = {
    'CACHE_TYPE': 'redis',
    'CACHE_DEFAULT_TIMEOUT': '60*60',  # 1 hour for development
    'CACHE_REDIS_URL': "redis://cache1.us1a.zone:6379/0",
    'CACHE_OPTIONS': {
        'socket_timeout': 1,
        'socket_connect_timeout': 2,
    }
}

it works if we set: 'CACHE_REDIS_URL': "redis://cache1.us1a.zone:6379/0?socket_timeout=1&socket_connect_timeout=2",

on: https://github.com/pallets-eco/flask-caching/blob/master/src/flask_caching/backends/rediscache.py#L86

if we change:

        if redis_url:
            kwargs["host"] = redis_from_url(
                redis_url,
                db=kwargs.pop("db", None),
            )

to:

        if redis_url:
            kwargs["host"] = redis_from_url(
                redis_url,
                db=kwargs.pop("db", None),
                socket_timeout=kwargs.pop("socket_timeout", None),
                socket_connect_timeout=kwargs.pop("socket_connect_timeout", None),
                socket_keepalive=kwargs.pop("socket_keepalive", None),
                socket_keepalive_options=kwargs.pop("socket_keepalive_options", None),
                max_connections=kwargs.pop("max_connections", None),
                username=kwargs.pop("username", None),
                retry=kwargs.pop("retry", None),
                retry_on_timeout=kwargs.pop("retry_on_timeout", False),
                retry_on_error=kwargs.pop("retry_on_error", None),
                redis_connect_func=kwargs.pop("redis_connect_func", None),
            )

works! Not a great solution but we can't pass unknown kwargs, we have to be explicit, this will increase flask-caching dependency with redis-py versions

Happy to open a PR

Environment:

  • Python version: 3.8
  • Flask-Caching version: 1.10.1

Seconding this request. Similarly I am trying to pass in ssl_cert_reqs as a CACHE_OPTION and can see that it is not being passed to redis.

"CACHE_OPTIONS": {
    "ssl": True,
    "ssl_cert_reqs": "none",
},

@dpgaspar To confirm, adding the kwargs as query parameters to your CACHE_REDIS_URL is a workaround that fixed the problem for you?