valkey-io / valkey-go

A fast Golang Valkey client that supports Client Side Caching and Auto Pipelining.
Apache License 2.0
157 stars 10 forks source link

Client-Side Sharding support #17

Closed duanhongyi closed 4 hours ago

duanhongyi commented 3 days 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,
    })
rueian commented 3 days ago

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.