diff --git a/examples/cache/file.go b/examples/cache/file.go index 37b20af..1ab1072 100644 --- a/examples/cache/file.go +++ b/examples/cache/file.go @@ -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{ diff --git a/examples/cache/redisCluster.go b/examples/cache/redisCluster.go index 114f0ec..c4fe071 100644 --- a/examples/cache/redisCluster.go +++ b/examples/cache/redisCluster.go @@ -1,7 +1,6 @@ package cache import ( - "fmt" "github.com/go-redis/redis" "time" ) @@ -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) {