Skip to content

Commit

Permalink
refactors for readability
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <[email protected]>
  • Loading branch information
elena-kolevska committed May 27, 2024
1 parent 0c4081a commit 861fe36
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions common/component/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,16 @@ func ParseClientFromProperties(properties map[string]string, componentType metad
}

var c RedisClient
newClientFunc := newV8Client
if settings.Failover {
c, err = newV8FailoverClient(settings)
if err != nil {
return nil, nil, fmt.Errorf("redis client configuration error: %w", err)
}
} else {
c, err = newV8Client(settings)
if err != nil {
return nil, nil, fmt.Errorf("redis client configuration error: %w", err)
}
newClientFunc = newV8FailoverClient
}

c, err = newClientFunc(settings)
if err != nil {
return nil, nil, fmt.Errorf("redis client configuration error: %w", err)
}

version, versionErr := GetServerVersion(c)
c.Close() // close the client to avoid leaking connections

Expand All @@ -181,33 +180,18 @@ func ParseClientFromProperties(properties map[string]string, componentType metad
// if the server version is >= 7, we will use the v9 client
useNewClient = true
}

if useNewClient {
newClientFunc = newV9Client
if settings.Failover {
c, err = newV9FailoverClient(settings)
if err != nil {
return nil, nil, fmt.Errorf("redis client configuration error: %w", err)
}
return c, settings, nil
newClientFunc = newV9FailoverClient
}
c, err = newV9Client(settings)
if err != nil {
return nil, nil, fmt.Errorf("redis client configuration error: %w", err)
}
return c, settings, nil
} else {
if settings.Failover {
c, err = newV8FailoverClient(settings)
if err != nil {
return nil, nil, fmt.Errorf("redis client configuration error: %w", err)
}
return c, settings, nil
}
c, err = newV8Client(settings)
if err != nil {
return nil, nil, fmt.Errorf("redis client configuration error: %w", err)
}
return c, settings, nil
}
c, err = newClientFunc(settings)
if err != nil {
return nil, nil, fmt.Errorf("redis client configuration error: %w", err)
}
return c, settings, nil
}

func ClientHasJSONSupport(c RedisClient) bool {
Expand Down

0 comments on commit 861fe36

Please sign in to comment.