From b690825cd4fa19f344b29535d859c4822dddc18c Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 15:47:14 +0800 Subject: [PATCH 1/9] add redis config. Signed-off-by: Bo-Yi Wu --- config/config.yml | 7 +++++++ gorush/config.go | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/config/config.yml b/config/config.yml index 6744425..6d90481 100644 --- a/config/config.yml +++ b/config/config.yml @@ -30,3 +30,10 @@ log: access_level: "debug" error_log: "stderr" error_level: "error" + +stat: + engine: "memory" + redis: + addr: "localhost:6379" + password: "" + db: "0" diff --git a/gorush/config.go b/gorush/config.go index bfb8e00..5af31a7 100644 --- a/gorush/config.go +++ b/gorush/config.go @@ -13,6 +13,7 @@ type ConfYaml struct { Android SectionAndroid `yaml:"android"` Ios SectionIos `yaml:"ios"` Log SectionLog `yaml:"log"` + Stat SectionStat `yaml:stat` } // SectionCore is sub seciont of config. @@ -58,6 +59,19 @@ type SectionLog struct { ErrorLevel string `yaml:"error_level"` } +// SectionStat is sub seciont of config. +type SectionStat struct { + Engine string `yaml:"service"` + Redis SectionRedis `yaml:"redis"` +} + +// SectionRedis is sub seciont of config. +type SectionRedis struct { + Addr string `yaml:"addr"` + Password string `yaml:"password"` + DB string `yaml:"db"` +} + // BuildDefaultPushConf is default config setting. func BuildDefaultPushConf() ConfYaml { var conf ConfYaml @@ -95,6 +109,11 @@ func BuildDefaultPushConf() ConfYaml { conf.Log.ErrorLog = "stderr" conf.Log.ErrorLevel = "error" + conf.Stat.Engine = "memory" + conf.Stat.Redis.Addr = "localhost:6379" + conf.Stat.Redis.Password = "" + conf.Stat.Redis.DB = "0" + return conf } From d95cb2abb53fc99cbfa1647eacd6c27d700179a1 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 17:54:00 +0800 Subject: [PATCH 2/9] Feature #61 support redis engine. Signed-off-by: Bo-Yi Wu --- config/config.yml | 2 +- gorush/config.go | 4 +- gorush/global.go | 3 + gorush/status.go | 153 ++++++++++++++++++++++++++++++++++++++---- gorush/status_test.go | 47 +++++++++++++ 5 files changed, 194 insertions(+), 15 deletions(-) diff --git a/config/config.yml b/config/config.yml index 6d90481..dd96f17 100644 --- a/config/config.yml +++ b/config/config.yml @@ -36,4 +36,4 @@ stat: redis: addr: "localhost:6379" password: "" - db: "0" + db: 0 diff --git a/gorush/config.go b/gorush/config.go index 5af31a7..29a8899 100644 --- a/gorush/config.go +++ b/gorush/config.go @@ -69,7 +69,7 @@ type SectionStat struct { type SectionRedis struct { Addr string `yaml:"addr"` Password string `yaml:"password"` - DB string `yaml:"db"` + DB int64 `yaml:"db"` } // BuildDefaultPushConf is default config setting. @@ -112,7 +112,7 @@ func BuildDefaultPushConf() ConfYaml { conf.Stat.Engine = "memory" conf.Stat.Redis.Addr = "localhost:6379" conf.Stat.Redis.Password = "" - conf.Stat.Redis.DB = "0" + conf.Stat.Redis.DB = 0 return conf } diff --git a/gorush/global.go b/gorush/global.go index 234604f..f5a5008 100644 --- a/gorush/global.go +++ b/gorush/global.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "github.com/Sirupsen/logrus" apns "github.com/sideshow/apns2" + "gopkg.in/redis.v3" ) var ( @@ -21,4 +22,6 @@ var ( LogError *logrus.Logger // RushStatus is notification status RushStatus StatusApp + // Redis + RedisClient *redis.Client ) diff --git a/gorush/status.go b/gorush/status.go index b4dc55c..6d5f1ca 100644 --- a/gorush/status.go +++ b/gorush/status.go @@ -2,7 +2,9 @@ package gorush import ( "github.com/gin-gonic/gin" + "gopkg.in/redis.v3" "net/http" + "strconv" "sync/atomic" ) @@ -27,8 +29,7 @@ type IosStatus struct { PushError int64 `json:"push_error"` } -// InitAppStatus for initialize app status -func InitAppStatus() { +func initApp() { RushStatus.TotalCount = 0 RushStatus.Ios.PushSuccess = 0 RushStatus.Ios.PushError = 0 @@ -36,24 +37,152 @@ func InitAppStatus() { RushStatus.Android.PushError = 0 } +// InitAppStatus for initialize app status +func InitAppStatus() { + switch PushConf.Stat.Engine { + case "memory": + initApp() + case "redis": + RedisClient = redis.NewClient(&redis.Options{ + Addr: PushConf.Stat.Redis.Addr, + Password: PushConf.Stat.Redis.Password, + DB: PushConf.Stat.Redis.DB, + }) + default: + initApp() + } + +} + func addTotalCount(count int64) { - atomic.AddInt64(&RushStatus.TotalCount, count) + switch PushConf.Stat.Engine { + case "memory": + atomic.AddInt64(&RushStatus.TotalCount, count) + case "redis": + RedisClient.Set("key1", strconv.Itoa(int(count)), 0) + default: + atomic.AddInt64(&RushStatus.TotalCount, count) + } } func addIosSuccess(count int64) { - atomic.AddInt64(&RushStatus.Ios.PushSuccess, count) + switch PushConf.Stat.Engine { + case "memory": + atomic.AddInt64(&RushStatus.Ios.PushSuccess, count) + case "redis": + RedisClient.Set("key2", strconv.Itoa(int(count)), 0) + default: + atomic.AddInt64(&RushStatus.Ios.PushSuccess, count) + } } func addIosError(count int64) { - atomic.AddInt64(&RushStatus.Ios.PushError, count) + switch PushConf.Stat.Engine { + case "memory": + atomic.AddInt64(&RushStatus.Ios.PushError, count) + case "redis": + RedisClient.Set("key3", strconv.Itoa(int(count)), 0) + default: + atomic.AddInt64(&RushStatus.Ios.PushError, count) + } } func addAndroidSuccess(count int64) { - atomic.AddInt64(&RushStatus.Android.PushSuccess, count) + switch PushConf.Stat.Engine { + case "memory": + atomic.AddInt64(&RushStatus.Android.PushSuccess, count) + case "redis": + + RedisClient.Set("key4", strconv.Itoa(int(count)), 0) + default: + atomic.AddInt64(&RushStatus.Android.PushSuccess, count) + } } func addAndroidError(count int64) { - atomic.AddInt64(&RushStatus.Android.PushError, count) + switch PushConf.Stat.Engine { + case "memory": + atomic.AddInt64(&RushStatus.Android.PushError, count) + case "redis": + RedisClient.Set("key5", strconv.Itoa(int(count)), 0) + default: + atomic.AddInt64(&RushStatus.Android.PushError, count) + } +} + +func getTotalCount() int64 { + var count int64 + switch PushConf.Stat.Engine { + case "memory": + count = atomic.LoadInt64(&RushStatus.TotalCount) + case "redis": + val, _ := RedisClient.Get("key1").Result() + count, _ = strconv.ParseInt(val, 10, 64) + default: + count = atomic.LoadInt64(&RushStatus.TotalCount) + } + + return count +} + +func getIosSuccess() int64 { + var count int64 + switch PushConf.Stat.Engine { + case "memory": + count = atomic.LoadInt64(&RushStatus.Ios.PushSuccess) + case "redis": + val, _ := RedisClient.Get("key2").Result() + count, _ = strconv.ParseInt(val, 10, 64) + default: + count = atomic.LoadInt64(&RushStatus.Ios.PushSuccess) + } + + return count +} + +func getIosError() int64 { + var count int64 + switch PushConf.Stat.Engine { + case "memory": + count = atomic.LoadInt64(&RushStatus.Ios.PushError) + case "redis": + val, _ := RedisClient.Get("key3").Result() + count, _ = strconv.ParseInt(val, 10, 64) + default: + count = atomic.LoadInt64(&RushStatus.Ios.PushError) + } + + return count +} + +func getAndroidSuccess() int64 { + var count int64 + switch PushConf.Stat.Engine { + case "memory": + count = atomic.LoadInt64(&RushStatus.Android.PushSuccess) + case "redis": + val, _ := RedisClient.Get("key4").Result() + count, _ = strconv.ParseInt(val, 10, 64) + default: + count = atomic.LoadInt64(&RushStatus.Android.PushSuccess) + } + + return count +} + +func getAndroidError() int64 { + var count int64 + switch PushConf.Stat.Engine { + case "memory": + count = atomic.LoadInt64(&RushStatus.Android.PushError) + case "redis": + val, _ := RedisClient.Get("key5").Result() + count, _ = strconv.ParseInt(val, 10, 64) + default: + count = atomic.LoadInt64(&RushStatus.Android.PushError) + } + + return count } func appStatusHandler(c *gin.Context) { @@ -61,11 +190,11 @@ func appStatusHandler(c *gin.Context) { result.QueueMax = cap(QueueNotification) result.QueueUsage = len(QueueNotification) - result.TotalCount = atomic.LoadInt64(&RushStatus.TotalCount) - result.Ios.PushSuccess = atomic.LoadInt64(&RushStatus.Ios.PushSuccess) - result.Ios.PushError = atomic.LoadInt64(&RushStatus.Ios.PushError) - result.Android.PushSuccess = atomic.LoadInt64(&RushStatus.Android.PushSuccess) - result.Android.PushError = atomic.LoadInt64(&RushStatus.Android.PushError) + result.TotalCount = getTotalCount() + result.Ios.PushSuccess = getIosSuccess() + result.Ios.PushError = getIosError() + result.Android.PushSuccess = getAndroidSuccess() + result.Android.PushError = getAndroidError() c.JSON(http.StatusOK, result) } diff --git a/gorush/status_test.go b/gorush/status_test.go index 0aa8017..371d6dd 100644 --- a/gorush/status_test.go +++ b/gorush/status_test.go @@ -50,3 +50,50 @@ func TestAddAndroidError(t *testing.T) { assert.Equal(t, int64(1000), val) } + +func TestStatForRedisEngine(t *testing.T) { + var val int64 + PushConf.Stat.Engine = "redis" + PushConf.Stat.Redis.Addr = "localhost:6379" + InitAppStatus() + + addTotalCount(1000) + addIosSuccess(1000) + addIosError(1000) + addAndroidSuccess(1000) + addAndroidError(1000) + + val = getTotalCount() + assert.Equal(t, int64(1000), val) + val = getIosSuccess() + assert.Equal(t, int64(1000), val) + val = getIosError() + assert.Equal(t, int64(1000), val) + val = getAndroidSuccess() + assert.Equal(t, int64(1000), val) + val = getAndroidError() + assert.Equal(t, int64(1000), val) +} + +func TestDefaultEngine(t *testing.T) { + var val int64 + PushConf.Stat.Engine = "test" + InitAppStatus() + + addTotalCount(1000) + addIosSuccess(1000) + addIosError(1000) + addAndroidSuccess(1000) + addAndroidError(1000) + + val = getTotalCount() + assert.Equal(t, int64(1000), val) + val = getIosSuccess() + assert.Equal(t, int64(1000), val) + val = getIosError() + assert.Equal(t, int64(1000), val) + val = getAndroidSuccess() + assert.Equal(t, int64(1000), val) + val = getAndroidError() + assert.Equal(t, int64(1000), val) +} From 3be61ad608aea91855bc5fd1e360ef283c0a53e3 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 17:57:45 +0800 Subject: [PATCH 3/9] update readme Signed-off-by: Bo-Yi Wu --- .travis.yml | 1 + README.md | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index b3deba4..919b36b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ go: services: - docker + - redis env: global: diff --git a/README.md b/README.md index eb27fba..9faf46f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,13 @@ log: access_level: "debug" error_log: "stderr" # stderr: output to console, or define log path like "log/error_log" error_level: "error" + +stat: + engine: "memory" # support memory or redis + redis: + addr: "localhost:6379" + password: "" + db: 0 ``` ## Basic Usage From 6ef663928d7d4fcd1a6f7fd44e7dfb0efdae6c12 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 18:20:01 +0800 Subject: [PATCH 4/9] fix initial error count for redis. Signed-off-by: Bo-Yi Wu --- gorush/status.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gorush/status.go b/gorush/status.go index 6d5f1ca..029f8e6 100644 --- a/gorush/status.go +++ b/gorush/status.go @@ -48,6 +48,12 @@ func InitAppStatus() { Password: PushConf.Stat.Redis.Password, DB: PushConf.Stat.Redis.DB, }) + + RushStatus.TotalCount = getTotalCount() + RushStatus.Ios.PushSuccess = getIosSuccess() + RushStatus.Ios.PushError = getIosError() + RushStatus.Android.PushSuccess = getAndroidSuccess() + RushStatus.Android.PushError = getAndroidError() default: initApp() } From 5628a66f142eec4bf9a11e000f55b2143a226c04 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 18:23:34 +0800 Subject: [PATCH 5/9] update readme. Signed-off-by: Bo-Yi Wu --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9faf46f..af72368 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ A push notification server using [Gin](https://github.com/gin-gonic/gin) framewo * Support notification queue and multiple workers. * Support `/api/stat/app` show notification success and failure counts. * Support `/api/config` show your yml config. +* Support store app stat to [redis](http://redis.io/) or memory. See the [YAML config example](config/config.yml): From 9a609aa5fef5f43a9b55ad70dcd198d90cccdbc4 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 22:45:19 +0800 Subject: [PATCH 6/9] update variable. Signed-off-by: Bo-Yi Wu --- gorush/const.go | 9 +++++++++ gorush/global.go | 2 +- gorush/status.go | 32 +++++++++++++++++--------------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/gorush/const.go b/gorush/const.go index b3b137c..dc3fb6f 100644 --- a/gorush/const.go +++ b/gorush/const.go @@ -18,3 +18,12 @@ const ( // FailedPush is log block FailedPush = "failed-push" ) + +// Stat variable for redis +const ( + gorushTotalCount = "gorush-total-count" + gorushIosSuccess = "gorush-ios-success-count" + gorushIosError = "gorush-ios-error-count" + gorushAndroidSuccess = "gorush-android-success-count" + gorushAndroidError = "gorush-android-error-count" +) diff --git a/gorush/global.go b/gorush/global.go index f5a5008..9beab50 100644 --- a/gorush/global.go +++ b/gorush/global.go @@ -22,6 +22,6 @@ var ( LogError *logrus.Logger // RushStatus is notification status RushStatus StatusApp - // Redis + // RedisClient is global variable for redis RedisClient *redis.Client ) diff --git a/gorush/status.go b/gorush/status.go index 029f8e6..6e23e7c 100644 --- a/gorush/status.go +++ b/gorush/status.go @@ -29,6 +29,13 @@ type IosStatus struct { PushError int64 `json:"push_error"` } +func getRedisInt64Result(key string) int64 { + val, _ := RedisClient.Get(key).Result() + count, _ := strconv.ParseInt(val, 10, 64) + + return count +} + func initApp() { RushStatus.TotalCount = 0 RushStatus.Ios.PushSuccess = 0 @@ -65,7 +72,7 @@ func addTotalCount(count int64) { case "memory": atomic.AddInt64(&RushStatus.TotalCount, count) case "redis": - RedisClient.Set("key1", strconv.Itoa(int(count)), 0) + RedisClient.Set(gorushTotalCount, strconv.Itoa(int(count)), 0) default: atomic.AddInt64(&RushStatus.TotalCount, count) } @@ -76,7 +83,7 @@ func addIosSuccess(count int64) { case "memory": atomic.AddInt64(&RushStatus.Ios.PushSuccess, count) case "redis": - RedisClient.Set("key2", strconv.Itoa(int(count)), 0) + RedisClient.Set(gorushIosSuccess, strconv.Itoa(int(count)), 0) default: atomic.AddInt64(&RushStatus.Ios.PushSuccess, count) } @@ -87,7 +94,7 @@ func addIosError(count int64) { case "memory": atomic.AddInt64(&RushStatus.Ios.PushError, count) case "redis": - RedisClient.Set("key3", strconv.Itoa(int(count)), 0) + RedisClient.Set(gorushIosError, strconv.Itoa(int(count)), 0) default: atomic.AddInt64(&RushStatus.Ios.PushError, count) } @@ -99,7 +106,7 @@ func addAndroidSuccess(count int64) { atomic.AddInt64(&RushStatus.Android.PushSuccess, count) case "redis": - RedisClient.Set("key4", strconv.Itoa(int(count)), 0) + RedisClient.Set(gorushAndroidSuccess, strconv.Itoa(int(count)), 0) default: atomic.AddInt64(&RushStatus.Android.PushSuccess, count) } @@ -110,7 +117,7 @@ func addAndroidError(count int64) { case "memory": atomic.AddInt64(&RushStatus.Android.PushError, count) case "redis": - RedisClient.Set("key5", strconv.Itoa(int(count)), 0) + RedisClient.Set(gorushAndroidError, strconv.Itoa(int(count)), 0) default: atomic.AddInt64(&RushStatus.Android.PushError, count) } @@ -122,8 +129,7 @@ func getTotalCount() int64 { case "memory": count = atomic.LoadInt64(&RushStatus.TotalCount) case "redis": - val, _ := RedisClient.Get("key1").Result() - count, _ = strconv.ParseInt(val, 10, 64) + count = getRedisInt64Result(gorushAndroidError) default: count = atomic.LoadInt64(&RushStatus.TotalCount) } @@ -137,8 +143,7 @@ func getIosSuccess() int64 { case "memory": count = atomic.LoadInt64(&RushStatus.Ios.PushSuccess) case "redis": - val, _ := RedisClient.Get("key2").Result() - count, _ = strconv.ParseInt(val, 10, 64) + count = getRedisInt64Result(gorushAndroidError) default: count = atomic.LoadInt64(&RushStatus.Ios.PushSuccess) } @@ -152,8 +157,7 @@ func getIosError() int64 { case "memory": count = atomic.LoadInt64(&RushStatus.Ios.PushError) case "redis": - val, _ := RedisClient.Get("key3").Result() - count, _ = strconv.ParseInt(val, 10, 64) + count = getRedisInt64Result(gorushAndroidError) default: count = atomic.LoadInt64(&RushStatus.Ios.PushError) } @@ -167,8 +171,7 @@ func getAndroidSuccess() int64 { case "memory": count = atomic.LoadInt64(&RushStatus.Android.PushSuccess) case "redis": - val, _ := RedisClient.Get("key4").Result() - count, _ = strconv.ParseInt(val, 10, 64) + count = getRedisInt64Result(gorushAndroidError) default: count = atomic.LoadInt64(&RushStatus.Android.PushSuccess) } @@ -182,8 +185,7 @@ func getAndroidError() int64 { case "memory": count = atomic.LoadInt64(&RushStatus.Android.PushError) case "redis": - val, _ := RedisClient.Get("key5").Result() - count, _ = strconv.ParseInt(val, 10, 64) + count = getRedisInt64Result(gorushAndroidError) default: count = atomic.LoadInt64(&RushStatus.Android.PushError) } From a8116a8ccb5fd924c46a1083aa193fb800049834 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 23:01:01 +0800 Subject: [PATCH 7/9] add init redis func. Signed-off-by: Bo-Yi Wu --- docker/Dockerfile.build | 2 +- gorush/status.go | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build index 1e3a942..6b90f82 100644 --- a/docker/Dockerfile.build +++ b/docker/Dockerfile.build @@ -7,6 +7,6 @@ RUN mkdir -p /tmp/build Add build.tar.gz /tmp/build/ WORKDIR /tmp/build RUN go get -v -d -RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w" -o bin/gorush gorush.go +RUN GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o bin/gorush gorush.go CMD tar -C bin -czf - gorush diff --git a/gorush/status.go b/gorush/status.go index 6e23e7c..ccdc569 100644 --- a/gorush/status.go +++ b/gorush/status.go @@ -44,23 +44,27 @@ func initApp() { RushStatus.Android.PushError = 0 } +func initRedis() { + RedisClient = redis.NewClient(&redis.Options{ + Addr: PushConf.Stat.Redis.Addr, + Password: PushConf.Stat.Redis.Password, + DB: PushConf.Stat.Redis.DB, + }) + + RushStatus.TotalCount = getTotalCount() + RushStatus.Ios.PushSuccess = getIosSuccess() + RushStatus.Ios.PushError = getIosError() + RushStatus.Android.PushSuccess = getAndroidSuccess() + RushStatus.Android.PushError = getAndroidError() +} + // InitAppStatus for initialize app status func InitAppStatus() { switch PushConf.Stat.Engine { case "memory": initApp() case "redis": - RedisClient = redis.NewClient(&redis.Options{ - Addr: PushConf.Stat.Redis.Addr, - Password: PushConf.Stat.Redis.Password, - DB: PushConf.Stat.Redis.DB, - }) - - RushStatus.TotalCount = getTotalCount() - RushStatus.Ios.PushSuccess = getIosSuccess() - RushStatus.Ios.PushError = getIosError() - RushStatus.Android.PushSuccess = getAndroidSuccess() - RushStatus.Android.PushError = getAndroidError() + initRedis() default: initApp() } From 23c6fa8f18502443f137592bc42527ea27f4f602 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 23:17:03 +0800 Subject: [PATCH 8/9] remove 1.3 and 1.4 testing for redis go. Signed-off-by: Bo-Yi Wu --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 919b36b..3ea246e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,9 @@ sudo: required language: go go: - - 1.3 - - 1.4 - 1.5 + - 1.6 + - 1.6.1 - 1.6.2 - tip From f6ad753345f0e2a4375c16d7c0f5162f59a6f32a Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 22 Apr 2016 23:39:36 +0800 Subject: [PATCH 9/9] test redis connect Signed-off-by: Bo-Yi Wu --- gorush/status.go | 13 ++++++++++++- gorush/status_test.go | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gorush/status.go b/gorush/status.go index ccdc569..d75122f 100644 --- a/gorush/status.go +++ b/gorush/status.go @@ -44,18 +44,29 @@ func initApp() { RushStatus.Android.PushError = 0 } -func initRedis() { +func initRedis() error { RedisClient = redis.NewClient(&redis.Options{ Addr: PushConf.Stat.Redis.Addr, Password: PushConf.Stat.Redis.Password, DB: PushConf.Stat.Redis.DB, }) + _, err := RedisClient.Ping().Result() + + if err != nil { + // redis server error + LogError.Error("Can't connect redis server: " + err.Error()) + + return err + } + RushStatus.TotalCount = getTotalCount() RushStatus.Ios.PushSuccess = getIosSuccess() RushStatus.Ios.PushError = getIosError() RushStatus.Android.PushSuccess = getAndroidSuccess() RushStatus.Android.PushError = getAndroidError() + + return nil } // InitAppStatus for initialize app status diff --git a/gorush/status_test.go b/gorush/status_test.go index 371d6dd..c80c1f4 100644 --- a/gorush/status_test.go +++ b/gorush/status_test.go @@ -51,6 +51,22 @@ func TestAddAndroidError(t *testing.T) { assert.Equal(t, int64(1000), val) } +func TestRedisServerSuccess(t *testing.T) { + PushConf.Stat.Redis.Addr = "localhost:6379" + + err := initRedis() + + assert.NoError(t, err) +} + +func TestRedisServerError(t *testing.T) { + PushConf.Stat.Redis.Addr = "localhost:6370" + + err := initRedis() + + assert.Error(t, err) +} + func TestStatForRedisEngine(t *testing.T) { var val int64 PushConf.Stat.Engine = "redis"