Skip to content

Commit

Permalink
cache interface
Browse files Browse the repository at this point in the history
  • Loading branch information
soup-zhang committed Aug 8, 2019
1 parent e33fbfe commit b6e9135
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
16 changes: 8 additions & 8 deletions examples/cache/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ func NewFile(fileFullPath string) (*File, error) {
return file, err
}

func (f *File) Get(key string) (interface{}, error) {
func (f *File) Get(key string) (string, error) {
is, err := f.IsExist(key)
if err != nil {
return nil, err
return "", err
}
if is {
v, ok := f.data.Str[key]
if ok {
return v.Value, nil
return v.Value.(string), nil
}
}
return nil, err
return "", err
}

func (f *File) Set(key string, val interface{}, t time.Duration) error {
func (f *File) Set(key string, val interface{}, t ...time.Duration) error {
val = changeType(val)
it := nowTimeAdd2Nano(t)
if t == 0 {
it = 0
var it int64
if len(t) == 1 {
it = nowTimeAdd2Nano(t[0])
}

f.data.Str[key] = baseAttr{
Expand Down
12 changes: 7 additions & 5 deletions examples/cache/redisCluster.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cache

import (
"fmt"
"github.com/go-redis/redis"
"time"
)
Expand All @@ -23,13 +22,16 @@ func NewRedisCluster(redis2 *RedisCluster) (*RedisCluster, error) {
return redis2, err
}

func (r *RedisCluster) Get(key string) (interface{}, error) {
fmt.Println("ttttt",key)
func (r *RedisCluster) Get(key string) (string, error) {
return r.redisClusterClient.Get(key).Result()
}

func (r *RedisCluster) Set(key string, val interface{}, t time.Duration) error {
return r.redisClusterClient.Set(key, val, t).Err()
func (r *RedisCluster) Set(key string, val interface{}, t ...time.Duration) error {
var exp time.Duration
if len(t) == 1 {
exp = t[0]
}
return r.redisClusterClient.Set(key, val, exp).Err()
}

func (r *RedisCluster) IsExist(key string) (bool, error) {
Expand Down

0 comments on commit b6e9135

Please # to comment.