File tree Expand file tree Collapse file tree 6 files changed +75
-0
lines changed Expand file tree Collapse file tree 6 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -933,6 +933,9 @@ type ClusterClient struct {
933933// NewClusterClient returns a Redis Cluster client as described in
934934// http://redis.io/topics/cluster-spec.
935935func NewClusterClient (opt * ClusterOptions ) * ClusterClient {
936+ if opt == nil {
937+ panic ("redis: NewClusterClient nil options" )
938+ }
936939 opt .init ()
937940
938941 c := & ClusterClient {
Original file line number Diff line number Diff line change @@ -661,6 +661,9 @@ type Client struct {
661661
662662// NewClient returns a client to the Redis Server specified by Options.
663663func NewClient (opt * Options ) * Client {
664+ if opt == nil {
665+ panic ("redis: NewClient nil options" )
666+ }
664667 opt .init ()
665668
666669 c := Client {
Original file line number Diff line number Diff line change @@ -727,3 +727,54 @@ var _ = Describe("Dialer connection timeouts", func() {
727727 Expect (time .Since (start )).To (BeNumerically ("<" , 2 * dialSimulatedDelay ))
728728 })
729729})
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 {
523523}
524524
525525func NewRing (opt * RingOptions ) * Ring {
526+ if opt == nil {
527+ panic ("redis: NewRing nil options" )
528+ }
526529 opt .init ()
527530
528531 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 {
224224// for automatic failover. It's safe for concurrent use by multiple
225225// goroutines.
226226func NewFailoverClient (failoverOpt * FailoverOptions ) * Client {
227+ if failoverOpt == nil {
228+ panic ("redis: NewFailoverClient nil options" )
229+ }
230+
227231 if failoverOpt .RouteByLatency {
228232 panic ("to route commands by latency, use NewFailoverClusterClient" )
229233 }
@@ -313,6 +317,9 @@ type SentinelClient struct {
313317}
314318
315319func NewSentinelClient (opt * Options ) * SentinelClient {
320+ if opt == nil {
321+ panic ("redis: NewSentinelClient nil options" )
322+ }
316323 opt .init ()
317324 c := & SentinelClient {
318325 baseClient : & baseClient {
@@ -828,6 +835,10 @@ func contains(slice []string, str string) bool {
828835// NewFailoverClusterClient returns a client that supports routing read-only commands
829836// to a replica node.
830837func NewFailoverClusterClient (failoverOpt * FailoverOptions ) * ClusterClient {
838+ if failoverOpt == nil {
839+ panic ("redis: NewFailoverClusterClient nil options" )
840+ }
841+
831842 sentinelAddrs := make ([]string , len (failoverOpt .SentinelAddrs ))
832843 copy (sentinelAddrs , failoverOpt .SentinelAddrs )
833844
Original file line number Diff line number Diff line change @@ -267,6 +267,10 @@ var (
267267// a ClusterClient is returned.
268268// 4. Otherwise, a single-node Client is returned.
269269func NewUniversalClient (opts * UniversalOptions ) UniversalClient {
270+ if opts == nil {
271+ panic ("redis: NewUniversalClient nil options" )
272+ }
273+
270274 switch {
271275 case opts .MasterName != "" && (opts .RouteByLatency || opts .RouteRandomly || opts .IsClusterMode ):
272276 return NewFailoverClusterClient (opts .Failover ())
You can’t perform that action at this time.
0 commit comments