Closed duanhongyi closed 4 hours ago
Can Redis clusters be directly supported at the client level?Refer to the following code:
redis.NewClusterClient(&redis.ClusterOptions{ ClusterSlots: func(context.Context) ([]redis.ClusterSlot, error) { const slotsSize = 16383 var size = len(addrs) var slotsRange = slotsSize / size var slots []redis.ClusterSlot for index, addr := range addrs { start := slotsRange * index end := start + slotsRange if (slotsSize - end) < slotsRange { end = slotsSize } slots = append(slots, redis.ClusterSlot{ Start: start, End: end, Nodes: []redis.ClusterNode{{Addr: addr}}, }) } return slots, nil }, Username: username, Password: password, RouteRandomly: true, })
The Client only supports clusters that can respond to CLUSTER SLOTS or CLUSTER SHARDS commands. You can't form a cluster using a client-side configuration.
CLUSTER SLOTS
CLUSTER SHARDS
Can Redis clusters be directly supported at the client level?Refer to the following code: