add redis init status log (#1867)

Co-authored-by: Kent Dong <ch3cho@qq.com>
This commit is contained in:
rinfx
2025-03-10 17:10:53 +08:00
committed by GitHub
parent b897825069
commit 9e2df8f7c7
6 changed files with 29 additions and 9 deletions

View File

@@ -16,13 +16,14 @@ func (r *redisProviderInitializer) ValidateConfig(cf ProviderConfig) error {
return nil
}
func (r *redisProviderInitializer) CreateProvider(cf ProviderConfig) (Provider, error) {
func (r *redisProviderInitializer) CreateProvider(cf ProviderConfig, log wrapper.Log) (Provider, error) {
rp := redisProvider{
config: cf,
client: wrapper.NewRedisClusterClient(wrapper.FQDNCluster{
FQDN: cf.serviceName,
Host: cf.serviceHost,
Port: int64(cf.servicePort)}),
log: log,
}
err := rp.Init(cf.username, cf.password, cf.timeout)
return &rp, err
@@ -31,6 +32,7 @@ func (r *redisProviderInitializer) CreateProvider(cf ProviderConfig) (Provider,
type redisProvider struct {
config ProviderConfig
client wrapper.RedisClient
log wrapper.Log
}
func (rp *redisProvider) GetProviderType() string {
@@ -38,7 +40,13 @@ 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), wrapper.WithDataBase(rp.config.database))
err := rp.client.Init(rp.config.username, rp.config.password, int64(rp.config.timeout), wrapper.WithDataBase(rp.config.database))
if rp.client.Ready() {
rp.log.Info("redis init successfully")
} else {
rp.log.Error("redis init failed, will try later")
}
return err
}
func (rp *redisProvider) Get(key string, cb wrapper.RedisResponseCallback) error {