Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Jul 18, 2018
1 parent da8ef0e commit ee41b90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
{
Expand All @@ -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)
Expand Down

0 comments on commit ee41b90

Please sign in to comment.