Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for internal/kvs/redis/option.go #611

Merged
merged 4 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions internal/db/kvs/redis/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/vdaas/vald/internal/timeutil"
)

// Option represents the functional option for redisClient.
type Option func(*redisClient) error

var (
Expand All @@ -36,6 +37,7 @@ var (
}
)

// WithDialer returns the option to set the dialer.
func WithDialer(der func(ctx context.Context, addr, port string) (net.Conn, error)) Option {
return func(r *redisClient) error {
if der != nil {
Expand All @@ -45,6 +47,7 @@ func WithDialer(der func(ctx context.Context, addr, port string) (net.Conn, erro
}
}

// WithAddrs returns the option to set the addrs.
func WithAddrs(addrs ...string) Option {
return func(r *redisClient) error {
if len(addrs) == 0 {
Expand All @@ -59,13 +62,15 @@ func WithAddrs(addrs ...string) Option {
}
}

// WithDB returns the option to set the db.
func WithDB(db int) Option {
return func(r *redisClient) error {
r.db = db
return nil
}
}

// WithClusterSlots returns the option to set the clusterSlots.
func WithClusterSlots(f func() ([]redis.ClusterSlot, error)) Option {
return func(r *redisClient) error {
if f != nil {
Expand All @@ -75,6 +80,7 @@ func WithClusterSlots(f func() ([]redis.ClusterSlot, error)) Option {
}
}

// WithDialTimeout returns the option to set the dialTimeout.
func WithDialTimeout(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -89,6 +95,7 @@ func WithDialTimeout(dur string) Option {
}
}

// WithIdleCheckFrequency returns the option to set the idleCheckFrequency.
func WithIdleCheckFrequency(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -103,6 +110,7 @@ func WithIdleCheckFrequency(dur string) Option {
}
}

// WithIdleTimeout returns the option to set the idleTimeout.
func WithIdleTimeout(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -117,6 +125,7 @@ func WithIdleTimeout(dur string) Option {
}
}

// WithKeyPrefix returns the option to set the keyPref.
func WithKeyPrefix(prefix string) Option {
return func(r *redisClient) error {
if prefix != "" {
Expand All @@ -126,6 +135,7 @@ func WithKeyPrefix(prefix string) Option {
}
}

// WithMaximumConnectionAge returns the option to set the maxConnAge.
func WithMaximumConnectionAge(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -140,20 +150,23 @@ func WithMaximumConnectionAge(dur string) Option {
}
}

// WithRedirectLimit returns the option to set the maxRedirects.
func WithRedirectLimit(maxRedirects int) Option {
return func(r *redisClient) error {
r.maxRedirects = maxRedirects
return nil
}
}

// WithRetryLimit returns the option to set the maxRetries.
func WithRetryLimit(maxRetries int) Option {
return func(r *redisClient) error {
r.maxRetries = maxRetries
return nil
}
}

// WithMaximumRetryBackoff returns the option to set the maxRetryBackoff.
func WithMaximumRetryBackoff(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -168,13 +181,15 @@ func WithMaximumRetryBackoff(dur string) Option {
}
}

// WithMinimumIdleConnection returns the option to set the minIdleConns.
func WithMinimumIdleConnection(minIdleConns int) Option {
return func(r *redisClient) error {
r.minIdleConns = minIdleConns
return nil
}
}

// WithMinimumRetryBackoff returns the option to set the minRetryBackoff.
func WithMinimumRetryBackoff(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -189,6 +204,7 @@ func WithMinimumRetryBackoff(dur string) Option {
}
}

// WithOnConnectFunction returns the option to set the onConnect.
func WithOnConnectFunction(f func(*redis.Conn) error) Option {
return func(r *redisClient) error {
if f != nil {
Expand All @@ -198,6 +214,7 @@ func WithOnConnectFunction(f func(*redis.Conn) error) Option {
}
}

// WithOnNewNodeFunction returns the option to set the onNewNode.
func WithOnNewNodeFunction(f func(*redis.Client)) Option {
return func(r *redisClient) error {
if f != nil {
Expand All @@ -207,6 +224,7 @@ func WithOnNewNodeFunction(f func(*redis.Client)) Option {
}
}

// WithPassword returns the option to set the password.
func WithPassword(password string) Option {
return func(r *redisClient) error {
if password != "" {
Expand All @@ -216,13 +234,15 @@ func WithPassword(password string) Option {
}
}

// WithPoolSize returns the option to set the poolSize.
func WithPoolSize(poolSize int) Option {
return func(r *redisClient) error {
r.poolSize = poolSize
return nil
}
}

// WithPoolTimeout returns the option to set the poolTimeout.
func WithPoolTimeout(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -237,13 +257,15 @@ func WithPoolTimeout(dur string) Option {
}
}

// WithReadOnlyFlag returns the option to set the readOnly.
func WithReadOnlyFlag(readOnly bool) Option {
return func(r *redisClient) error {
r.readOnly = readOnly
return nil
}
}

// WithReadTimeout returns the option to set the readTimeout.
func WithReadTimeout(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -258,20 +280,23 @@ func WithReadTimeout(dur string) Option {
}
}

// WithRouteByLatencyFlag returns the option to set the routeByLatency.
func WithRouteByLatencyFlag(routeByLatency bool) Option {
return func(r *redisClient) error {
r.routeByLatency = routeByLatency
return nil
}
}

// WithRouteRandomlyFlag returns the option to set the routeRandomly.
func WithRouteRandomlyFlag(routeRandomly bool) Option {
return func(r *redisClient) error {
r.routeRandomly = routeRandomly
return nil
}
}

// WithTLSConfig returns the option to set the tlsConfig.
func WithTLSConfig(cfg *tls.Config) Option {
return func(r *redisClient) error {
if cfg != nil {
Expand All @@ -281,6 +306,7 @@ func WithTLSConfig(cfg *tls.Config) Option {
}
}

// WithWriteTimeout returns the option to set the writeTimeout.
func WithWriteTimeout(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand All @@ -295,6 +321,7 @@ func WithWriteTimeout(dur string) Option {
}
}

// WithInitialPingTimeLimit returns the option to set the initialPingTimeLimit.
func WithInitialPingTimeLimit(lim string) Option {
return func(r *redisClient) error {
if lim == "" {
Expand All @@ -309,6 +336,7 @@ func WithInitialPingTimeLimit(lim string) Option {
}
}

// WithInitialPingDuration returns the option to set the initialPingDuration.
func WithInitialPingDuration(dur string) Option {
return func(r *redisClient) error {
if dur == "" {
Expand Down
Loading