redis / go-redis

Redis Go client
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
19.65k stars 2.32k forks source link

ClusterOptions needs the callback for getting username and password to pass to the underlying Redis object #2888

Closed scr-oath closed 5 months ago

scr-oath commented 5 months ago

Expected Behavior

When using the GCP MemoryStore redis cluster, the credentials only last for about an hour. therefore, the same option added in https://github.com/redis/go-redis/pull/2097 needs to be added to the ClusterOptions and passed through to the underlying NewRedis call's Options object.

Current Behavior

There is only the static Username and Password options on the ClusterOptions; because of this, cluster clients may only be used for up to an hour and then need to be replaced with a new one.

Possible Solution

Add and curry/copy the CredentialsProvider option to the NewRedis call. Maybe also provide an option that provides a method that takes a Context and returns error as suggested in https://github.com/redis/go-redis/issues/2681

Steps to Reproduce

Just try to invent a way to change the password periodically and see that you can't without getting very deep in the guts with reflection and changing things around.

Context (Environment)

This is blocking or at least hindering use of this client with GCP MemoryStore redis cluster; possible workaround is to replace the entire client with a frequency more than the expiration duration.

https://github.com/redis/go-redis/pull/2097 solved this for redis instance.

Detailed Description

Possible Implementation

Provide the same option in the cluster options and ensure that gets to the underlying redis client's Options.

scr-oath commented 5 months ago

Seems to be a duplicate of #2790