rueidis icon indicating copy to clipboard operation
rueidis copied to clipboard

Get the node address of an executed command in cluster mode

Open longxice opened this issue 1 year ago • 4 comments

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?

longxice avatar Aug 29 '24 23:08 longxice

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 avatar Aug 30 '24 00:08 rueian

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

rueian avatar Aug 30 '24 00:08 rueian

Hi @rueian

Thank you for your response.

I hope this feature will be released soon.

Thank you.

longxice avatar Sep 09 '24 05:09 longxice

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.

rueian avatar Sep 11 '24 11:09 rueian