mirror of
https://github.com/redis/go-redis.git
synced 2025-06-02 08:21:36 +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
|
// NewClusterClient returns a Redis Cluster client as described in
|
||||||
// http://redis.io/topics/cluster-spec.
|
// http://redis.io/topics/cluster-spec.
|
||||||
func NewClusterClient(opt *ClusterOptions) *ClusterClient {
|
func NewClusterClient(opt *ClusterOptions) *ClusterClient {
|
||||||
|
if opt == nil {
|
||||||
|
panic("redis: NewClusterClient nil options")
|
||||||
|
}
|
||||||
opt.init()
|
opt.init()
|
||||||
|
|
||||||
c := &ClusterClient{
|
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.
|
// NewClient returns a client to the Redis Server specified by Options.
|
||||||
func NewClient(opt *Options) *Client {
|
func NewClient(opt *Options) *Client {
|
||||||
|
if opt == nil {
|
||||||
|
panic("redis: NewClient nil options")
|
||||||
|
}
|
||||||
opt.init()
|
opt.init()
|
||||||
|
|
||||||
c := Client{
|
c := Client{
|
||||||
|
@ -727,3 +727,54 @@ var _ = Describe("Dialer connection timeouts", func() {
|
|||||||
Expect(time.Since(start)).To(BeNumerically("<", 2*dialSimulatedDelay))
|
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 {
|
func NewRing(opt *RingOptions) *Ring {
|
||||||
|
if opt == nil {
|
||||||
|
panic("redis: NewRing nil options")
|
||||||
|
}
|
||||||
opt.init()
|
opt.init()
|
||||||
|
|
||||||
hbCtx, hbCancel := context.WithCancel(context.Background())
|
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
|
// for automatic failover. It's safe for concurrent use by multiple
|
||||||
// goroutines.
|
// goroutines.
|
||||||
func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
|
func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
|
||||||
|
if failoverOpt == nil {
|
||||||
|
panic("redis: NewFailoverClient nil options")
|
||||||
|
}
|
||||||
|
|
||||||
if failoverOpt.RouteByLatency {
|
if failoverOpt.RouteByLatency {
|
||||||
panic("to route commands by latency, use NewFailoverClusterClient")
|
panic("to route commands by latency, use NewFailoverClusterClient")
|
||||||
}
|
}
|
||||||
@ -313,6 +317,9 @@ type SentinelClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewSentinelClient(opt *Options) *SentinelClient {
|
func NewSentinelClient(opt *Options) *SentinelClient {
|
||||||
|
if opt == nil {
|
||||||
|
panic("redis: NewSentinelClient nil options")
|
||||||
|
}
|
||||||
opt.init()
|
opt.init()
|
||||||
c := &SentinelClient{
|
c := &SentinelClient{
|
||||||
baseClient: &baseClient{
|
baseClient: &baseClient{
|
||||||
@ -828,6 +835,10 @@ func contains(slice []string, str string) bool {
|
|||||||
// NewFailoverClusterClient returns a client that supports routing read-only commands
|
// NewFailoverClusterClient returns a client that supports routing read-only commands
|
||||||
// to a replica node.
|
// to a replica node.
|
||||||
func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
|
func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient {
|
||||||
|
if failoverOpt == nil {
|
||||||
|
panic("redis: NewFailoverClusterClient nil options")
|
||||||
|
}
|
||||||
|
|
||||||
sentinelAddrs := make([]string, len(failoverOpt.SentinelAddrs))
|
sentinelAddrs := make([]string, len(failoverOpt.SentinelAddrs))
|
||||||
copy(sentinelAddrs, failoverOpt.SentinelAddrs)
|
copy(sentinelAddrs, failoverOpt.SentinelAddrs)
|
||||||
|
|
||||||
|
@ -267,6 +267,10 @@ var (
|
|||||||
// a ClusterClient is returned.
|
// a ClusterClient is returned.
|
||||||
// 4. Otherwise, a single-node Client is returned.
|
// 4. Otherwise, a single-node Client is returned.
|
||||||
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
|
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
|
||||||
|
if opts == nil {
|
||||||
|
panic("redis: NewUniversalClient nil options")
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case opts.MasterName != "" && (opts.RouteByLatency || opts.RouteRandomly || opts.IsClusterMode):
|
case opts.MasterName != "" && (opts.RouteByLatency || opts.RouteRandomly || opts.IsClusterMode):
|
||||||
return NewFailoverClusterClient(opts.Failover())
|
return NewFailoverClusterClient(opts.Failover())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user