MCPcopy
hub / github.com/redis/go-redis / ExampleNewClusterClient_manualSetup

Function ExampleNewClusterClient_manualSetup

example_test.go:81–120  ·  view source on GitHub ↗

Following example creates a cluster from 2 master nodes and 2 slave nodes without using cluster mode or Redis Sentinel.

()

Source from the content-addressed store, hash-verified

79// Following example creates a cluster from 2 master nodes and 2 slave nodes
80// without using cluster mode or Redis Sentinel.
81func ExampleNewClusterClient_manualSetup() {
82 // clusterSlots returns cluster slots information.
83 // It can use service like ZooKeeper to maintain configuration information
84 // and Cluster.ReloadState to manually trigger state reloading.
85 clusterSlots := func(ctx context.Context) ([]redis.ClusterSlot, error) {
86 slots := []redis.ClusterSlot{
87 // First node with 1 master and 1 slave.
88 {
89 Start: 0,
90 End: 8191,
91 Nodes: []redis.ClusterNode{{
92 Addr: ":7000", // master
93 }, {
94 Addr: ":8000", // 1st slave
95 }},
96 },
97 // Second node with 1 master and 1 slave.
98 {
99 Start: 8192,
100 End: 16383,
101 Nodes: []redis.ClusterNode{{
102 Addr: ":7001", // master
103 }, {
104 Addr: ":8001", // 1st slave
105 }},
106 },
107 }
108 return slots, nil
109 }
110
111 rdb := redis.NewClusterClient(&redis.ClusterOptions{
112 ClusterSlots: clusterSlots,
113 RouteRandomly: true,
114 })
115 rdb.Ping(ctx)
116
117 // ReloadState reloads cluster state. It calls ClusterSlots func
118 // to get cluster slots information.
119 rdb.ReloadState(ctx)
120}
121
122func ExampleNewRing() {
123 rdb := redis.NewRing(&redis.RingOptions{

Callers

nothing calls this directly

Calls 2

ReloadStateMethod · 0.95
PingMethod · 0.65

Tested by

no test coverage detected