Documentation ¶
Index ¶
- Constants
- Variables
- func AddOptionParser(adapter string, parser func(cache.Options) (cache.Options, error))
- func AddTTL(a x.GetOption, ttl int64) x.GetOption
- func AdminRefreshable(ctx echo.Context, customer *dbschema.OfficialCustomer, ttl x.GetOption) x.GetOption
- func Cache(ctx context.Context, args ...string) cache.Cache
- func CacheNew(ctx context.Context, opts cache.Options, keys ...string) error
- func CloseCache()
- func Decr(ctx context.Context, key string, args ...string) error
- func Delete(ctx context.Context, key string, args ...string) error
- func Flush(ctx context.Context, args ...string) error
- func ForgetLock(key string, types ...LockType)
- func GenOptions(ctx echo.Context, cacheSeconds int64) []x.GetOption
- func Get(ctx context.Context, key string, recv interface{}, args ...string) error
- func GetTTLByNumber(ttl int64, b x.GetOption) x.GetOption
- func Incr(ctx context.Context, key string, args ...string) error
- func IsDbAccount(v string) bool
- func IsExist(ctx context.Context, key string, args ...string) (bool, error)
- func IsNotExist(err error) bool
- func NewDBCacher() *dbCacher
- func Put(ctx context.Context, key string, val interface{}, timeout int64, ...) error
- func RedisClient() *redis.Client
- func RedisMutex(key string, options ...redsync.Option) *redsync.Mutex
- func RedisOptions() *redis.Options
- func RedsyncClient() *redsync.Redsync
- func RegisterTryLocker(t LockType, fn TryLocker)
- func SetDefaultLockType(lockType LockType)
- func SingleflightDo(key string, fn func() (interface{}, error)) (v interface{}, err error, shared bool)
- func SingleflightDoChan(key string, fn func() (interface{}, error)) <-chan SinglefightResult
- func SingleflightForget(key string)
- func TTLIf(condition bool, a x.GetOption, b x.GetOption) x.GetOption
- func TTLIfCallback(condition func() bool, a x.GetOption, b x.GetOption) x.GetOption
- func XFunc(ctx context.Context, key string, recv interface{}, fn func() error, ...) error
- func XQuery(ctx context.Context, key string, recv interface{}, query x.Querier, ...) error
- type LockType
- type QueryFunc
- type ReloadableOptions
- type SinglefightResult
- type Singleflighter
- type TryLocker
- type UnlockFunc
- func Lock(key string, types ...LockType) (unlock UnlockFunc, err error)
- func TryLock(key string, types ...LockType) (unlock UnlockFunc, err error)
- func TryLockWithContext(key string, ctx context.Context, types ...LockType) (unlock UnlockFunc, err error)
- func TryLockWithTimeout(key string, timeout time.Duration, types ...LockType) (unlock UnlockFunc, err error)
Constants ¶
View Source
const ( CacheDisabled int64 = -1 // 禁用缓存 CacheFresh int64 = -2 // 强制缓存新数据 )
Variables ¶
View Source
var ( TTL = x.TTL Query = x.Query DisableCacheUsage = x.DisableCacheUsage UseFreshData = x.UseFreshData Disabled = DisableCacheUsage(true) // 禁用缓存 Fresh = UseFreshData(true) // 强制缓存新数据 Noop = func(o *x.Options) {} )
View Source
var DBCacher = NewDBCacher()
View Source
var ErrFailedToAcquireLock = errors.New("failed to acquire lock")
Functions ¶
func AddOptionParser ¶
func AdminRefreshable ¶
func CloseCache ¶
func CloseCache()
func ForgetLock ¶
func IsDbAccount ¶
func IsNotExist ¶
func NewDBCacher ¶
func NewDBCacher() *dbCacher
func RedisClient ¶
func RedisClient() *redis.Client
func RedisMutex ¶
func RedisMutex(key string, options ...redsync.Option) *redsync.Mutex
RedisMutex 分布式锁 example: mutex := RedisMutex(`goods_1`) err = mutex.Lock(ctx)
if err != nil { panic(err) }
mutex.Unlock(ctx)
func RedisOptions ¶
func RedisOptions() *redis.Options
func RedsyncClient ¶
func RedsyncClient() *redsync.Redsync
func RegisterTryLocker ¶
func SetDefaultLockType ¶
func SetDefaultLockType(lockType LockType)
func SingleflightDo ¶
func SingleflightDoChan ¶
func SingleflightDoChan(key string, fn func() (interface{}, error)) <-chan SinglefightResult
func SingleflightForget ¶
func SingleflightForget(key string)
func TTLIfCallback ¶
Types ¶
type ReloadableOptions ¶
func NewReloadableOptions ¶
func NewReloadableOptions() *ReloadableOptions
func (*ReloadableOptions) IsValid ¶
func (o *ReloadableOptions) IsValid() bool
func (*ReloadableOptions) Reload ¶
func (o *ReloadableOptions) Reload() error
type SinglefightResult ¶
type SinglefightResult = singleflight.Result
type Singleflighter ¶
type Singleflighter interface { Do(key string, fn func() (interface{}, error)) (v interface{}, err error, shared bool) DoChan(key string, fn func() (interface{}, error)) <-chan SinglefightResult Forget(key string) }
func NewSingleflight ¶
func NewSingleflight(mu TryLocker) Singleflighter
func Singleflight ¶
func Singleflight(types ...LockType) Singleflighter
type TryLocker ¶
type TryLocker interface { Lock(key string) (unlock UnlockFunc, err error) TryLock(key string) (unlock UnlockFunc, err error) TryLockWithTimeout(key string, timeout time.Duration) (unlock UnlockFunc, err error) TryLockWithContext(key string, ctx context.Context) (unlock UnlockFunc, err error) Forget(key string) }
Click to show internal directories.
Click to hide internal directories.