Skip to content

More configurable Redis Cluster #40762

Open
@Agalin

Description

@Agalin

Problem Statement

When configuring Redis Cluster in settings only a few selected options are supported (startup_nodes and readonly_mode + a few more hardcoded values).

Not only it differs from Redis Blaster clusters (where whole config is passed after a minor transformation to hosts) but also blocks some important options:

  • Host/Port remapping.
  • User and password for authentication (or at least I haven't found a way to pass those as parts of the host name).
  • Read from replica (not sure if Sentry would work correctly in this mode).

Solution Brainstorm

Currently I'm using a small reimplementation of _RedisCluster's factory method that passes a copy of the whole config excluding is_redis_cluster (custom Sentry parameter) and hosts as it's overwritten explicitly):

def custom_factory(self, **config):
    hosts = config.get("hosts")
    hosts = list(hosts.values()) if isinstance(hosts, dict) else hosts

    def cluster_factory():
        if config.get("is_redis_cluster", False):
            # Copy config and remove Sentry-specific keys.
            safe_config = deepcopy(config)
            del safe_config["is_redis_cluster"]
            hosts = safe_config.pop("hosts")
            return RetryingRedisCluster(
                startup_nodes=hosts,
                decode_responses=True,
                skip_full_coverage_check=True,
                max_connections=16,
                max_connections_per_node=True,
                **safe_config  # Pass all options to the Redis Cluster client.
            )
        else:
            host = hosts[0].copy()
            host["decode_responses"] = True
            return (
                import_string(config["client_class"])
                if "client_class" in config
                else StrictRedis
            )(**host)

    return SimpleLazyObject(cluster_factory)

It works fine but I assume there are reasons only selected list of options is supported.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions