Repository: appleboy/gorush

Issue:
can not specify redis db
can not specify redis db which is not 0

Hints from issue comments:
@appleboy: I will take it.@appleboy: update to https://github.com/appleboy/gorush/releases/tag/v1.19.2

Solution patch:
diff --git a/config/config.go b/config/config.go
index 132973f..e84e9b3 100644
--- a/config/config.go
+++ b/config/config.go
@@ -88,6 +88,7 @@ queue:
     with_tls: false
     username: ""
     password: ""
+    db: 0
 
 ios:
   enabled: false
@@ -263,6 +264,7 @@ type SectionRedisQueue struct {
 	Addr       string `yaml:"addr"`
 	Username   string `yaml:"username"`
 	Password   string `yaml:"password"`
+	DB         int    `yaml:"db"`
 	StreamName string `yaml:"stream_name"`
 	Group      string `yaml:"group"`
 	Consumer   string `yaml:"consumer"`
@@ -487,6 +489,7 @@ func loadConfigFromViper() (*ConfYaml, error) {
 	conf.Queue.Redis.WithTLS = viper.GetBool("queue.redis.with_tls")
 	conf.Queue.Redis.Username = viper.GetString("queue.redis.username")
 	conf.Queue.Redis.Password = viper.GetString("queue.redis.password")
+	conf.Queue.Redis.DB = viper.GetInt("queue.redis.db")
 
 	// Stat Engine
 	conf.Stat.Engine = viper.GetString("stat.engine")
diff --git a/main.go b/main.go
index 40cc6c5..b8c1f81 100644
--- a/main.go
+++ b/main.go
@@ -344,6 +344,7 @@ func main() {
 			redisdb.WithAddr(cfg.Queue.Redis.Addr),
 			redisdb.WithUsername(cfg.Queue.Redis.Username),
 			redisdb.WithPassword(cfg.Queue.Redis.Password),
+			redisdb.WithDB(cfg.Queue.Redis.DB),
 			redisdb.WithStreamName(cfg.Queue.Redis.StreamName),
 			redisdb.WithGroup(cfg.Queue.Redis.Group),
 			redisdb.WithConsumer(cfg.Queue.Redis.Consumer),



Test patch:
diff --git a/config/config_test.go b/config/config_test.go
index 497a8a9..1867e09 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -160,6 +160,7 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
 	assert.Equal(suite.T(), "", suite.ConfGorushDefault.Queue.Redis.Username)
 	assert.Equal(suite.T(), "", suite.ConfGorushDefault.Queue.Redis.Password)
 	assert.Equal(suite.T(), false, suite.ConfGorushDefault.Queue.Redis.WithTLS)
+	assert.Equal(suite.T(), 0, suite.ConfGorushDefault.Queue.Redis.DB)
 
 	// log
 	assert.Equal(suite.T(), "string", suite.ConfGorushDefault.Log.Format)
@@ -299,6 +300,43 @@ func TestLoadConfigFromEnv(t *testing.T) {
 	assert.Equal(t, "x-auth-key:0987654321", ConfGorush.Core.FeedbackHeader[1])
 }
 
+func TestRedisDBConfiguration(t *testing.T) {
+	// Test loading Redis DB configuration from file
+	conf, err := LoadConf("testdata/redis_db_config.yml")
+	if err != nil {
+		t.Fatalf("failed to load redis_db_config.yml: %v", err)
+	}
+
+	// Test queue.redis.db is properly loaded
+	assert.Equal(t, "redis", conf.Queue.Engine)
+	assert.Equal(t, 5, conf.Queue.Redis.DB)
+
+	// Test stat.redis.db is properly loaded
+	assert.Equal(t, "redis", conf.Stat.Engine)
+	assert.Equal(t, 3, conf.Stat.Redis.DB)
+}
+
+func TestRedisDBConfigurationFromEnv(t *testing.T) {
+	// Test loading Redis DB configuration from environment variables
+	os.Setenv("GORUSH_QUEUE_REDIS_DB", "7")
+	os.Setenv("GORUSH_STAT_REDIS_DB", "9")
+
+	conf, err := LoadConf()
+	if err != nil {
+		t.Fatalf("failed to load config: %v", err)
+	}
+
+	// Test queue.redis.db is properly loaded from env
+	assert.Equal(t, 7, conf.Queue.Redis.DB)
+
+	// Test stat.redis.db is properly loaded from env
+	assert.Equal(t, 9, conf.Stat.Redis.DB)
+
+	// Clean up
+	os.Unsetenv("GORUSH_QUEUE_REDIS_DB")
+	os.Unsetenv("GORUSH_STAT_REDIS_DB")
+}
+
 func TestLoadWrongDefaultYAMLConfig(t *testing.T) {
 	defaultConf = []byte(`a`)
 	_, err := LoadConf()
diff --git a/config/testdata/config.yml b/config/testdata/config.yml
index b8fd5f7..4bbfa38 100644
--- a/config/testdata/config.yml
+++ b/config/testdata/config.yml
@@ -73,6 +73,7 @@ queue:
     username: ""
     password: ""
     with_tls: false
+    db: 0
 
 ios:
   enabled: false
diff --git a/config/testdata/redis_db_config.yml b/config/testdata/redis_db_config.yml
new file mode 100644
index 0000000..10d95f7
--- /dev/null
+++ b/config/testdata/redis_db_config.yml
@@ -0,0 +1,20 @@
+queue:
+  engine: "redis"
+  redis:
+    addr: 127.0.0.1:6379
+    group: gorush
+    consumer: gorush
+    stream_name: gorush
+    username: ""
+    password: ""
+    with_tls: false
+    db: 5
+
+stat:
+  engine: "redis"
+  redis:
+    cluster: false
+    addr: "localhost:6379"
+    username: ""
+    password: ""
+    db: 3