diff --git a/cluster.go b/cluster.go index d584423..982dff4 100644 --- a/cluster.go +++ b/cluster.go @@ -42,9 +42,11 @@ type ClusterOptions struct { // It automatically enables ReadOnly. RouteRandomly bool - // Optional function that is used to load cluster slots information. + // Optional function that returns cluster slots information. // It is useful to manually create cluster of standalone Redis servers - // or load-balance read/write operations between master and slaves. + // and load-balance read/write operations between master and slaves. + // It can use service like ZooKeeper to maintain configuration information + // and Cluster.ReloadState to manually trigger state reloading. ClusterSlots func() ([]ClusterSlot, error) // Following options are copied from Options struct. @@ -676,7 +678,8 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient { return c } -// ReloadState loads cluster slots information to update cluster topography. +// ReloadState reloads cluster state. It calls ClusterSlots func +// to get cluster slots information. func (c *ClusterClient) ReloadState() error { _, err := c.state.Reload() return err diff --git a/example_test.go b/example_test.go index eb2bb95..2206e7f 100644 --- a/example_test.go +++ b/example_test.go @@ -74,7 +74,10 @@ func ExampleNewClusterClient() { // Following example creates a cluster from 2 master nodes and 2 slave nodes // without using cluster mode or Redis Sentinel. func ExampleNewClusterClient_manualSetup() { - loadClusterSlots := func() ([]redis.ClusterSlot, error) { + // clusterSlots returns cluster slots information. + // It can use service like ZooKeeper to maintain configuration information + // and Cluster.ReloadState to manually trigger state reloading. + clusterSlots := func() ([]redis.ClusterSlot, error) { slots := []redis.ClusterSlot{ // First node with 1 master and 1 slave. { @@ -101,12 +104,13 @@ func ExampleNewClusterClient_manualSetup() { } client := redis.NewClusterClient(&redis.ClusterOptions{ - ClusterSlots: loadClusterSlots, + ClusterSlots: clusterSlots, RouteRandomly: true, }) client.Ping() - // ReloadState can be used to update cluster topography. + // ReloadState reloads cluster state. It calls ClusterSlots func + // to get cluster slots information. err := client.ReloadState() if err != nil { panic(err)