Description
Good day!
Is there any option to set the closing callback for a node client in ClusterClient?
Use Case
I want to start metrics collection process on every new node client creation and stop it when the node client is removed for some reason. To stop the process I have to provide a callback somehow. To start the process I can use ClusterClient.OnNewNode
.
Ideas
One solution that comes to my mind is to add a callback to the return function that the ClusterClient.OnNewNode
accepts:
func (c *ClusterClient) OnNewNode(fn func(rdb *Client) func()) {
...
}
This callback should be added to the clusterNode
and called inside it's Close
method.
However, to avoid breaking backward compatibility, it's possible to add a separate method for ClusterClient
, such as OnNewNodeWithClose
.
Another idea is to expand the redis.Hook
interface to provide additional CloseHook
method.
Thanks for any feedback in advance.