Merge pull request #908 from go-redis/fix/redis-cluster-fixes

Fix corner cases and a bug
This commit is contained in:
Vladimir Mihailenco 2018-11-21 12:26:15 +02:00 committed by GitHub
commit 78a66f0e5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 5 deletions

View File

@ -3,6 +3,8 @@ all: testdeps
go test ./... -short -race go test ./... -short -race
env GOOS=linux GOARCH=386 go test ./... env GOOS=linux GOARCH=386 go test ./...
go vet go vet
go get github.com/gordonklaus/ineffassign
ineffassign .
testdeps: testdata/redis/src/redis-server testdeps: testdata/redis/src/redis-server

View File

@ -533,10 +533,12 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
n := rand.Intn(len(nodes)-1) + 1 n := rand.Intn(len(nodes)-1) + 1
slave = nodes[n] slave = nodes[n]
if !slave.Loading() { if !slave.Loading() {
break return slave, nil
} }
} }
return slave, nil
// All slaves are loading - use master.
return nodes[0], nil
} }
} }
@ -979,9 +981,10 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
break break
} }
// If slave is loading - read from master. // If slave is loading - pick another node.
if c.opt.ReadOnly && internal.IsLoadingError(err) { if c.opt.ReadOnly && internal.IsLoadingError(err) {
node.MarkAsLoading() node.MarkAsLoading()
node = nil
continue continue
} }

View File

@ -1447,6 +1447,7 @@ type XReadGroupArgs struct {
Streams []string Streams []string
Count int64 Count int64
Block time.Duration Block time.Duration
NoAck bool
} }
func (c *cmdable) XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd { func (c *cmdable) XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd {
@ -1458,6 +1459,9 @@ func (c *cmdable) XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd {
if a.Block >= 0 { if a.Block >= 0 {
args = append(args, "block", int64(a.Block/time.Millisecond)) args = append(args, "block", int64(a.Block/time.Millisecond))
} }
if a.NoAck {
args = append(args, "noack")
}
args = append(args, "streams") args = append(args, "streams")
for _, s := range a.Streams { for _, s := range a.Streams {
args = append(args, s) args = append(args, s)

View File

@ -69,7 +69,7 @@ var _ = Describe("Commands", func() {
val, err := client.Wait(1, wait).Result() val, err := client.Wait(1, wait).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal(int64(0))) Expect(val).To(Equal(int64(0)))
Expect(time.Now()).To(BeTemporally("~", start.Add(wait), time.Second)) Expect(time.Now()).To(BeTemporally("~", start.Add(wait), 3*time.Second))
}) })
It("should Select", func() { It("should Select", func() {
@ -2793,10 +2793,13 @@ var _ = Describe("Commands", func() {
Member: "one", Member: "one",
}).Err() }).Err()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = client.ZAdd("zset", redis.Z{ err = client.ZAdd("zset", redis.Z{
Score: 2, Score: 2,
Member: "two", Member: "two",
}).Err() }).Err()
Expect(err).NotTo(HaveOccurred())
members, err = client.ZPopMin("zset", 10).Result() members, err = client.ZPopMin("zset", 10).Result()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(members).To(Equal([]redis.Z{{ Expect(members).To(Equal([]redis.Z{{
@ -3541,8 +3544,9 @@ var _ = Describe("Commands", func() {
res, err := client.XReadGroup(&redis.XReadGroupArgs{ res, err := client.XReadGroup(&redis.XReadGroupArgs{
Group: "group", Group: "group",
Consumer: "consumer", Consumer: "consumer",
Streams: []string{"stream", "0"}, Streams: []string{"stream", ">"},
}).Result() }).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res).To(Equal([]redis.XStream{{ Expect(res).To(Equal([]redis.XStream{{
Stream: "stream", Stream: "stream",
Messages: []redis.XMessage{ Messages: []redis.XMessage{