fix wrong stat count for redis engine.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
9cfe693ad9
commit
1ccd81bbd0
|
@ -52,24 +52,37 @@ func (s *Storage) initRedis() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Storage) resetRedis() {
|
||||
RedisClient.Set(gorush.TotalCountKey, strconv.Itoa(0), 0)
|
||||
RedisClient.Set(gorush.IosSuccessKey, strconv.Itoa(0), 0)
|
||||
RedisClient.Set(gorush.IosErrorKey, strconv.Itoa(0), 0)
|
||||
RedisClient.Set(gorush.AndroidSuccessKey, strconv.Itoa(0), 0)
|
||||
RedisClient.Set(gorush.AndroidErrorKey, strconv.Itoa(0), 0)
|
||||
}
|
||||
|
||||
func (s *Storage) addTotalCount(count int64) {
|
||||
RedisClient.Set(gorush.TotalCountKey, strconv.Itoa(int(count)), 0)
|
||||
total := s.getTotalCount() + count
|
||||
RedisClient.Set(gorush.TotalCountKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
func (s *Storage) addIosSuccess(count int64) {
|
||||
RedisClient.Set(gorush.IosSuccessKey, strconv.Itoa(int(count)), 0)
|
||||
total := s.getIosSuccess() + count
|
||||
RedisClient.Set(gorush.IosSuccessKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
func (s *Storage) addIosError(count int64) {
|
||||
RedisClient.Set(gorush.IosErrorKey, strconv.Itoa(int(count)), 0)
|
||||
total := s.getIosError() + count
|
||||
RedisClient.Set(gorush.IosErrorKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
func (s *Storage) addAndroidSuccess(count int64) {
|
||||
RedisClient.Set(gorush.AndroidSuccessKey, strconv.Itoa(int(count)), 0)
|
||||
total := s.getAndroidSuccess() + count
|
||||
RedisClient.Set(gorush.AndroidSuccessKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
func (s *Storage) addAndroidError(count int64) {
|
||||
RedisClient.Set(gorush.AndroidErrorKey, strconv.Itoa(int(count)), 0)
|
||||
total := s.getAndroidError() + count
|
||||
RedisClient.Set(gorush.AndroidErrorKey, strconv.Itoa(int(total)), 0)
|
||||
}
|
||||
|
||||
func (s *Storage) getTotalCount() int64 {
|
||||
|
|
|
@ -23,24 +23,28 @@ func TestRedisEngine(t *testing.T) {
|
|||
|
||||
redis := New(config, gorush.StatusApp{})
|
||||
redis.initRedis()
|
||||
redis.resetRedis()
|
||||
|
||||
redis.addTotalCount(1)
|
||||
redis.addTotalCount(10)
|
||||
val = redis.getTotalCount()
|
||||
assert.Equal(t, int64(1), val)
|
||||
assert.Equal(t, int64(10), val)
|
||||
redis.addTotalCount(10)
|
||||
val = redis.getTotalCount()
|
||||
assert.Equal(t, int64(20), val)
|
||||
|
||||
redis.addIosSuccess(2)
|
||||
redis.addIosSuccess(20)
|
||||
val = redis.getIosSuccess()
|
||||
assert.Equal(t, int64(2), val)
|
||||
assert.Equal(t, int64(20), val)
|
||||
|
||||
redis.addIosError(3)
|
||||
redis.addIosError(30)
|
||||
val = redis.getIosError()
|
||||
assert.Equal(t, int64(3), val)
|
||||
assert.Equal(t, int64(30), val)
|
||||
|
||||
redis.addAndroidSuccess(4)
|
||||
redis.addAndroidSuccess(40)
|
||||
val = redis.getAndroidSuccess()
|
||||
assert.Equal(t, int64(4), val)
|
||||
assert.Equal(t, int64(40), val)
|
||||
|
||||
redis.addAndroidError(5)
|
||||
redis.addAndroidError(50)
|
||||
val = redis.getAndroidError()
|
||||
assert.Equal(t, int64(5), val)
|
||||
assert.Equal(t, int64(50), val)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue