File tree 6 files changed +75
-0
lines changed
6 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -924,6 +924,9 @@ type ClusterClient struct {
924
924
// NewClusterClient returns a Redis Cluster client as described in
925
925
// http://redis.io/topics/cluster-spec.
926
926
func NewClusterClient (opt * ClusterOptions ) * ClusterClient {
927
+ if opt == nil {
928
+ panic ("redis: NewClusterClient nil options" )
929
+ }
927
930
opt .init ()
928
931
929
932
c := & ClusterClient {
Original file line number Diff line number Diff line change @@ -661,6 +661,9 @@ type Client struct {
661
661
662
662
// NewClient returns a client to the Redis Server specified by Options.
663
663
func NewClient (opt * Options ) * Client {
664
+ if opt == nil {
665
+ panic ("redis: NewClient nil options" )
666
+ }
664
667
opt .init ()
665
668
666
669
c := Client {
Original file line number Diff line number Diff line change @@ -727,3 +727,54 @@ var _ = Describe("Dialer connection timeouts", func() {
727
727
Expect (time .Since (start )).To (BeNumerically ("<" , 2 * dialSimulatedDelay ))
728
728
})
729
729
})
730
+ var _ = Describe ("Client creation" , func () {
731
+ Context ("simple client with nil options" , func () {
732
+ It ("panics" , func () {
733
+ Expect (func () {
734
+ redis .NewClient (nil )
735
+ }).To (Panic ())
736
+ })
737
+ })
738
+ Context ("cluster client with nil options" , func () {
739
+ It ("panics" , func () {
740
+ Expect (func () {
741
+ redis .NewClusterClient (nil )
742
+ }).To (Panic ())
743
+ })
744
+ })
745
+ Context ("ring client with nil options" , func () {
746
+ It ("panics" , func () {
747
+ Expect (func () {
748
+ redis .NewRing (nil )
749
+ }).To (Panic ())
750
+ })
751
+ })
752
+ Context ("universal client with nil options" , func () {
753
+ It ("panics" , func () {
754
+ Expect (func () {
755
+ redis .NewUniversalClient (nil )
756
+ }).To (Panic ())
757
+ })
758
+ })
759
+ Context ("failover client with nil options" , func () {
760
+ It ("panics" , func () {
761
+ Expect (func () {
762
+ redis .NewFailoverClient (nil )
763
+ }).To (Panic ())
764
+ })
765
+ })
766
+ Context ("failover cluster client with nil options" , func () {
767
+ It ("panics" , func () {
768
+ Expect (func () {
769
+ redis .NewFailoverClusterClient (nil )
770
+ }).To (Panic ())
771
+ })
772
+ })
773
+ Context ("sentinel client with nil options" , func () {
774
+ It ("panics" , func () {
775
+ Expect (func () {
776
+ redis .NewSentinelClient (nil )
777
+ }).To (Panic ())
778
+ })
779
+ })
780
+ })
Original file line number Diff line number Diff line change @@ -523,6 +523,9 @@ type Ring struct {
523
523
}
524
524
525
525
func NewRing (opt * RingOptions ) * Ring {
526
+ if opt == nil {
527
+ panic ("redis: NewRing nil options" )
528
+ }
526
529
opt .init ()
527
530
528
531
hbCtx , hbCancel := context .WithCancel (context .Background ())
Original file line number Diff line number Diff line change @@ -224,6 +224,10 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
224
224
// for automatic failover. It's safe for concurrent use by multiple
225
225
// goroutines.
226
226
func NewFailoverClient (failoverOpt * FailoverOptions ) * Client {
227
+ if failoverOpt == nil {
228
+ panic ("redis: NewFailoverClient nil options" )
229
+ }
230
+
227
231
if failoverOpt .RouteByLatency {
228
232
panic ("to route commands by latency, use NewFailoverClusterClient" )
229
233
}
@@ -313,6 +317,9 @@ type SentinelClient struct {
313
317
}
314
318
315
319
func NewSentinelClient (opt * Options ) * SentinelClient {
320
+ if opt == nil {
321
+ panic ("redis: NewSentinelClient nil options" )
322
+ }
316
323
opt .init ()
317
324
c := & SentinelClient {
318
325
baseClient : & baseClient {
@@ -828,6 +835,10 @@ func contains(slice []string, str string) bool {
828
835
// NewFailoverClusterClient returns a client that supports routing read-only commands
829
836
// to a replica node.
830
837
func NewFailoverClusterClient (failoverOpt * FailoverOptions ) * ClusterClient {
838
+ if failoverOpt == nil {
839
+ panic ("redis: NewFailoverClusterClient nil options" )
840
+ }
841
+
831
842
sentinelAddrs := make ([]string , len (failoverOpt .SentinelAddrs ))
832
843
copy (sentinelAddrs , failoverOpt .SentinelAddrs )
833
844
Original file line number Diff line number Diff line change @@ -267,6 +267,10 @@ var (
267
267
// a ClusterClient is returned.
268
268
// 4. Otherwise, a single-node Client is returned.
269
269
func NewUniversalClient (opts * UniversalOptions ) UniversalClient {
270
+ if opts == nil {
271
+ panic ("redis: NewUniversalClient nil options" )
272
+ }
273
+
270
274
switch {
271
275
case opts .MasterName != "" && (opts .RouteByLatency || opts .RouteRandomly || opts .IsClusterMode ):
272
276
return NewFailoverClusterClient (opts .Failover ())
You can’t perform that action at this time.
0 commit comments