Documentation ¶
Index ¶
- Constants
- Variables
- func IsConnError(err error) bool
- func Log() golog.LoggerInterface
- func NewRedisSentinelModeConfig(redisHost string, redisDB int, redisPass string, masterName string) *kv.MyRedisConf
- func NewRedisSingleModeConfig(redisHost string, redisDB int, redisPass string) *kv.MyRedisConf
- func SetDebug()
- func SetLogLevel(level Level)
- type Level
- type Lock
- type LockFactory
- type LockFactoryCore
Constants ¶
View Source
const ( DEBUG = golog.DebugLevel INFO = golog.InfoLevel WARN = golog.WarnLevel ERROR = golog.ErrorLevel )
Variables ¶
View Source
var (
LockEmptyError = errors.New("lock empty")
)
View Source
var (
Logger = golog.New()
)
Logger Global logger config for debug
View Source
var NewRedisPool = kv.NewRedis
NewRedisPool make a redis pool
Functions ¶
func IsConnError ¶ added in v1.1.1
func NewRedisSentinelModeConfig ¶
func NewRedisSentinelModeConfig(redisHost string, redisDB int, redisPass string, masterName string) *kv.MyRedisConf
NewRedisSentinelModeConfig redis sentinel mode config redisHost is sentinel address, not redis address redisPass is redis password
func NewRedisSingleModeConfig ¶
func NewRedisSingleModeConfig(redisHost string, redisDB int, redisPass string) *kv.MyRedisConf
NewRedisSingleModeConfig redis single mode config
Types ¶
type Lock ¶
type Lock struct { // lock time CreateMillSecondTime int64 // lock live time, TTL LiveMillSecondTime int // if isKeepAlive, the last time refresh lock live time LastKeepAliveMillSecondTime int64 // unlock time UnlockMillSecondTime int64 // resource you lock ResourceName string // unique key of resource lock RandomKey string // when lock is unlock, will make chan signal, keepAlive find it unlock or call UnLock() IsUnlock bool // call UnLock() will set to true IsClose bool // the lock is open keep alive OpenKeepAlive bool // contains filtered or unexported fields }
Lock Redis lock
func (*Lock) Done ¶
func (lock *Lock) Done() chan struct{}
Done judge lock is whether release one example is:
lockFactory.SetKeepAlive(true).SetRetryCount(-1) lock, _ := lockFactory.Lock(context.Background(), resourceName, expireMillSecond) if lock != nil { crontab = true } select { case <- lock.Done(): crontab = false }
very useful for crontab work
type LockFactory ¶
type LockFactory interface { SetRetryCount(c int64) LockFactory GetRetryCount() int64 SetUnLockRetryCount(c int64) LockFactory GetUnLockRetryCount() int64 SetKeepAlive(isKeepAlive bool) LockFactory IsKeepAlive() bool SetRetryMillSecondDelay(c int64) LockFactory GetRetryMillSecondDelay() int64 SetUnLockRetryMillSecondDelay(c int64) LockFactory GetUnLockRetryMillSecondDelay() int64 LockFactoryCore }
LockFactory is main interface
func New ¶
func New(pool *redis.Pool) LockFactory
New make a redis lock factory call NewRedisSingleModeConfig and NewRedisSentinelModeConfig then call NewRedisPool you can also call kv.NewRedis for diy redis pool
func NewByRedisConfig ¶
func NewByRedisConfig(redisConf *kv.MyRedisConf) (LockFactory, error)
NewByRedisConfig One step do everyThing
type LockFactoryCore ¶
type LockFactoryCore interface { // Lock ,lock resource default keepAlive depend on LockFactory Lock(ctx context.Context, resourceName string, lockMillSecond int) (lock *Lock, err error) // LockForceKeepAlive lock resource force keepAlive LockForceKeepAlive(ctx context.Context, resourceName string, lockMillSecond int) (lock *Lock, err error) // LockForceNotKeepAlive lock resource force not keepAlive LockForceNotKeepAlive(ctx context.Context, resourceName string, lockMillSecond int) (lock *Lock, err error) // UnLock ,unlock resource UnLock(ctx context.Context, lock *Lock) (isUnLock bool, err error) // Done asynchronous see lock whether is release Done(lock *Lock) chan struct{} }
LockFactoryCore is core interface
Click to show internal directories.
Click to hide internal directories.