Skip to content

Commit

Permalink
Add method to set database for redis client (#125)
Browse files Browse the repository at this point in the history
Signed-off-by: Md. Ishtiaq Islam <[email protected]>
  • Loading branch information
ishtiaqhimel authored Jul 26, 2024
1 parent 877df85 commit 0123160
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions redis/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ const (
)

type KubeDBClientBuilder struct {
kc client.Client
db *dbapi.Redis
podName string
url string
kc client.Client
db *dbapi.Redis
podName string
url string
database int
}

func NewKubeDBClientBuilder(kc client.Client, db *dbapi.Redis) *KubeDBClientBuilder {
Expand All @@ -63,6 +64,11 @@ func (o *KubeDBClientBuilder) WithURL(url string) *KubeDBClientBuilder {
return o
}

func (o *KubeDBClientBuilder) WithDatabase(database int) *KubeDBClientBuilder {
o.database = database
return o
}

func (o *KubeDBClientBuilder) GetRedisClient(ctx context.Context) (*Client, error) {
var err error
if o.podName != "" {
Expand All @@ -76,6 +82,7 @@ func (o *KubeDBClientBuilder) GetRedisClient(ctx context.Context) (*Client, erro
ConnMaxIdleTime: DefaultConnMaxIdleTime,
PoolSize: DefaultPoolSize,
Addr: o.url,
DB: o.database,
}
if !o.db.Spec.DisableAuth {
rdOpts.Password, err = o.getClientPassword(ctx)
Expand Down

0 comments on commit 0123160

Please sign in to comment.