mirror of
https://github.com/alibaba/higress.git
synced 2026-06-06 19:27:33 +08:00
Add database configuration for plugins that use Redis. (#1814)
This commit is contained in:
@@ -52,6 +52,9 @@ type ProviderConfig struct {
|
||||
// @Title 缓存 Key 前缀
|
||||
// @Description 缓存 Key 的前缀,默认值为 "higressAiCache:"
|
||||
cacheKeyPrefix string
|
||||
// @Title redis database
|
||||
// @Description 指定 redis 的 database,默认使用0
|
||||
database int
|
||||
}
|
||||
|
||||
func (c *ProviderConfig) GetProviderType() string {
|
||||
@@ -79,6 +82,7 @@ func (c *ProviderConfig) FromJson(json gjson.Result) {
|
||||
if !json.Get("password").Exists() {
|
||||
c.password = ""
|
||||
}
|
||||
c.database = int(json.Get("database").Int())
|
||||
c.timeout = uint32(json.Get("timeout").Int())
|
||||
if !json.Get("timeout").Exists() {
|
||||
c.timeout = 10000
|
||||
|
||||
@@ -38,7 +38,7 @@ func (rp *redisProvider) GetProviderType() string {
|
||||
}
|
||||
|
||||
func (rp *redisProvider) Init(username string, password string, timeout uint32) error {
|
||||
return rp.client.Init(rp.config.username, rp.config.password, int64(rp.config.timeout))
|
||||
return rp.client.Init(rp.config.username, rp.config.password, int64(rp.config.timeout), wrapper.WithDataBase(rp.config.database))
|
||||
}
|
||||
|
||||
func (rp *redisProvider) Get(key string, cb wrapper.RedisResponseCallback) error {
|
||||
|
||||
Reference in New Issue
Block a user