1 Star 0 Fork 0

carlmax_my/console-core-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
store.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
carlmax_my 提交于 2024-12-02 21:32 . init project
package general_scope
import (
"time"
"gitee.com/carlmax_my/console-core-go/pkg/cache"
"gitee.com/carlmax_my/console-core-go/pkg/cache/scope"
)
type IGeneralScopeStore[T interface{}] interface {
Set(key, scope string, m *T) error
Get(key, scope string) (*T, error)
Del(key, scope string) (int64, error)
Exists(key, scope string) (bool, error)
CheckGet(key, scope string) (*T, error)
}
type GeneralScopeStore[T interface{}] struct {
scope.ScopeBaseStore
}
func NewWithTTL[T interface{}](cache cache.Cache, keyFunc scope.KeyFunc, ttl time.Duration) (IGeneralScopeStore[T], error) {
tenantStore, _ := scope.NewWithTTL(cache, keyFunc, ttl)
return &GeneralScopeStore[T]{
*tenantStore,
}, nil
}
func New[T interface{}](cache cache.Cache, keyFunc scope.KeyFunc) (IGeneralScopeStore[T], error) {
tenantStore, _ := scope.New(cache, keyFunc)
return &GeneralScopeStore[T]{
*tenantStore,
}, nil
}
func (s *GeneralScopeStore[T]) Set(key, scope string, m *T) error {
return s.SetModel(key, scope, m)
}
func (s *GeneralScopeStore[T]) Get(key, scope string) (*T, error) {
m := new(T)
if err := s.GetModel(key, scope, m); err != nil {
return nil, err
}
return m, nil
}
func (s *GeneralScopeStore[T]) CheckGet(key, scope string) (*T, error) {
m := new(T)
if err := s.CheckGetModel(key, scope, m); err != nil {
return nil, err
}
return m, nil
}
func (s *GeneralScopeStore[T]) Del(key, scope string) (int64, error) {
return s.ScopeBaseStore.Del(key, scope)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/carlmax_my/console-core-go.git
git@gitee.com:carlmax_my/console-core-go.git
carlmax_my
console-core-go
console-core-go
v0.0.17

搜索帮助