Skip to content

Commit

Permalink
return zero rather than redis nil error (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Wong authored May 14, 2021
1 parent c2472ea commit f7807bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion balance/handler/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ func (c *counter) decr(userID, path string, delta int64) (int64, error) {
}

func (c *counter) read(userID, path string) (int64, error) {
return c.redisClient.Get(context.Background(), fmt.Sprintf("%s:%s:%s", prefixCounter, userID, path)).Int64()
ret, err := c.redisClient.Get(context.Background(), fmt.Sprintf("%s:%s:%s", prefixCounter, userID, path)).Int64()
if err == redis.Nil {
return 0, nil
}
return ret, err
}

func (c *counter) reset(userID, path string) error {
Expand Down
6 changes: 5 additions & 1 deletion usage/handler/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func (c *counter) decr(userID, path string, delta int64, t time.Time) (int64, er

func (c *counter) read(userID, path string, t time.Time) (int64, error) {
t = t.UTC()
return c.redisClient.Get(context.Background(), fmt.Sprintf("%s:%s:%s:%s", prefixCounter, userID, t.Format("20060102"), path)).Int64()
ret, err := c.redisClient.Get(context.Background(), fmt.Sprintf("%s:%s:%s:%s", prefixCounter, userID, t.Format("20060102"), path)).Int64()
if err == redis.Nil {
return 0, nil
}
return ret, err
}

type listEntry struct {
Expand Down

0 comments on commit f7807bd

Please sign in to comment.