1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-02 06:22:31 +03:00
This commit is contained in:
Nedyalko Dyakov
2025-11-20 11:01:57 +02:00
parent 9b7f1be092
commit 212095540d
2 changed files with 144 additions and 61 deletions

View File

@@ -1037,7 +1037,6 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
pipeline: c.processPipeline,
txPipeline: c.processTxPipeline,
})
return c
}
@@ -1046,6 +1045,24 @@ func (c *ClusterClient) Options() *ClusterOptions {
return c.opt
}
// AddHook adds a hook to the client.
func (c *ClusterClient) AddHook(h Hook) {
// Add hook only to nodes, not to the cluster client itself.
// This prevents hooks from being called twice (once at cluster level, once at node level).
// The cluster client delegates all commands to nodes, so hooks on nodes will be called.
if err := c.ForEachShard(context.Background(), func(ctx context.Context, node *Client) error {
node.AddHook(h)
return nil
}); err != nil {
return
}
c.nodes.OnNewNode(func(rdb *Client) {
rdb.AddHook(h)
})
}
// ReloadState reloads cluster state. If available it calls ClusterSlots func
// to get cluster slots information.
func (c *ClusterClient) ReloadState(ctx context.Context) {