From 012316037ab1bee5b7326a7a2560c6a400402761 Mon Sep 17 00:00:00 2001 From: "Md. Ishtiaq Islam" Date: Fri, 26 Jul 2024 17:38:08 +0600 Subject: [PATCH] Add method to set database for redis client (#125) Signed-off-by: Md. Ishtiaq Islam --- redis/kubedb_client_builder.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/redis/kubedb_client_builder.go b/redis/kubedb_client_builder.go index 00d74d4d..f94dbeb4 100644 --- a/redis/kubedb_client_builder.go +++ b/redis/kubedb_client_builder.go @@ -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 { @@ -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 != "" { @@ -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)