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"`
}
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
@ -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) {
db, _ := storm.Open(PushConf.Stat.BoltDB.Path)
db.Set(PushConf.Stat.BoltDB.Bucket, key, count)
@ -176,7 +174,7 @@ func getTotalCount() int64 {
case "memory":
count = atomic.LoadInt64(&RushStatus.TotalCount)
case "redis":
count = getRedisInt64Result(gorushTotalCount)
getRedisInt64Result(gorushTotalCount, &count)
case "boltdb":
boltdbGet(gorushTotalCount, &count)
default:
@ -192,7 +190,7 @@ func getIosSuccess() int64 {
case "memory":
count = atomic.LoadInt64(&RushStatus.Ios.PushSuccess)
case "redis":
count = getRedisInt64Result(gorushIosSuccess)
getRedisInt64Result(gorushIosSuccess, &count)
case "boltdb":
boltdbGet(gorushIosSuccess, &count)
default:
@ -208,7 +206,7 @@ func getIosError() int64 {
case "memory":
count = atomic.LoadInt64(&RushStatus.Ios.PushError)
case "redis":
count = getRedisInt64Result(gorushIosError)
getRedisInt64Result(gorushIosError, &count)
case "boltdb":
boltdbGet(gorushIosError, &count)
default:
@ -224,7 +222,7 @@ func getAndroidSuccess() int64 {
case "memory":
count = atomic.LoadInt64(&RushStatus.Android.PushSuccess)
case "redis":
count = getRedisInt64Result(gorushAndroidSuccess)
getRedisInt64Result(gorushAndroidSuccess, &count)
case "boltdb":
boltdbGet(gorushAndroidSuccess, &count)
default:
@ -240,7 +238,7 @@ func getAndroidError() int64 {
case "memory":
count = atomic.LoadInt64(&RushStatus.Android.PushError)
case "redis":
count = getRedisInt64Result(gorushAndroidError)
getRedisInt64Result(gorushAndroidError, &count)
case "boltdb":
boltdbGet(gorushAndroidError, &count)
default: