redis / rueidis

A fast Golang Redis client that supports Client Side Caching, Auto Pipelining, Generics OM, RedisJSON, RedisBloom, RediSearch, etc.
Apache License 2.0
2.34k stars 149 forks source link

Get the node address of an executed command in cluster mode #624

Open longxice opened 2 weeks ago

longxice commented 2 weeks ago

Hi all,

I would like to use the node address for metrics. That helps to identify which commands are sent to a node in the cluster. However, I don't sure the way to get it.

I intend to get the node address of the executed command as follows: Step 1: Get the key slot by calling cmd.Slot(). Step 2: Use reflection to call clusterClient._pick(...).

However, after executing the command, there may be a hash slot change caused by Redis failover.

Could you point out the correct way?

rueian commented 2 weeks ago

Hi @longxice,

Unfortunately, getting the exact address is impossible currently. Unless we expend the CommandSlice struct https://github.com/redis/rueidis/blob/9a347d752902b16afe2fda0c327fdbee732b3919/internal/cmds/builder.go#L16-L20 and inject destination into the it from here https://github.com/redis/rueidis/blob/9a347d752902b16afe2fda0c327fdbee732b3919/mux.go#L54

rueian commented 2 weeks ago

But we also need to consider if there is a notable performance impact due to the changes.

longxice commented 1 week ago

Hi @rueian

Thank you for your response.

I hope this feature will be released soon.

Thank you.

rueian commented 4 days ago

Yes, but we don’t have an ETA for this. This could have great impact in terms of performance. I currently have no idea how big it could be.

Also this may related ro https://github.com/redis/rueidis/issues/454.