refactor: storage key. (#242)
* refactor: storage key. * fix path Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -5,16 +5,9 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/appleboy/gorush/config"
|
||||
"gopkg.in/redis.v5"
|
||||
)
|
||||
"github.com/appleboy/gorush/storage"
|
||||
|
||||
// Stat variable for redis
|
||||
const (
|
||||
TotalCountKey = "gorush-total-count"
|
||||
IosSuccessKey = "gorush-ios-success-count"
|
||||
IosErrorKey = "gorush-ios-error-count"
|
||||
AndroidSuccessKey = "gorush-android-success-count"
|
||||
AndroidErrorKey = "gorush-android-error-count"
|
||||
"gopkg.in/redis.v5"
|
||||
)
|
||||
|
||||
//
|
||||
@@ -59,47 +52,47 @@ func (s *Storage) Init() error {
|
||||
|
||||
// Reset Client storage.
|
||||
func (s *Storage) Reset() {
|
||||
redisClient.Set(TotalCountKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(IosSuccessKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(IosErrorKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(AndroidSuccessKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(AndroidErrorKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(storage.TotalCountKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(storage.IosSuccessKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(storage.IosErrorKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(storage.AndroidSuccessKey, strconv.Itoa(0), 0)
|
||||
redisClient.Set(storage.AndroidErrorKey, strconv.Itoa(0), 0)
|
||||
}
|
||||
|
||||
// AddTotalCount record push notification count.
|
||||
func (s *Storage) AddTotalCount(count int64) {
|
||||
total := s.GetTotalCount() + count
|
||||
redisClient.Set(TotalCountKey, strconv.Itoa(int(total)), 0)
|
||||
redisClient.Set(storage.TotalCountKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
// AddIosSuccess record counts of success iOS push notification.
|
||||
func (s *Storage) AddIosSuccess(count int64) {
|
||||
total := s.GetIosSuccess() + count
|
||||
redisClient.Set(IosSuccessKey, strconv.Itoa(int(total)), 0)
|
||||
redisClient.Set(storage.IosSuccessKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
// AddIosError record counts of error iOS push notification.
|
||||
func (s *Storage) AddIosError(count int64) {
|
||||
total := s.GetIosError() + count
|
||||
redisClient.Set(IosErrorKey, strconv.Itoa(int(total)), 0)
|
||||
redisClient.Set(storage.IosErrorKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
// AddAndroidSuccess record counts of success Android push notification.
|
||||
func (s *Storage) AddAndroidSuccess(count int64) {
|
||||
total := s.GetAndroidSuccess() + count
|
||||
redisClient.Set(AndroidSuccessKey, strconv.Itoa(int(total)), 0)
|
||||
redisClient.Set(storage.AndroidSuccessKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
// AddAndroidError record counts of error Android push notification.
|
||||
func (s *Storage) AddAndroidError(count int64) {
|
||||
total := s.GetAndroidError() + count
|
||||
redisClient.Set(AndroidErrorKey, strconv.Itoa(int(total)), 0)
|
||||
redisClient.Set(storage.AndroidErrorKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
// GetTotalCount show counts of all notification.
|
||||
func (s *Storage) GetTotalCount() int64 {
|
||||
var count int64
|
||||
getInt64(TotalCountKey, &count)
|
||||
getInt64(storage.TotalCountKey, &count)
|
||||
|
||||
return count
|
||||
}
|
||||
@@ -107,7 +100,7 @@ func (s *Storage) GetTotalCount() int64 {
|
||||
// GetIosSuccess show success counts of iOS notification.
|
||||
func (s *Storage) GetIosSuccess() int64 {
|
||||
var count int64
|
||||
getInt64(IosSuccessKey, &count)
|
||||
getInt64(storage.IosSuccessKey, &count)
|
||||
|
||||
return count
|
||||
}
|
||||
@@ -115,7 +108,7 @@ func (s *Storage) GetIosSuccess() int64 {
|
||||
// GetIosError show error counts of iOS notification.
|
||||
func (s *Storage) GetIosError() int64 {
|
||||
var count int64
|
||||
getInt64(IosErrorKey, &count)
|
||||
getInt64(storage.IosErrorKey, &count)
|
||||
|
||||
return count
|
||||
}
|
||||
@@ -123,7 +116,7 @@ func (s *Storage) GetIosError() int64 {
|
||||
// GetAndroidSuccess show success counts of Android notification.
|
||||
func (s *Storage) GetAndroidSuccess() int64 {
|
||||
var count int64
|
||||
getInt64(AndroidSuccessKey, &count)
|
||||
getInt64(storage.AndroidSuccessKey, &count)
|
||||
|
||||
return count
|
||||
}
|
||||
@@ -131,7 +124,7 @@ func (s *Storage) GetAndroidSuccess() int64 {
|
||||
// GetAndroidError show error counts of Android notification.
|
||||
func (s *Storage) GetAndroidError() int64 {
|
||||
var count int64
|
||||
getInt64(AndroidErrorKey, &count)
|
||||
getInt64(storage.AndroidErrorKey, &count)
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user