update redis func

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-23 15:20:30 +08:00
parent f5857f54b0
commit 8e79329131
1 changed files with 10 additions and 12 deletions

View File

@ -30,13 +30,6 @@ type IosStatus struct {
PushError int64 `json:"push_error"` 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() { func initApp() {
RushStatus.TotalCount = 0 RushStatus.TotalCount = 0
RushStatus.Ios.PushSuccess = 0 RushStatus.Ios.PushSuccess = 0
@ -93,6 +86,11 @@ func InitAppStatus() {
} }
func getRedisInt64Result(key string, count *int64) {
val, _ := RedisClient.Get(key).Result()
*count, _ = strconv.ParseInt(val, 10, 64)
}
func boltdbSet(key string, count int64) { func boltdbSet(key string, count int64) {
db, _ := storm.Open(PushConf.Stat.BoltDB.Path) db, _ := storm.Open(PushConf.Stat.BoltDB.Path)
db.Set(PushConf.Stat.BoltDB.Bucket, key, count) db.Set(PushConf.Stat.BoltDB.Bucket, key, count)
@ -176,7 +174,7 @@ func getTotalCount() int64 {
case "memory": case "memory":
count = atomic.LoadInt64(&RushStatus.TotalCount) count = atomic.LoadInt64(&RushStatus.TotalCount)
case "redis": case "redis":
count = getRedisInt64Result(gorushTotalCount) getRedisInt64Result(gorushTotalCount, &count)
case "boltdb": case "boltdb":
boltdbGet(gorushTotalCount, &count) boltdbGet(gorushTotalCount, &count)
default: default:
@ -192,7 +190,7 @@ func getIosSuccess() int64 {
case "memory": case "memory":
count = atomic.LoadInt64(&RushStatus.Ios.PushSuccess) count = atomic.LoadInt64(&RushStatus.Ios.PushSuccess)
case "redis": case "redis":
count = getRedisInt64Result(gorushIosSuccess) getRedisInt64Result(gorushIosSuccess, &count)
case "boltdb": case "boltdb":
boltdbGet(gorushIosSuccess, &count) boltdbGet(gorushIosSuccess, &count)
default: default:
@ -208,7 +206,7 @@ func getIosError() int64 {
case "memory": case "memory":
count = atomic.LoadInt64(&RushStatus.Ios.PushError) count = atomic.LoadInt64(&RushStatus.Ios.PushError)
case "redis": case "redis":
count = getRedisInt64Result(gorushIosError) getRedisInt64Result(gorushIosError, &count)
case "boltdb": case "boltdb":
boltdbGet(gorushIosError, &count) boltdbGet(gorushIosError, &count)
default: default:
@ -224,7 +222,7 @@ func getAndroidSuccess() int64 {
case "memory": case "memory":
count = atomic.LoadInt64(&RushStatus.Android.PushSuccess) count = atomic.LoadInt64(&RushStatus.Android.PushSuccess)
case "redis": case "redis":
count = getRedisInt64Result(gorushAndroidSuccess) getRedisInt64Result(gorushAndroidSuccess, &count)
case "boltdb": case "boltdb":
boltdbGet(gorushAndroidSuccess, &count) boltdbGet(gorushAndroidSuccess, &count)
default: default:
@ -240,7 +238,7 @@ func getAndroidError() int64 {
case "memory": case "memory":
count = atomic.LoadInt64(&RushStatus.Android.PushError) count = atomic.LoadInt64(&RushStatus.Android.PushError)
case "redis": case "redis":
count = getRedisInt64Result(gorushAndroidError) getRedisInt64Result(gorushAndroidError, &count)
case "boltdb": case "boltdb":
boltdbGet(gorushAndroidError, &count) boltdbGet(gorushAndroidError, &count)
default: default: