You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/02/20 04:06:46 UTC

(incubator-answer-plugins) branch main updated: feat: cache-redis add username field

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git


The following commit(s) were added to refs/heads/main by this push:
     new 8c94253  feat: cache-redis add username field
8c94253 is described below

commit 8c942539ad190c5952f3e45ac895a51f1102fb27
Author: lincolnzhou <87...@qq.com>
AuthorDate: Tue Feb 20 11:21:19 2024 +0800

    feat: cache-redis add username field
---
 cache-redis/i18n/en_US.yaml     |  5 +++++
 cache-redis/i18n/translation.go |  2 ++
 cache-redis/i18n/zh_CN.yaml     |  5 +++++
 cache-redis/redis.go            | 13 +++++++++++++
 4 files changed, 25 insertions(+)

diff --git a/cache-redis/i18n/en_US.yaml b/cache-redis/i18n/en_US.yaml
index 9742f36..950185e 100644
--- a/cache-redis/i18n/en_US.yaml
+++ b/cache-redis/i18n/en_US.yaml
@@ -29,6 +29,11 @@ plugin:
             other: Endpoint
           description:
             other: Redis connection address, such as 127.0.0.1:6379
+        username:
+          title:
+            other: Username
+          description:
+            other: Redis username
         password:
           title:
             other: Password
diff --git a/cache-redis/i18n/translation.go b/cache-redis/i18n/translation.go
index 0d79295..55aa151 100644
--- a/cache-redis/i18n/translation.go
+++ b/cache-redis/i18n/translation.go
@@ -25,6 +25,8 @@ const (
 
 	ConfigEndpointTitle       = "plugin.redis_cache.backend.config.endpoint.title"
 	ConfigEndpointDescription = "plugin.redis_cache.backend.config.endpoint.description"
+	ConfigUsernameTitle       = "plugin.redis_cache.backend.config.username.title"
+	ConfigUsernameDescription = "plugin.redis_cache.backend.config.username.description"
 	ConfigPasswordTitle       = "plugin.redis_cache.backend.config.password.title"
 	ConfigPasswordDescription = "plugin.redis_cache.backend.config.password.description"
 )
diff --git a/cache-redis/i18n/zh_CN.yaml b/cache-redis/i18n/zh_CN.yaml
index 244fed5..ccb685b 100644
--- a/cache-redis/i18n/zh_CN.yaml
+++ b/cache-redis/i18n/zh_CN.yaml
@@ -29,6 +29,11 @@ plugin:
             other: Endpoint
           description:
             other: Redis的链接地址,如:127.0.0.1:6379
+        username:
+          title:
+            other: 用户名
+          description:
+            other: Redis 用户名
         password:
           title:
             other: 密码
diff --git a/cache-redis/redis.go b/cache-redis/redis.go
index 5cc239e..1fe3ca3 100644
--- a/cache-redis/redis.go
+++ b/cache-redis/redis.go
@@ -42,6 +42,7 @@ type Cache struct {
 
 type CacheConfig struct {
 	Endpoint string `json:"endpoint"`
+	Username string `json:"username"`
 	Password string `json:"password"`
 }
 
@@ -145,6 +146,17 @@ func (c *Cache) ConfigFields() []plugin.ConfigField {
 			},
 			Value: c.Config.Endpoint,
 		},
+		{
+			Name:        "username",
+			Type:        plugin.ConfigTypeInput,
+			Title:       plugin.MakeTranslator(i18n.ConfigUsernameTitle),
+			Description: plugin.MakeTranslator(i18n.ConfigUsernameDescription),
+			Required:    false,
+			UIOptions: plugin.ConfigFieldUIOptions{
+				InputType: plugin.InputTypeText,
+			},
+			Value: c.Config.Username,
+		},
 		{
 			Name:        "password",
 			Type:        plugin.ConfigTypeInput,
@@ -166,6 +178,7 @@ func (c *Cache) ConfigReceiver(config []byte) error {
 
 	c.RedisClient = redis.NewClient(&redis.Options{
 		Addr:     conf.Endpoint,
+		Username: conf.Username,
 		Password: conf.Password,
 	})
 	return nil