Skip to content

CACHE_OPTIONS has no effect if CACHE_REDIS_URL is set #443

Open
@dpgaspar

Description

@dpgaspar

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions