mirror of
https://github.com/redis/go-redis.git
synced 2025-05-31 21:01:13 +03:00
Merge branch 'master' into ndyakov/ai-generated-docs
This commit is contained in:
commit
4b982054d9
@ -924,6 +924,9 @@ type ClusterClient struct {
|
||||
// NewClusterClient returns a Redis Cluster client as described in
|
||||
// http://redis.io/topics/cluster-spec.
|
||||
func NewClusterClient(opt *ClusterOptions) *ClusterClient {
|
||||
if opt == nil {
|
||||
panic("redis: NewClusterClient nil options")
|
||||
}
|
||||
opt.init()
|
||||
|
||||
c := &ClusterClient{
|
||||
|
3
redis.go
3
redis.go
@ -661,6 +661,9 @@ type Client struct {
|
||||
|
||||
// NewClient returns a client to the Redis Server specified by Options.
|
||||
func NewClient(opt *Options) *Client {
|
||||
if opt == nil {
|
||||
panic("redis: NewClient nil options")
|
||||
}
|
||||
opt.init()
|
||||
|
||||
c := Client{
|
||||
|
@ -727,3 +727,54 @@ var _ = Describe("Dialer connection timeouts", func() {
|
||||
Expect(time.Since(start)).To(BeNumerically("<", 2*dialSimulatedDelay))
|
||||
})
|
||||
})
|
||||
var _ = Describe("Client creation", func() {
|
||||
Context("simple client with nil options", func() {
|
||||
It("panics", func() {
|
||||
Expect(func() {
|
||||
redis.NewClient(nil)
|
||||
}).To(Panic())
|
||||
})
|
||||
})
|
||||
Context("cluster client with nil options", func() {
|
||||
It("panics", func() {
|
||||
Expect(func() {
|
||||
redis.NewClusterClient(nil)
|
||||
}).To(Panic())
|
||||
})
|
||||
})
|
||||
Context("ring client with nil options", func() {
|
||||
It("panics", func() {
|
||||
Expect(func() {
|
||||
redis.NewRing(nil)
|
||||
}).To(Panic())
|
||||
})
|
||||
})
|
||||
Context("universal client with nil options", func() {
|
||||
It("panics", func() {
|
||||
Expect(func() {
|
||||
redis.NewUniversalClient(nil)
|
||||
}).To(Panic())
|
||||
})
|
||||
})
|
||||
Context("failover client with nil options", func() {
|
||||
It("panics", func() {
|
||||
Expect(func() {
|
||||
redis.NewFailoverClient(nil)
|
||||
}).To(Panic())
|
||||
})
|
||||
})
|
||||
Context("failover cluster client with nil options", func() {
|
||||
It("panics", func() {
|
||||
Expect(func() {
|
||||
redis.NewFailoverClusterClient(nil)
|
||||
}).To(Panic())
|
||||
})
|
||||
})
|
||||
Context("sentinel client with nil options", func() {
|
||||
It("panics", func() {
|
||||
Expect(func() {
|
||||
redis.NewSentinelClient(nil)
|
||||
}).To(Panic())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
3
ring.go
3
ring.go
@ -523,6 +523,9 @@ type Ring struct {
|
||||
}
|
||||
|
||||
func NewRing(opt *RingOptions) *Ring {
|
||||
if opt == nil {
|
||||
panic("redis: NewRing nil options")
|
||||
}
|
||||
opt.init()
|
||||
|
||||
hbCtx, hbCancel := context.WithCancel(context.Background())
|
||||
|
11
sentinel.go
11
sentinel.go
@ -224,6 +224,10 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
|
||||
// for automatic failover. It's safe for concurrent use by multiple
|
||||
// goroutines.
|
||||
func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
|
||||
if failoverOpt == nil {
|
||||
panic("redis: NewFailoverClient nil options")
|
||||
}
|
||||
|
||||
if failoverOpt.RouteByLatency {
|
||||
panic("to route commands by latency, use NewFailoverClusterClient")
|
||||
}
|
||||
@ -313,6 +317,9 @@ type SentinelClient struct {
|
||||
}
|
||||
|
||||
func NewSentinelClient(opt *Options) *SentinelClient {
|
||||
if opt == nil {
|
||||
panic("redis: NewSentinelClient nil options")
|
||||
}
|
||||
opt.init()
|
||||
c := &SentinelClient{
|
||||
baseClient: &baseClient{
|
||||
@ -828,6 +835,10 @@ func contains(slice []string, str string) bool {
|
||||
// NewFailoverClusterClient returns a client that supports routing read-only commands
|
||||
// to a replica node.
|
||||
func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
|
||||
if failoverOpt == nil {
|
||||
panic("redis: NewFailoverClusterClient nil options")
|
||||
}
|
||||
|
||||
sentinelAddrs := make([]string, len(failoverOpt.SentinelAddrs))
|
||||
copy(sentinelAddrs, failoverOpt.SentinelAddrs)
|
||||
|
||||
|
@ -267,6 +267,10 @@ var (
|
||||
// a ClusterClient is returned.
|
||||
// 4. Otherwise, a single-node Client is returned.
|
||||
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
|
||||
if opts == nil {
|
||||
panic("redis: NewUniversalClient nil options")
|
||||
}
|
||||
|
||||
switch {
|
||||
case opts.MasterName != "" && (opts.RouteByLatency || opts.RouteRandomly || opts.IsClusterMode):
|
||||
return NewFailoverClusterClient(opts.Failover())
|
||||
|
Loading…
x
Reference in New Issue
Block a user