46 lines
1 KiB
Go
46 lines
1 KiB
Go
|
|
package config
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"github.com/redis/go-redis/v9"
|
||
|
|
"go.uber.org/zap"
|
||
|
|
)
|
||
|
|
|
||
|
|
// initRedis initialise la connexion Redis
|
||
|
|
func initRedis(redisURL string, logger *zap.Logger) (*redis.Client, error) {
|
||
|
|
opts, err := redis.ParseURL(redisURL)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
// Configurer un logger filtré pour Redis pour éviter les warnings "maint_notifications"
|
||
|
|
redis.SetLogger(&filteredRedisLogger{logger: logger})
|
||
|
|
|
||
|
|
client := redis.NewClient(opts)
|
||
|
|
|
||
|
|
// Test de connexion
|
||
|
|
ctx := context.Background()
|
||
|
|
_, err = client.Ping(ctx).Result()
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return client, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// filteredRedisLogger est un wrapper pour filtrer les logs de Redis
|
||
|
|
type filteredRedisLogger struct {
|
||
|
|
logger *zap.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *filteredRedisLogger) Printf(ctx context.Context, format string, v ...interface{}) {
|
||
|
|
msg := fmt.Sprintf(format, v...)
|
||
|
|
if strings.Contains(msg, "maint_notifications") {
|
||
|
|
return // Ignorer ce warning spécifique en mode auto-discovery
|
||
|
|
}
|
||
|
|
l.logger.Debug("Redis internal", zap.String("message", msg))
|
||
|
|
}
|