mirror of https://github.com/go-redis/redis.git
Improve docs
This commit is contained in:
parent
da8ef0efa6
commit
ee41b90923
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue