forked from bsm/redis-lock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
35 lines (29 loc) · 807 Bytes
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package lock
import "time"
// Options describe the options for the lock
type Options struct {
// The maximum duration to lock a key for
// Default: 5s
LockTimeout time.Duration
// The number of time the acquisition of a lock will be retried.
// Default: 0 = do not retry
RetryCount int
// RetryDelay is the amount of time to wait between retries.
// Default: 100ms
RetryDelay time.Duration
// TokenPrefix the redis lock key's value will set TokenPrefix + randomToken
// If we set token prefix as hostname + pid, we can know who get the locker
TokenPrefix string
}
func (o *Options) normalize() *Options {
if o.LockTimeout < 1 {
o.LockTimeout = 5 * time.Second
}
if o.RetryCount < 0 {
o.RetryCount = 0
}
if o.RetryDelay < 1 {
o.RetryDelay = 100 * time.Millisecond
}
return o
}