MCPcopy
hub / github.com/redis/go-redis / init

Method init

options.go:318–425  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

316}
317
318func (opt *Options) init() {
319 if opt.Addr == "" {
320 opt.Addr = "localhost:6379"
321 }
322 if opt.Network == "" {
323 if strings.HasPrefix(opt.Addr, "/") {
324 opt.Network = "unix"
325 } else {
326 opt.Network = "tcp"
327 }
328 }
329 // For standalone clients, default NodeAddress to Addr if not set.
330 // This ensures maintenance notifications (SMIGRATED, etc.) can match
331 // the connection's endpoint even for non-cluster clients.
332 if opt.NodeAddress == "" {
333 opt.NodeAddress = opt.Addr
334 }
335 if opt.Protocol < 2 {
336 opt.Protocol = 3
337 }
338 if opt.DialTimeout == 0 {
339 opt.DialTimeout = 5 * time.Second
340 }
341 if opt.DialerRetries == 0 {
342 opt.DialerRetries = 5
343 }
344 if opt.DialerRetryTimeout == 0 {
345 opt.DialerRetryTimeout = 100 * time.Millisecond
346 }
347 if opt.Dialer == nil {
348 opt.Dialer = NewDialer(opt)
349 }
350 if opt.PoolSize == 0 {
351 opt.PoolSize = 10 * runtime.GOMAXPROCS(0)
352 }
353 if opt.MaxConcurrentDials <= 0 {
354 opt.MaxConcurrentDials = opt.PoolSize
355 } else if opt.MaxConcurrentDials > opt.PoolSize {
356 opt.MaxConcurrentDials = opt.PoolSize
357 }
358 if opt.ReadBufferSize == 0 {
359 opt.ReadBufferSize = proto.DefaultBufferSize
360 }
361 if opt.WriteBufferSize == 0 {
362 opt.WriteBufferSize = proto.DefaultBufferSize
363 }
364 switch opt.ReadTimeout {
365 case -2:
366 opt.ReadTimeout = -1
367 case -1:
368 opt.ReadTimeout = 0
369 case 0:
370 opt.ReadTimeout = 3 * time.Second
371 }
372 switch opt.WriteTimeout {
373 case -2:
374 opt.WriteTimeout = -1
375 case -1:

Calls 3

DetectEndpointTypeFunction · 0.92
NewDialerFunction · 0.85