Skip to content
Open
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
4 changes: 4 additions & 0 deletions cache-redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@

### Configuration
- `Endpoint` - Redis connection address
- `Username` - Redis username
- `Password` - Redis password
- `TLS` - Enable TLS when connecting to Redis
- `Skip TLS Verify` - Skip TLS certificate verification (insecure, not recommended for production)
10 changes: 10 additions & 0 deletions cache-redis/i18n/en_US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ plugin:
other: Password
description:
other: Redis password
tls_enabled:
title:
other: TLS
description:
other: Enable TLS when connecting to Redis
tls_skip_verify:
title:
other: Skip TLS Verify
description:
other: Skip TLS certificate verification (insecure, not recommended for production)
5 changes: 5 additions & 0 deletions cache-redis/i18n/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ const (
ConfigUsernameDescription = "plugin.redis_cache.backend.config.username.description"
ConfigPasswordTitle = "plugin.redis_cache.backend.config.password.title"
ConfigPasswordDescription = "plugin.redis_cache.backend.config.password.description"

ConfigTLSEnabledTitle = "plugin.redis_cache.backend.config.tls_enabled.title"
ConfigTLSEnabledDescription = "plugin.redis_cache.backend.config.tls_enabled.description"
ConfigTLSSkipVerifyTitle = "plugin.redis_cache.backend.config.tls_skip_verify.title"
ConfigTLSSkipVerifyDescription = "plugin.redis_cache.backend.config.tls_skip_verify.description"
)
12 changes: 11 additions & 1 deletion cache-redis/i18n/zh_CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ plugin:
title:
other: 密码
description:
other: Redis 密码
other: Redis 密码
tls_enabled:
title:
other: TLS
description:
other: 连接 Redis 时启用 TLS
tls_skip_verify:
title:
other: 跳过 TLS 验证
description:
other: 跳过 TLS 证书验证(不安全,不建议在生产环境使用)
2 changes: 1 addition & 1 deletion cache-redis/info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

slug_name: redis_cache
type: cache
version: 1.3.1
version: 1.4.0
author: answerdev
link: https://github.com/apache/answer-plugins/tree/main/cache-redis
38 changes: 33 additions & 5 deletions cache-redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package redis

import (
"context"
"crypto/tls"
"embed"
_ "embed"
"encoding/json"
Expand All @@ -45,9 +46,11 @@ type Cache struct {
}

type CacheConfig struct {
Endpoint string `json:"endpoint"`
Username string `json:"username"`
Password string `json:"password"`
Endpoint string `json:"endpoint"`
Username string `json:"username"`
Password string `json:"password"`
TLSEnabled bool `json:"tls_enabled"`
TLSSkipVerify bool `json:"tls_skip_verify"`
}

func init() {
Expand Down Expand Up @@ -175,6 +178,24 @@ func (c *Cache) ConfigFields() []plugin.ConfigField {
},
Value: c.Config.Password,
},
{
Name: "tls_enabled",
Type: plugin.ConfigTypeSwitch,
Title: plugin.MakeTranslator(i18n.ConfigTLSEnabledTitle),
Value: c.Config.TLSEnabled,
UIOptions: plugin.ConfigFieldUIOptions{
Label: plugin.MakeTranslator(i18n.ConfigTLSEnabledDescription),
},
},
{
Name: "tls_skip_verify",
Type: plugin.ConfigTypeSwitch,
Title: plugin.MakeTranslator(i18n.ConfigTLSSkipVerifyTitle),
Value: c.Config.TLSSkipVerify,
UIOptions: plugin.ConfigFieldUIOptions{
Label: plugin.MakeTranslator(i18n.ConfigTLSSkipVerifyDescription),
},
},
}
}

Expand All @@ -183,10 +204,17 @@ func (c *Cache) ConfigReceiver(config []byte) error {
_ = json.Unmarshal(config, conf)
c.Config = conf

c.RedisClient = redis.NewClient(&redis.Options{
opts := &redis.Options{
Addr: conf.Endpoint,
Username: conf.Username,
Password: conf.Password,
})
}
if conf.TLSEnabled {
opts.TLSConfig = &tls.Config{
InsecureSkipVerify: conf.TLSSkipVerify,
MinVersion: tls.VersionTLS12,
}
}
c.RedisClient = redis.NewClient(opts)
return nil
}