diff --git a/README.md b/README.md index 58e1ca4..6042835 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,12 @@ All cache driver implemented the `cache.Cache` interface. So, You can add any cu type Cache interface { // basic operation Has(key string) bool - Get(key string) interface{} - Set(key string, val interface{}, ttl time.Duration) (err error) + Get(key string) any + Set(key string, val any, ttl time.Duration) (err error) Del(key string) error // multi operation - GetMulti(keys []string) map[string]interface{} - SetMulti(values map[string]interface{}, ttl time.Duration) (err error) + GetMulti(keys []string) map[string]any + SetMulti(values map[string]any, ttl time.Duration) (err error) DelMulti(keys []string) error // clear and close Clear() error diff --git a/README_cn.md b/README_cn.md index 80ada5f..6455ee3 100644 --- a/README_cn.md +++ b/README_cn.md @@ -55,12 +55,12 @@ go get github.com/gookit/cache type Cache interface { // basic op Has(key string) bool - Get(key string) interface{} - Set(key string, val interface{}, ttl time.Duration) (err error) + Get(key string) any + Set(key string, val any, ttl time.Duration) (err error) Del(key string) error // multi op - GetMulti(keys []string) map[string]interface{} - SetMulti(values map[string]interface{}, ttl time.Duration) (err error) + GetMulti(keys []string) map[string]any + SetMulti(values map[string]any, ttl time.Duration) (err error) DelMulti(keys []string) error // clear & close Clear() error diff --git a/badger/badger.go b/badger/badger.go index 1890039..e3cfc73 100644 --- a/badger/badger.go +++ b/badger/badger.go @@ -19,11 +19,11 @@ func (c *BadgerDB) Has(key string) bool { panic("implement me") } -func (c *BadgerDB) Get(key string) interface{} { +func (c *BadgerDB) Get(key string) any { panic("implement me") } -func (c *BadgerDB) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *BadgerDB) Set(key string, val any, ttl time.Duration) (err error) { panic("implement me") } @@ -31,11 +31,11 @@ func (c *BadgerDB) Del(key string) error { panic("implement me") } -func (c *BadgerDB) GetMulti(keys []string) map[string]interface{} { +func (c *BadgerDB) GetMulti(keys []string) map[string]any { panic("implement me") } -func (c *BadgerDB) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *BadgerDB) SetMulti(values map[string]any, ttl time.Duration) (err error) { panic("implement me") } diff --git a/boltdb/boltdb.go b/boltdb/boltdb.go index 60a5289..0ed8a5f 100644 --- a/boltdb/boltdb.go +++ b/boltdb/boltdb.go @@ -38,8 +38,8 @@ func (c *BoltDB) Has(key string) bool { } // Get value by key -func (c *BoltDB) Get(key string) interface{} { - var val interface{} +func (c *BoltDB) Get(key string) any { + var val any err := c.db.View(func(tx *bbolt.Tx) error { b := tx.Bucket([]byte(c.Bucket)) bs := b.Get([]byte(key)) @@ -58,7 +58,7 @@ func (c *BoltDB) Get(key string) interface{} { } // Set value by key -func (c *BoltDB) Set(key string, val interface{}, _ time.Duration) (err error) { +func (c *BoltDB) Set(key string, val any, _ time.Duration) (err error) { bts, err := c.MustMarshal(val) if err != nil { return @@ -77,12 +77,12 @@ func (c *BoltDB) Del(key string) error { } // GetMulti values by multi key -func (c *BoltDB) GetMulti(keys []string) map[string]interface{} { +func (c *BoltDB) GetMulti(keys []string) map[string]any { panic("implement me") } // SetMulti values by multi key -func (c *BoltDB) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *BoltDB) SetMulti(values map[string]any, ttl time.Duration) (err error) { panic("implement me") } diff --git a/buntdb/buntdb.go b/buntdb/buntdb.go index 0960b29..8157066 100644 --- a/buntdb/buntdb.go +++ b/buntdb/buntdb.go @@ -10,6 +10,7 @@ import ( // Name driver name const Name = "buntDB" + // Memory open a file that does not persist to disk. const Memory = ":memory:" @@ -65,8 +66,8 @@ func (c *BuntDB) Has(key string) bool { } // Get value by key -func (c *BuntDB) Get(key string) interface{} { - var val interface{} +func (c *BuntDB) Get(key string) any { + var val any err := c.db.View(func(tx *buntdb.Tx) error { str, err := tx.Get(key, false) if err != nil { @@ -83,7 +84,7 @@ func (c *BuntDB) Get(key string) interface{} { } // Set value by key -func (c *BuntDB) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *BuntDB) Set(key string, val any, ttl time.Duration) (err error) { bts, err := c.MustMarshal(val) if err != nil { return err @@ -110,8 +111,8 @@ func (c *BuntDB) Del(key string) error { } // GetMulti values by multi key -func (c *BuntDB) GetMulti(keys []string) map[string]interface{} { - results := make(map[string]interface{}, len(keys)) +func (c *BuntDB) GetMulti(keys []string) map[string]any { + results := make(map[string]any, len(keys)) err := c.db.View(func(tx *buntdb.Tx) error { for _, key := range keys { str, err := tx.Get(key, false) @@ -119,7 +120,7 @@ func (c *BuntDB) GetMulti(keys []string) map[string]interface{} { return err } - var val interface{} + var val any err = c.UnmarshalTo([]byte(str), &val) if err != nil { return err @@ -138,7 +139,7 @@ func (c *BuntDB) GetMulti(keys []string) map[string]interface{} { } // SetMulti values by multi key -func (c *BuntDB) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *BuntDB) SetMulti(values map[string]any, ttl time.Duration) (err error) { return c.db.Update(func(tx *buntdb.Tx) (err error) { opt := &buntdb.SetOptions{} if ttl > 0 { diff --git a/cache.go b/cache.go index 0a6ff1a..cfde649 100644 --- a/cache.go +++ b/cache.go @@ -99,7 +99,8 @@ func UnregisterAll(fn ...func(cache Cache)) int { // SetDefName set default driver name. // Deprecated -// please use DefaultUse() instead it +// +// please use DefaultUse() instead it func SetDefName(driverName string) { std.DefaultUse(driverName) } @@ -159,12 +160,12 @@ func Has(key string) bool { } // Get value by key -func Get(key string) interface{} { +func Get(key string) any { return std.Default().Get(key) } // Set value by key -func Set(key string, val interface{}, ttl time.Duration) error { +func Set(key string, val any, ttl time.Duration) error { return std.Default().Set(key, val, ttl) } @@ -174,12 +175,12 @@ func Del(key string) error { } // GetMulti values by keys -func GetMulti(keys []string) map[string]interface{} { +func GetMulti(keys []string) map[string]any { return std.Default().GetMulti(keys) } // SetMulti values -func SetMulti(mv map[string]interface{}, ttl time.Duration) error { +func SetMulti(mv map[string]any, ttl time.Duration) error { return std.Default().SetMulti(mv, ttl) } diff --git a/driver.go b/driver.go index 910e7da..2ea5dcf 100644 --- a/driver.go +++ b/driver.go @@ -9,10 +9,10 @@ import ( type ( // MarshalFunc define - MarshalFunc func(v interface{}) ([]byte, error) + MarshalFunc func(v any) ([]byte, error) // UnmarshalFunc define - UnmarshalFunc func(data []byte, v interface{}) error + UnmarshalFunc func(data []byte, v any) error ) // data (Un)marshal func @@ -20,7 +20,7 @@ var ( Marshal MarshalFunc = json.Marshal Unmarshal UnmarshalFunc = json.Unmarshal - errNoMarshal = errors.New("must set Marshal func") + errNoMarshal = errors.New("must set Marshal func") errNoUnmarshal = errors.New("must set Unmarshal func") ) @@ -47,21 +47,21 @@ type BaseDriver struct { // WithDebug add option: debug func WithDebug(debug bool) func(opt *Option) { - return func (opt *Option) { + return func(opt *Option) { opt.Debug = debug } } // WithEncode add option: encode func WithEncode(encode bool) func(opt *Option) { - return func (opt *Option) { + return func(opt *Option) { opt.Encode = encode } } // WithPrefix add option: prefix func WithPrefix(prefix string) func(opt *Option) { - return func (opt *Option) { + return func(opt *Option) { opt.Prefix = prefix } } @@ -74,7 +74,7 @@ func (l *BaseDriver) WithOptions(optFns ...func(option *Option)) { } // MustMarshal cache value -func (l *BaseDriver) MustMarshal(val interface{}) ([]byte, error) { +func (l *BaseDriver) MustMarshal(val any) ([]byte, error) { if Marshal == nil { return nil, errNoMarshal } @@ -82,7 +82,7 @@ func (l *BaseDriver) MustMarshal(val interface{}) ([]byte, error) { } // Marshal cache value -func (l *BaseDriver) Marshal(val interface{}) (interface{}, error) { +func (l *BaseDriver) Marshal(val any) (any, error) { if l.opt.Encode && Marshal != nil { return Marshal(val) } @@ -91,7 +91,7 @@ func (l *BaseDriver) Marshal(val interface{}) (interface{}, error) { } // UnmarshalTo cache value -func (l *BaseDriver) UnmarshalTo(bts []byte, ptr interface{}) error { +func (l *BaseDriver) UnmarshalTo(bts []byte, ptr any) error { if Unmarshal == nil { return errNoUnmarshal } @@ -99,13 +99,13 @@ func (l *BaseDriver) UnmarshalTo(bts []byte, ptr interface{}) error { } // Unmarshal cache value -func (l *BaseDriver) Unmarshal(val []byte, err error) interface{} { +func (l *BaseDriver) Unmarshal(val []byte, err error) any { if err != nil { l.SetLastErr(err) return nil } - var newV interface{} + var newV any if l.opt.Encode && Unmarshal != nil { err := Unmarshal(val, &newV) l.SetLastErr(err) @@ -129,23 +129,23 @@ func (l *BaseDriver) BuildKeys(keys []string) []string { return keys } - rks := make([]string,0, len(keys)) + rks := make([]string, 0, len(keys)) for _, key := range keys { - rks = append(rks, l.opt.Prefix + key) + rks = append(rks, l.opt.Prefix+key) } return rks } // Debugf print an debug message -func (l *BaseDriver) Debugf(format string, v ...interface{}) { +func (l *BaseDriver) Debugf(format string, v ...any) { if l.opt.Debug && l.opt.Logger != nil { l.opt.Logger.Printf(format, v...) } } // Logf print an log message -func (l *BaseDriver) Logf(format string, v ...interface{}) { +func (l *BaseDriver) Logf(format string, v ...any) { if l.opt.Logger != nil { l.opt.Logger.Printf(format, v...) } diff --git a/driver_file.go b/driver_file.go index ec8c539..beba85f 100644 --- a/driver_file.go +++ b/driver_file.go @@ -55,14 +55,14 @@ func (c *FileCache) Has(key string) bool { } // Get value by key -func (c *FileCache) Get(key string) interface{} { +func (c *FileCache) Get(key string) any { c.lock.RLock() defer c.lock.RUnlock() return c.get(key) } -func (c *FileCache) get(key string) interface{} { +func (c *FileCache) get(key string) any { // read cache from memory if val := c.MemoryCache.get(key); val != nil { return val @@ -92,14 +92,14 @@ func (c *FileCache) get(key string) interface{} { } // Set value by key -func (c *FileCache) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *FileCache) Set(key string, val any, ttl time.Duration) (err error) { c.lock.Lock() defer c.lock.Unlock() return c.set(key, val, ttl) } -func (c *FileCache) set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *FileCache) set(key string, val any, ttl time.Duration) (err error) { err = c.MemoryCache.set(key, val, ttl) if err != nil { return @@ -151,11 +151,11 @@ func (c *FileCache) del(key string) error { } // GetMulti values by multi key -func (c *FileCache) GetMulti(keys []string) map[string]interface{} { +func (c *FileCache) GetMulti(keys []string) map[string]any { c.lock.RLock() defer c.lock.RUnlock() - data := make(map[string]interface{}, len(keys)) + data := make(map[string]any, len(keys)) for _, key := range keys { data[key] = c.get(key) } @@ -164,7 +164,7 @@ func (c *FileCache) GetMulti(keys []string) map[string]interface{} { } // SetMulti values by multi key -func (c *FileCache) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *FileCache) SetMulti(values map[string]any, ttl time.Duration) (err error) { c.lock.Lock() defer c.lock.Unlock() diff --git a/driver_memory.go b/driver_memory.go index fa0f616..f731753 100644 --- a/driver_memory.go +++ b/driver_memory.go @@ -10,7 +10,7 @@ type Item struct { // Exp expire time Exp int64 // Val cache value storage - Val interface{} + Val any } // Expired check whether expired @@ -44,14 +44,14 @@ func (c *MemoryCache) Has(key string) bool { } // Get cache value by key -func (c *MemoryCache) Get(key string) interface{} { +func (c *MemoryCache) Get(key string) any { c.lock.RLock() defer c.lock.RUnlock() return c.get(key) } -func (c *MemoryCache) get(key string) interface{} { +func (c *MemoryCache) get(key string) any { if item, ok := c.caches[key]; ok { // check expire time. if has been expired, remove it. if item.Expired() { @@ -66,14 +66,14 @@ func (c *MemoryCache) get(key string) interface{} { } // Set cache value by key -func (c *MemoryCache) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *MemoryCache) Set(key string, val any, ttl time.Duration) (err error) { c.lock.Lock() defer c.lock.Unlock() return c.set(key, val, ttl) } -func (c *MemoryCache) set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *MemoryCache) set(key string, val any, ttl time.Duration) (err error) { item := &Item{Val: val} if ttl > 0 { item.Exp = time.Now().Unix() + int64(ttl/time.Second) @@ -100,10 +100,10 @@ func (c *MemoryCache) del(key string) error { } // GetMulti values by multi key -func (c *MemoryCache) GetMulti(keys []string) map[string]interface{} { +func (c *MemoryCache) GetMulti(keys []string) map[string]any { c.lock.RLock() - data := make(map[string]interface{}, len(keys)) + data := make(map[string]any, len(keys)) for _, key := range keys { data[key] = c.get(key) } @@ -113,7 +113,7 @@ func (c *MemoryCache) GetMulti(keys []string) map[string]interface{} { } // SetMulti values by multi key -func (c *MemoryCache) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *MemoryCache) SetMulti(values map[string]any, ttl time.Duration) (err error) { c.lock.Lock() for key, val := range values { if err = c.set(key, val, ttl); err != nil { diff --git a/gcache/gcache.go b/gcache/gcache.go index 638d3dc..af14ba3 100644 --- a/gcache/gcache.go +++ b/gcache/gcache.go @@ -45,13 +45,13 @@ func (g *GCache) Has(key string) bool { } // Get cache by key -func (g *GCache) Get(key string) interface{} { +func (g *GCache) Get(key string) any { val, _ := g.db.Get(key) return val } // Set cache by key -func (g *GCache) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (g *GCache) Set(key string, val any, ttl time.Duration) (err error) { return g.db.SetWithExpire(key, val, ttl) } @@ -62,8 +62,8 @@ func (g *GCache) Del(key string) error { } // GetMulti cache by keys -func (g *GCache) GetMulti(keys []string) map[string]interface{} { - data := make(map[string]interface{}, len(keys)) +func (g *GCache) GetMulti(keys []string) map[string]any { + data := make(map[string]any, len(keys)) for _, key := range keys { val, err := g.db.Get(key) @@ -76,7 +76,7 @@ func (g *GCache) GetMulti(keys []string) map[string]interface{} { } // SetMulti cache by keys -func (g *GCache) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (g *GCache) SetMulti(values map[string]any, ttl time.Duration) (err error) { for key, val := range values { err = g.db.SetWithExpire(key, val, ttl) } diff --git a/gocache/gocache.go b/gocache/gocache.go index 5d2475d..4b0f070 100644 --- a/gocache/gocache.go +++ b/gocache/gocache.go @@ -2,6 +2,7 @@ // base on the package: github.com/patrickmn/go-cache // // Usage: +// // import "github.com/gookit/cache" // // cache.Register(gocache.NewGoCache(0, cache.FiveMinutes)) @@ -63,7 +64,7 @@ func (g *GoCache) Has(key string) bool { } // Get cache by key -func (g *GoCache) Get(key string) interface{} { +func (g *GoCache) Get(key string) any { if g.expireManually { g.db.DeleteExpired() } @@ -73,7 +74,7 @@ func (g *GoCache) Get(key string) interface{} { } // Set cache by key -func (g *GoCache) Set(key string, val interface{}, ttl time.Duration) error { +func (g *GoCache) Set(key string, val any, ttl time.Duration) error { g.db.Set(key, val, ttl) return nil } @@ -85,8 +86,8 @@ func (g GoCache) Del(key string) error { } // GetMulti cache by keys -func (g *GoCache) GetMulti(keys []string) map[string]interface{} { - data := make(map[string]interface{}, len(keys)) +func (g *GoCache) GetMulti(keys []string) map[string]any { + data := make(map[string]any, len(keys)) for _, key := range keys { val, ok := g.db.Get(key) @@ -99,7 +100,7 @@ func (g *GoCache) GetMulti(keys []string) map[string]interface{} { } // SetMulti cache by keys -func (g GoCache) SetMulti(values map[string]interface{}, ttl time.Duration) error { +func (g GoCache) SetMulti(values map[string]any, ttl time.Duration) error { for key, val := range values { g.db.Set(key, val, ttl) } diff --git a/goredis/goredis.go b/goredis/goredis.go index f92e431..3c9d88e 100644 --- a/goredis/goredis.go +++ b/goredis/goredis.go @@ -100,14 +100,14 @@ func (c *GoRedis) Has(key string) bool { } // Get cache by key -func (c *GoRedis) Get(key string) interface{} { +func (c *GoRedis) Get(key string) any { bts, err := c.rdb.Get(c.ctx, c.Key(key)).Bytes() return c.Unmarshal(bts, err) } // GetAs get cache and unmarshal to ptr -func (c *GoRedis) GetAs(key string, ptr interface{}) error { +func (c *GoRedis) GetAs(key string, ptr any) error { bts, err := c.rdb.Get(c.ctx, c.Key(key)).Bytes() if err != nil { return err @@ -117,7 +117,7 @@ func (c *GoRedis) GetAs(key string, ptr interface{}) error { } // Set cache by key -func (c *GoRedis) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *GoRedis) Set(key string, val any, ttl time.Duration) (err error) { val, err = c.Marshal(val) if err != nil { return err @@ -132,12 +132,12 @@ func (c *GoRedis) Del(key string) error { } // GetMulti cache by keys -func (c *GoRedis) GetMulti(keys []string) map[string]interface{} { +func (c *GoRedis) GetMulti(keys []string) map[string]any { panic("implement me") } // SetMulti cache by keys -func (c *GoRedis) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *GoRedis) SetMulti(values map[string]any, ttl time.Duration) (err error) { panic("implement me") } diff --git a/helper.go b/helper.go index b24ea63..e1a85be 100644 --- a/helper.go +++ b/helper.go @@ -6,13 +6,13 @@ import ( ) // BindStruct get cache value and map to a struct -func BindStruct(val interface{}, ptr interface{}) error { +func BindStruct(val any, ptr any) error { // val must convert to byte return Unmarshal(val.([]byte), ptr) } // GobDecode decode data by gob.Decode -func GobDecode(bts []byte, ptr interface{}) error { +func GobDecode(bts []byte, ptr any) error { buf := bytes.NewBuffer(bts) dec := gob.NewDecoder(buf) @@ -20,7 +20,7 @@ func GobDecode(bts []byte, ptr interface{}) error { } // GobEncode encode data by gob.Encode -func GobEncode(val interface{}) (bs []byte, err error) { +func GobEncode(val any) (bs []byte, err error) { buf := new(bytes.Buffer) enc := gob.NewEncoder(buf) if err = enc.Encode(val); err != nil { diff --git a/leveldb/leveldb.go b/leveldb/leveldb.go index 56aef77..978727e 100644 --- a/leveldb/leveldb.go +++ b/leveldb/leveldb.go @@ -20,11 +20,11 @@ func (c *LevelDB) Has(key string) bool { panic("implement me") } -func (c *LevelDB) Get(key string) interface{} { +func (c *LevelDB) Get(key string) any { panic("implement me") } -func (c *LevelDB) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *LevelDB) Set(key string, val any, ttl time.Duration) (err error) { panic("implement me") } @@ -32,11 +32,11 @@ func (c *LevelDB) Del(key string) error { panic("implement me") } -func (c *LevelDB) GetMulti(keys []string) map[string]interface{} { +func (c *LevelDB) GetMulti(keys []string) map[string]any { panic("implement me") } -func (c *LevelDB) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *LevelDB) SetMulti(values map[string]any, ttl time.Duration) (err error) { panic("implement me") } diff --git a/manager.go b/manager.go index b56872e..5fe016a 100644 --- a/manager.go +++ b/manager.go @@ -59,7 +59,8 @@ func (m *Manager) Unregister(name string) int { // SetDefName set default driver name. alias of DefaultUse() // Deprecated -// please use DefaultUse() instead it +// +// please use DefaultUse() instead it func (m *Manager) SetDefName(driverName string) { m.DefaultUse(driverName) } @@ -145,12 +146,12 @@ func (m *Manager) Has(key string) bool { } // Get value by key -func (m *Manager) Get(key string) interface{} { +func (m *Manager) Get(key string) any { return m.Default().Get(key) } // Set value by key -func (m *Manager) Set(key string, val interface{}, ttl time.Duration) error { +func (m *Manager) Set(key string, val any, ttl time.Duration) error { return m.Default().Set(key, val, ttl) } @@ -160,12 +161,12 @@ func (m *Manager) Del(key string) error { } // GetMulti values by keys -func (m *Manager) GetMulti(keys []string) map[string]interface{} { +func (m *Manager) GetMulti(keys []string) map[string]any { return m.Default().GetMulti(keys) } // SetMulti values -func (m *Manager) SetMulti(mv map[string]interface{}, ttl time.Duration) error { +func (m *Manager) SetMulti(mv map[string]any, ttl time.Duration) error { return m.Default().SetMulti(mv, ttl) } diff --git a/memcached/memcached.go b/memcached/memcached.go index c6ac3e2..0d7f2a9 100644 --- a/memcached/memcached.go +++ b/memcached/memcached.go @@ -47,7 +47,7 @@ func (c *MemCached) Has(key string) bool { } // Get value by key -func (c *MemCached) Get(key string) (val interface{}) { +func (c *MemCached) Get(key string) (val any) { item, err := c.client.Get(c.Key(key)) if err != nil { return @@ -61,7 +61,7 @@ func (c *MemCached) Get(key string) (val interface{}) { } // Set value by key -func (c *MemCached) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *MemCached) Set(key string, val any, ttl time.Duration) (err error) { bts, err := c.MustMarshal(val) if err != nil { return err @@ -81,7 +81,7 @@ func (c *MemCached) Del(key string) error { } // GetMulti values by multi key -func (c *MemCached) GetMulti(keys []string) map[string]interface{} { +func (c *MemCached) GetMulti(keys []string) map[string]any { keys = c.BuildKeys(keys) items, err := c.client.GetMulti(keys) @@ -89,9 +89,9 @@ func (c *MemCached) GetMulti(keys []string) map[string]interface{} { return nil } - values := make(map[string]interface{}, len(keys)) + values := make(map[string]any, len(keys)) for key, item := range items { - var val interface{} + var val any if err := c.UnmarshalTo(item.Value, &val); err != nil { continue } @@ -103,7 +103,7 @@ func (c *MemCached) GetMulti(keys []string) map[string]interface{} { } // SetMulti values by multi key -func (c *MemCached) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *MemCached) SetMulti(values map[string]any, ttl time.Duration) (err error) { for key, val := range values { if err = c.Set(c.Key(key), val, ttl); err != nil { return diff --git a/nutsdb/nutsdb.go b/nutsdb/nutsdb.go index 9451ee3..dd1447a 100644 --- a/nutsdb/nutsdb.go +++ b/nutsdb/nutsdb.go @@ -17,11 +17,11 @@ func (c *NutsDB) Has(key string) bool { panic("implement me") } -func (c *NutsDB) Get(key string) interface{} { +func (c *NutsDB) Get(key string) any { panic("implement me") } -func (c *NutsDB) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *NutsDB) Set(key string, val any, ttl time.Duration) (err error) { panic("implement me") } @@ -29,11 +29,11 @@ func (c *NutsDB) Del(key string) error { panic("implement me") } -func (c *NutsDB) GetMulti(keys []string) map[string]interface{} { +func (c *NutsDB) GetMulti(keys []string) map[string]any { panic("implement me") } -func (c *NutsDB) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *NutsDB) SetMulti(values map[string]any, ttl time.Duration) (err error) { panic("implement me") } diff --git a/redis/redigo.go b/redis/redigo.go index 036de31..be20a5f 100644 --- a/redis/redigo.go +++ b/redis/redigo.go @@ -56,14 +56,14 @@ func (c *Redigo) Connect() *Redigo { *************************************************************/ // Get value by key -func (c *Redigo) Get(key string) interface{} { +func (c *Redigo) Get(key string) any { bts, err := redis.Bytes(c.exec("Get", c.Key(key))) return c.Unmarshal(bts, err) } // GetAs get cache and unmarshal to ptr -func (c *Redigo) GetAs(key string, ptr interface{}) error { +func (c *Redigo) GetAs(key string, ptr any) error { bts, err := redis.Bytes(c.exec("Get", c.Key(key))) if err != nil { return err @@ -73,7 +73,7 @@ func (c *Redigo) GetAs(key string, ptr interface{}) error { } // Set value by key -func (c *Redigo) Set(key string, val interface{}, ttl time.Duration) (err error) { +func (c *Redigo) Set(key string, val any, ttl time.Duration) (err error) { val, err = c.Marshal(val) if err != nil { return err @@ -99,11 +99,11 @@ func (c *Redigo) Has(key string) bool { } // GetMulti values by keys -func (c *Redigo) GetMulti(keys []string) map[string]interface{} { +func (c *Redigo) GetMulti(keys []string) map[string]any { conn := c.pool.Get() defer conn.Close() - args := make([]interface{}, 0, len(keys)) + args := make([]any, 0, len(keys)) for _, key := range keys { args = append(args, c.Key(key)) } @@ -114,7 +114,7 @@ func (c *Redigo) GetMulti(keys []string) map[string]interface{} { return nil } - values := make(map[string]interface{}, len(keys)) + values := make(map[string]any, len(keys)) for i, val := range list { values[keys[i]] = val } @@ -123,7 +123,7 @@ func (c *Redigo) GetMulti(keys []string) map[string]interface{} { } // SetMulti values -func (c *Redigo) SetMulti(values map[string]interface{}, ttl time.Duration) (err error) { +func (c *Redigo) SetMulti(values map[string]any, ttl time.Duration) (err error) { conn := c.pool.Get() defer conn.Close() @@ -146,7 +146,7 @@ func (c *Redigo) SetMulti(values map[string]interface{}, ttl time.Duration) (err // DelMulti values by keys func (c *Redigo) DelMulti(keys []string) (err error) { - args := make([]interface{}, 0, len(keys)) + args := make([]any, 0, len(keys)) for _, key := range keys { args = append(args, c.Key(key)) } @@ -186,7 +186,7 @@ func (c *Redigo) String() string { } // actually do the redis cmds, args[0] must be the key name. -func (c *Redigo) exec(commandName string, args ...interface{}) (reply interface{}, err error) { +func (c *Redigo) exec(commandName string, args ...any) (reply any, err error) { if len(args) < 1 { return nil, errors.New("missing required arguments") }