You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/consts/ckey"
|
|
"fmt"
|
|
"gits.branchcn.com/backend/microcode/plugins/derivative/bucket"
|
|
"gits.branchcn.com/backend/microcode/plugins/derivative/lock"
|
|
"gits.branchcn.com/backend/microcode/plugins/derivative/progress"
|
|
"gits.branchcn.com/backend/microcode/plugins/derivative/task"
|
|
"gits.branchcn.com/backend/microcode/plugins/derivative/vercontrol"
|
|
"sync"
|
|
)
|
|
|
|
type SubLock struct {
|
|
once sync.Once
|
|
lock *lock.SubLock
|
|
}
|
|
|
|
var subLock = &SubLock{}
|
|
|
|
// InitSubLock 初始化关注锁
|
|
func InitSubLock() {
|
|
subLock.once.Do(func() {
|
|
subLock.lock = lock.NewSubLock(context.Background(), Redis.Cache, ckey.SubLockCommon(), lock.SetLogger(RedisLog{}))
|
|
})
|
|
}
|
|
|
|
// NewFollower redis订阅锁记录
|
|
func NewFollower(ctx context.Context, key string, opts ...lock.Option) *lock.Follower {
|
|
return subLock.lock.NewFollower(ctx, key, opts...)
|
|
}
|
|
|
|
// NewRedisLock redis锁记录
|
|
func NewRedisLock(ctx context.Context, key string, opts ...lock.Option) *lock.RedisLock {
|
|
return lock.NewRedisLock(ctx, Redis.Cache, key, opts...)
|
|
}
|
|
|
|
// NewLastingBucket redis桶
|
|
func NewLastingBucket(ctx context.Context, key string, val bucket.Value, opts ...bucket.LastingOption) *bucket.LastingBucket {
|
|
return bucket.NewLastingBucket(ctx, Redis.Cache, key, val, opts...)
|
|
}
|
|
|
|
// NewRedisProgress redis进度
|
|
func NewRedisProgress(ctx context.Context, key string, opts ...progress.Option) *progress.Progress {
|
|
return progress.NewRedisProgress(ctx, Redis.Cache, key, opts...)
|
|
}
|
|
|
|
// NewRedisTask redis任务
|
|
func NewRedisTask(ctx context.Context, key string) *task.RedisTask {
|
|
return task.NewRedisTask(ctx, Redis.Cache, key)
|
|
}
|
|
|
|
// NewVerControl redis版本
|
|
func NewVerControl(ctx context.Context, key string, opts ...vercontrol.Option) *vercontrol.VerControl {
|
|
return vercontrol.NewRedisVerControl(ctx, Redis.Cache, key, opts...)
|
|
}
|
|
|
|
type RedisLog struct {
|
|
}
|
|
|
|
func (RedisLog) Print(ctx context.Context, format string, args ...interface{}) {
|
|
Logger.Info(ctx, fmt.Sprintf(format, args...))
|
|
}
|
|
func (RedisLog) Panic(ctx context.Context, format string, args ...interface{}) {
|
|
Logger.Error(ctx, fmt.Sprintf(format, args...))
|
|
}
|