setupClusterQueryParams converts query parameters in u to option value in o.
(u *url.URL, o *ClusterOptions)
| 357 | |
| 358 | // setupClusterQueryParams converts query parameters in u to option value in o. |
| 359 | func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, error) { |
| 360 | q := queryOptions{q: u.Query()} |
| 361 | |
| 362 | o.Protocol = q.int("protocol") |
| 363 | o.ClientName = q.string("client_name") |
| 364 | o.MaxRedirects = q.int("max_redirects") |
| 365 | o.ReadOnly = q.bool("read_only") |
| 366 | o.RouteByLatency = q.bool("route_by_latency") |
| 367 | o.RouteRandomly = q.bool("route_randomly") |
| 368 | o.MaxRetries = q.int("max_retries") |
| 369 | o.MinRetryBackoff = q.duration("min_retry_backoff") |
| 370 | o.MaxRetryBackoff = q.duration("max_retry_backoff") |
| 371 | o.DialTimeout = q.duration("dial_timeout") |
| 372 | o.DialerRetries = q.int("dialer_retries") |
| 373 | o.DialerRetryTimeout = q.duration("dialer_retry_timeout") |
| 374 | o.ReadTimeout = q.duration("read_timeout") |
| 375 | o.WriteTimeout = q.duration("write_timeout") |
| 376 | o.PoolFIFO = q.bool("pool_fifo") |
| 377 | o.PoolSize = q.int("pool_size") |
| 378 | o.MaxConcurrentDials = q.int("max_concurrent_dials") |
| 379 | o.MinIdleConns = q.int("min_idle_conns") |
| 380 | o.MaxIdleConns = q.int("max_idle_conns") |
| 381 | o.MaxActiveConns = q.int("max_active_conns") |
| 382 | o.PoolTimeout = q.duration("pool_timeout") |
| 383 | o.ConnMaxLifetime = q.duration("conn_max_lifetime") |
| 384 | if q.has("conn_max_lifetime_jitter") { |
| 385 | o.ConnMaxLifetimeJitter = min(q.duration("conn_max_lifetime_jitter"), o.ConnMaxLifetime) |
| 386 | } |
| 387 | o.ConnMaxIdleTime = q.duration("conn_max_idle_time") |
| 388 | o.FailingTimeoutSeconds = q.int("failing_timeout_seconds") |
| 389 | |
| 390 | if q.err != nil { |
| 391 | return nil, q.err |
| 392 | } |
| 393 | |
| 394 | // addr can be specified as many times as needed |
| 395 | addrs := q.strings("addr") |
| 396 | for _, addr := range addrs { |
| 397 | h, p, err := net.SplitHostPort(addr) |
| 398 | if err != nil || h == "" || p == "" { |
| 399 | return nil, fmt.Errorf("redis: unable to parse addr param: %s", addr) |
| 400 | } |
| 401 | |
| 402 | o.Addrs = append(o.Addrs, net.JoinHostPort(h, p)) |
| 403 | } |
| 404 | |
| 405 | // any parameters left? |
| 406 | if r := q.remaining(); len(r) > 0 { |
| 407 | return nil, fmt.Errorf("redis: unexpected option: %s", strings.Join(r, ", ")) |
| 408 | } |
| 409 | |
| 410 | return o, nil |
| 411 | } |
| 412 | |
| 413 | func (opt *ClusterOptions) clientOptions() *Options { |
| 414 | // Clone MaintNotificationsConfig to avoid sharing between cluster node clients |