github.com/godaddy-x/freego@v1.0.156/cache/cache.go (about) 1 package cache 2 3 import ( 4 "github.com/godaddy-x/freego/utils" 5 ) 6 7 // 缓存管理器 8 type CacheManager struct{} 9 10 /********************************** 缓存接口定义 **********************************/ 11 12 type PutObj struct { 13 Key string 14 Value interface{} 15 Expire int 16 } 17 18 // 缓存定义接口接口 19 type Cache interface { 20 // 查询 21 Get(key string, input interface{}) (interface{}, bool, error) 22 GetInt64(key string) (int64, error) 23 GetFloat64(key string) (float64, error) 24 GetString(key string) (string, error) 25 GetBytes(key string) ([]byte, error) 26 GetBool(key string) (bool, error) 27 // 保存/过期时间(秒) 28 Put(key string, input interface{}, expire ...int) error 29 // 批量保存/过期时间(秒) 30 PutBatch(objs ...*PutObj) error 31 // 删除 32 Del(input ...string) error 33 // 查询全部key数量 34 Size(pattern ...string) (int, error) 35 // 查询全部key 36 Keys(pattern ...string) ([]string, error) 37 // 查询全部key 38 Values(pattern ...string) ([]interface{}, error) 39 // 查询key是否存在 40 Exists(key string) (bool, error) 41 // 查询队列数据 42 Brpop(key string, expire int64, result interface{}) error 43 BrpopString(key string, expire int64) (string, error) 44 BrpopInt64(key string, expire int64) (int64, error) 45 BrpopFloat64(key string, expire int64) (float64, error) 46 BrpopBool(key string, expire int64) (bool, error) 47 // 发送队列数据 48 Rpush(key string, val interface{}) error 49 // 发送订阅数据 50 Publish(key string, val interface{}, try ...int) (bool, error) 51 // 监听订阅数据 52 Subscribe(key string, timeout int, call func(msg string) (bool, error)) error 53 // 发送lua脚本 54 LuaScript(script string, key []string, val ...interface{}) (interface{}, error) 55 // 清空全部key-value 56 Flush() error 57 } 58 59 func (self *CacheManager) Get(key string, input interface{}) (interface{}, bool, error) { 60 return nil, false, utils.Error("No implementation method [Get] was found") 61 } 62 63 func (self *CacheManager) GetInt64(key string) (int64, error) { 64 return 0, utils.Error("No implementation method [GetInt64] was found") 65 } 66 67 func (self *CacheManager) GetFloat64(key string) (float64, error) { 68 return 0, utils.Error("No implementation method [GetFloat64] was found") 69 } 70 71 func (self *CacheManager) GetBytes(key string) ([]byte, error) { 72 return nil, utils.Error("No implementation method [GetBytes] was found") 73 } 74 75 func (self *CacheManager) GetString(key string) (string, error) { 76 return "", utils.Error("No implementation method [GetString] was found") 77 } 78 79 func (self *CacheManager) GetBool(key string) (bool, error) { 80 return false, utils.Error("No implementation method [GetBool] was found") 81 } 82 83 func (self *CacheManager) Put(key string, input interface{}, expire ...int) error { 84 return utils.Error("No implementation method [Put] was found") 85 } 86 87 func (self *CacheManager) PutBatch(objs ...*PutObj) error { 88 return utils.Error("No implementation method [PutBatch] was found") 89 } 90 91 func (self *CacheManager) Del(key ...string) error { 92 return utils.Error("No implementation method [Del] was found") 93 } 94 95 func (self *CacheManager) Size(pattern ...string) (int, error) { 96 return 0, utils.Error("No implementation method [Size] was found") 97 } 98 99 func (self *CacheManager) Keys(pattern ...string) ([]string, error) { 100 return nil, utils.Error("No implementation method [Keys] was found") 101 } 102 103 func (self *CacheManager) Values(pattern ...string) ([]interface{}, error) { 104 return nil, utils.Error("No implementation method [Values] was found") 105 } 106 107 func (self *CacheManager) Exists(key string) (bool, error) { 108 return false, utils.Error("No implementation method [Exists] was found") 109 } 110 111 func (self *CacheManager) Flush() error { 112 return utils.Error("No implementation method [Flush] was found") 113 } 114 115 func (self *CacheManager) Brpop(key string, expire int64, result interface{}) error { 116 return utils.Error("No implementation method [Brpop] was found") 117 } 118 119 func (self *CacheManager) BrpopString(key string, expire int64) (string, error) { 120 return "", utils.Error("No implementation method [BrpopString] was found") 121 } 122 123 func (self *CacheManager) BrpopInt64(key string, expire int64) (int64, error) { 124 return 0, utils.Error("No implementation method [BrpopInt64] was found") 125 } 126 127 func (self *CacheManager) BrpopFloat64(key string, expire int64) (float64, error) { 128 return 0, utils.Error("No implementation method [BrpopFloat64] was found") 129 } 130 131 func (self *CacheManager) BrpopBool(key string, expire int64) (bool, error) { 132 return false, utils.Error("No implementation method [BrpopBool] was found") 133 } 134 135 func (self *CacheManager) Rpush(key string, val interface{}) error { 136 return utils.Error("No implementation method [Rpush] was found") 137 } 138 139 func (self *CacheManager) Publish(key string, val interface{}, try ...int) (bool, error) { 140 return false, utils.Error("No implementation method [Publish] was found") 141 } 142 143 // exp second 144 func (self *CacheManager) Subscribe(key string, timeout int, call func(msg string) (bool, error)) error { 145 return utils.Error("No implementation method [Subscribe] was found") 146 } 147 148 func (self *CacheManager) LuaScript(script string, key []string, val ...interface{}) (interface{}, error) { 149 return nil, utils.Error("No implementation method [LuaScript] was found") 150 }