⬆️ dep(go): replace all interface{} to any, will not support on go < 1.18

This commit is contained in:
Inhere
2023-02-26 12:12:31 +08:00
parent e614e45317
commit 7c343a8e82
18 changed files with 109 additions and 105 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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 {

View File

@@ -99,6 +99,7 @@ func UnregisterAll(fn ...func(cache Cache)) int {
// SetDefName set default driver name.
// Deprecated
//
// 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)
}

View File

@@ -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
@@ -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...)
}

View File

@@ -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()

View File

@@ -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 {

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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")
}

View File

@@ -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 {

View File

@@ -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")
}

View File

@@ -59,6 +59,7 @@ func (m *Manager) Unregister(name string) int {
// SetDefName set default driver name. alias of DefaultUse()
// Deprecated
//
// 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)
}

View File

@@ -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

View File

@@ -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")
}

View File

@@ -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")
}