Skip to content

Commit

Permalink
feat: update cache
Browse files Browse the repository at this point in the history
  • Loading branch information
miaolz123 committed Jun 12, 2020
1 parent ca3f316 commit 81693d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package cache

import (
"time"

"github.com/go-redis/redis/v7"
)

var (
ErrNil = redis.Nil
DefaultCacher = NewMemoryCacher()
)

Expand Down
5 changes: 2 additions & 3 deletions cache/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cache
import (
"time"

"github.com/go-redis/redis/v7"
"github.com/gxxgle/go-utils/json"
"github.com/patrickmn/go-cache"
)
Expand Down Expand Up @@ -37,13 +36,13 @@ func (c *MemoryCacher) Set(key string, value interface{}, expiration time.Durati
func (c *MemoryCacher) Get(key string, value interface{}) error {
v, ok := c.Client.Get(key)
if !ok {
return redis.Nil
return ErrNil
}

bs, ok := v.([]byte)
if !ok {
c.Client.Delete(key)
return redis.Nil
return ErrNil
}

return json.Unmarshal(bs, value)
Expand Down

0 comments on commit 81693d5

Please sign in to comment.