mirror of https://github.com/go-redis/redis.git
parent
3227091087
commit
97e6ed8178
9
ring.go
9
ring.go
|
@ -361,7 +361,8 @@ func NewRing(opt *RingOptions) *Ring {
|
||||||
|
|
||||||
ring.process = ring.defaultProcess
|
ring.process = ring.defaultProcess
|
||||||
ring.processPipeline = ring.defaultProcessPipeline
|
ring.processPipeline = ring.defaultProcessPipeline
|
||||||
ring.cmdable.setProcessor(ring.Process)
|
|
||||||
|
ring.init()
|
||||||
|
|
||||||
for name, addr := range opt.Addrs {
|
for name, addr := range opt.Addrs {
|
||||||
clopt := opt.clientOptions()
|
clopt := opt.clientOptions()
|
||||||
|
@ -374,6 +375,10 @@ func NewRing(opt *RingOptions) *Ring {
|
||||||
return ring
|
return ring
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Ring) init() {
|
||||||
|
c.cmdable.setProcessor(c.Process)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Ring) Context() context.Context {
|
func (c *Ring) Context() context.Context {
|
||||||
if c.ctx != nil {
|
if c.ctx != nil {
|
||||||
return c.ctx
|
return c.ctx
|
||||||
|
@ -392,6 +397,8 @@ func (c *Ring) WithContext(ctx context.Context) *Ring {
|
||||||
|
|
||||||
func (c *Ring) clone() *Ring {
|
func (c *Ring) clone() *Ring {
|
||||||
cp := *c
|
cp := *c
|
||||||
|
cp.init()
|
||||||
|
|
||||||
return &cp
|
return &cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
ring_test.go
22
ring_test.go
|
@ -1,6 +1,7 @@
|
||||||
package redis_test
|
package redis_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
@ -104,6 +105,27 @@ var _ = Describe("Redis Ring", func() {
|
||||||
Expect(ringShard2.Info("keyspace").Val()).To(ContainSubstring("keys=100"))
|
Expect(ringShard2.Info("keyspace").Val()).To(ContainSubstring("keys=100"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("propagates process for WithContext", func() {
|
||||||
|
var fromWrap []string
|
||||||
|
wrapper := func(oldProcess func(cmd redis.Cmder) error) func(cmd redis.Cmder) error {
|
||||||
|
return func(cmd redis.Cmder) error {
|
||||||
|
fromWrap = append(fromWrap, cmd.Name())
|
||||||
|
|
||||||
|
return oldProcess(cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
ring = ring.WithContext(ctx)
|
||||||
|
ring.WrapProcess(wrapper)
|
||||||
|
|
||||||
|
ring.Ping()
|
||||||
|
Expect(fromWrap).To(Equal([]string{"ping"}))
|
||||||
|
|
||||||
|
ring.Ping()
|
||||||
|
Expect(fromWrap).To(Equal([]string{"ping", "ping"}))
|
||||||
|
})
|
||||||
|
|
||||||
Describe("pipeline", func() {
|
Describe("pipeline", func() {
|
||||||
It("distributes keys", func() {
|
It("distributes keys", func() {
|
||||||
pipe := ring.Pipeline()
|
pipe := ring.Pipeline()
|
||||||
|
|
Loading…
Reference in New Issue