Improve docs

This commit is contained in:
Vladimir Mihailenco 2018-07-18 15:28:51 +03:00
parent da8ef0efa6
commit ee41b90923
2 changed files with 13 additions and 6 deletions

View File

@ -42,9 +42,11 @@ type ClusterOptions struct {
// It automatically enables ReadOnly. // It automatically enables ReadOnly.
RouteRandomly bool 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 // 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) ClusterSlots func() ([]ClusterSlot, error)
// Following options are copied from Options struct. // Following options are copied from Options struct.
@ -676,7 +678,8 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
return c 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 { func (c *ClusterClient) ReloadState() error {
_, err := c.state.Reload() _, err := c.state.Reload()
return err return err

View File

@ -74,7 +74,10 @@ func ExampleNewClusterClient() {
// Following example creates a cluster from 2 master nodes and 2 slave nodes // Following example creates a cluster from 2 master nodes and 2 slave nodes
// without using cluster mode or Redis Sentinel. // without using cluster mode or Redis Sentinel.
func ExampleNewClusterClient_manualSetup() { 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{ slots := []redis.ClusterSlot{
// First node with 1 master and 1 slave. // First node with 1 master and 1 slave.
{ {
@ -101,12 +104,13 @@ func ExampleNewClusterClient_manualSetup() {
} }
client := redis.NewClusterClient(&redis.ClusterOptions{ client := redis.NewClusterClient(&redis.ClusterOptions{
ClusterSlots: loadClusterSlots, ClusterSlots: clusterSlots,
RouteRandomly: true, RouteRandomly: true,
}) })
client.Ping() 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() err := client.ReloadState()
if err != nil { if err != nil {
panic(err) panic(err)