NewClusterClient returns a Redis Cluster client as described in https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec. Passing nil ClusterOptions will cause a panic.
(opt *ClusterOptions)
| 1159 | // https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec. |
| 1160 | // Passing nil ClusterOptions will cause a panic. |
| 1161 | func NewClusterClient(opt *ClusterOptions) *ClusterClient { |
| 1162 | if opt == nil { |
| 1163 | panic("redis: NewClusterClient nil options") |
| 1164 | } |
| 1165 | opt.init() |
| 1166 | |
| 1167 | c := &ClusterClient{ |
| 1168 | opt: opt, |
| 1169 | nodes: newClusterNodes(opt), |
| 1170 | } |
| 1171 | |
| 1172 | c.cmdsInfoCache = newCmdsInfoCache(c.cmdsInfo) |
| 1173 | |
| 1174 | c.state = newClusterStateHolder(c.loadState, opt.ClusterStateReloadInterval) |
| 1175 | |
| 1176 | c.SetCommandInfoResolver(NewDefaultCommandPolicyResolver()) |
| 1177 | |
| 1178 | c.cmdable = c.Process |
| 1179 | c.initHooks(hooks{ |
| 1180 | dial: nil, |
| 1181 | process: c.process, |
| 1182 | pipeline: c.processPipeline, |
| 1183 | txPipeline: c.processTxPipeline, |
| 1184 | }) |
| 1185 | |
| 1186 | // Set up SMIGRATED notification handling for cluster state reload |
| 1187 | // When a node client receives a SMIGRATED notification, it should trigger |
| 1188 | // cluster state reload on the parent ClusterClient |
| 1189 | if opt.MaintNotificationsConfig != nil { |
| 1190 | c.nodes.OnNewNode(func(nodeClient *Client) { |
| 1191 | manager := nodeClient.GetMaintNotificationsManager() |
| 1192 | if manager != nil { |
| 1193 | manager.SetClusterStateReloadCallback(func(ctx context.Context, hostPort string, slotRanges []string) { |
| 1194 | // Log the migration details for now |
| 1195 | if internal.LogLevel.InfoOrAbove() { |
| 1196 | internal.Logger.Printf(ctx, "cluster: slots %v migrated to %s, reloading cluster state", slotRanges, hostPort) |
| 1197 | } |
| 1198 | // Currently we reload the entire cluster state |
| 1199 | // In the future, this could be optimized to reload only the specific slots |
| 1200 | c.state.LazyReload() |
| 1201 | }) |
| 1202 | } |
| 1203 | }) |
| 1204 | } |
| 1205 | |
| 1206 | return c |
| 1207 | } |
| 1208 | |
| 1209 | // Options returns read-only *ClusterOptions that were used to create the client. |
| 1210 | // Any alteration of the returned *ClusterOptions may result in undefined behaviour. |
no test coverage detected