Skip to content

Passing sentinel_kwargs to redis client via CACHE_OPTIONS doesn't work #626

Open
@cjproud

Description

@cjproud

I have a Redis deployment on a k8s cluster which uses Redis Sentinel. The sentinels are configured to require authentication however I cannot pass the password through sentinel_kwargs (itself via CACHE_OPTIONS) as these get nested under a kwargs key when unpacked.

This is the structure of my CACHE_OPTIONS dict:

                "CACHE_OPTIONS":
                    {
                        "sentinel_kwargs": {
                            "password": get_dev_redis_password()
                            if not self.prod_flag
                            else get_prod_redis_password()
                        }
                    }

this is the traceback:

  File "/workspaces/dst_storage_dashboard/app.py", line 36, in <module>
    config.cache.init_app(server)
  File "/usr/local/lib/python3.12/site-packages/flask_caching/__init__.py", line 145, in init_app
    self._set_cache(app, config)
  File "/usr/local/lib/python3.12/site-packages/flask_caching/__init__.py", line 177, in _set_cache
    app.extensions["cache"][self] = cache_factory(
                                    ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask_caching/backends/rediscache.py", line 194, in factory
    return cls(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/flask_caching/backends/rediscache.py", line 170, in __init__
    sentinel = redis.sentinel.Sentinel(
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/redis/sentinel.py", line 237, in __init__
    Redis(hostname, port, **self.sentinel_kwargs)
TypeError: Redis.__init__() got an unexpected keyword argument 'kwargs'

I can clearly see when initialising the Sentinel object the sentinel_kwargs argument is populated like so:

{'kwargs': {'password': '<my-top-secret-password>'}}

where I'm assuming it should be:

{'password': '<my-top-secret-password>'}

I could be doing this incorrectly? I can't find any references to passing sentinel_kwargs as a cache option in any of the doco.

Environment:

  • Python version: 3.12
  • Flask-Caching version: 2.3.0

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