feat(redis): add REDIS_USERNAME support for Redis ACL

This commit is contained in:
Dounx
2026-02-04 18:48:04 +08:00
committed by lyingbug
parent c2cdc16712
commit 6e03f1ea79
8 changed files with 18 additions and 2 deletions
+1
View File
@@ -149,6 +149,7 @@ type StreamManagerConfig struct {
// RedisConfig Redis配置
type RedisConfig struct {
Address string `yaml:"address" json:"address"` // Redis地址
Username string `yaml:"username" json:"username"` // Redis用户名
Password string `yaml:"password" json:"password"` // Redis密码
DB int `yaml:"db" json:"db"` // Redis数据库
Prefix string `yaml:"prefix" json:"prefix"` // 键前缀
+1
View File
@@ -238,6 +238,7 @@ func initRedisClient() (*redis.Client, error) {
client := redis.NewClient(&redis.Options{
Addr: os.Getenv("REDIS_ADDR"),
Username: os.Getenv("REDIS_USERNAME"),
Password: os.Getenv("REDIS_PASSWORD"),
DB: db,
})
+1
View File
@@ -25,6 +25,7 @@ func NewStreamManager() (interfaces.StreamManager, error) {
ttl := time.Hour // 默认1小时
return NewRedisStreamManager(
os.Getenv("REDIS_ADDR"),
os.Getenv("REDIS_USERNAME"),
os.Getenv("REDIS_PASSWORD"),
db,
os.Getenv("REDIS_PREFIX"),
+2 -1
View File
@@ -18,11 +18,12 @@ type RedisStreamManager struct {
}
// NewRedisStreamManager creates a new Redis-based stream manager
func NewRedisStreamManager(redisAddr, redisPassword string,
func NewRedisStreamManager(redisAddr, redisUsername, redisPassword string,
redisDB int, prefix string, ttl time.Duration,
) (*RedisStreamManager, error) {
client := redis.NewClient(&redis.Options{
Addr: redisAddr,
Username: redisUsername,
Password: redisPassword,
DB: redisDB,
})