File tree Expand file tree Collapse file tree 4 files changed +13
-15
lines changed Expand file tree Collapse file tree 4 files changed +13
-15
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ func (p *mysqlProvider) init() error {
63
63
return nil
64
64
}
65
65
66
- func (p * mysqlProvider ) Lock (lock LockInfo ) error {
66
+ func (p * mysqlProvider ) Lock (lock NamedLock ) error {
67
67
now := time .Now ()
68
68
expireAt := now .Add (lock .GetLifetime ())
69
69
rs , err := p .lockStmt .Exec (
@@ -86,7 +86,7 @@ func (p *mysqlProvider) Lock(lock LockInfo) error {
86
86
return nil
87
87
}
88
88
89
- func (p * mysqlProvider ) Unlock (lock LockInfo ) error {
89
+ func (p * mysqlProvider ) Unlock (lock NamedLock ) error {
90
90
rs , err := p .unlockStmt .Exec (
91
91
lock .GetLockId (),
92
92
lock .GetLockOwner (),
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ func (p *postgreSQLProvider) init() error {
56
56
return nil
57
57
}
58
58
59
- func (p * postgreSQLProvider ) Lock (lock LockInfo ) error {
59
+ func (p * postgreSQLProvider ) Lock (lock NamedLock ) error {
60
60
now := time .Now ()
61
61
expireAt := now .Add (lock .GetLifetime ())
62
62
rs , err := p .lockStmt .Exec (
@@ -72,14 +72,13 @@ func (p *postgreSQLProvider) Lock(lock LockInfo) error {
72
72
if err != nil {
73
73
return fmt .Errorf ("get affected rows: %w" , err )
74
74
}
75
- println ("lock affected:" , affected )
76
75
if affected == 0 {
77
76
return ErrAlreadyLocked
78
77
}
79
78
return nil
80
79
}
81
80
82
- func (p * postgreSQLProvider ) Unlock (lock LockInfo ) error {
81
+ func (p * postgreSQLProvider ) Unlock (lock NamedLock ) error {
83
82
rs , err := p .unlockStmt .Exec (
84
83
lock .GetLockId (),
85
84
lock .GetLockOwner (),
@@ -92,7 +91,6 @@ func (p *postgreSQLProvider) Unlock(lock LockInfo) error {
92
91
if err != nil {
93
92
return fmt .Errorf ("get affected rows: %w" , err )
94
93
}
95
- println ("unlock affected:" , affected )
96
94
if affected == 0 {
97
95
return ErrNotLocked
98
96
}
Original file line number Diff line number Diff line change @@ -2,16 +2,16 @@ package distlock
2
2
3
3
import "time"
4
4
5
- type LockInfo interface {
5
+ type NamedLock interface {
6
6
GetLockId () string
7
7
GetLockOwner () string
8
8
GetLifetime () time.Duration
9
9
}
10
10
11
11
type Provider interface {
12
12
Name () string
13
- Lock (info LockInfo ) error
14
- Unlock (info LockInfo ) error
13
+ Lock (info NamedLock ) error
14
+ Unlock (info NamedLock ) error
15
15
}
16
16
17
17
type Mutex interface {
Original file line number Diff line number Diff line change @@ -17,17 +17,17 @@ const (
17
17
`
18
18
)
19
19
20
- // Pool represents a pool of redis connections.
21
- type Pool interface {
20
+ // RedisPool represents a pool of redis connections.
21
+ type RedisPool interface {
22
22
// Get returns a connection from the pool.
23
23
Get () redis.Conn
24
24
}
25
25
26
26
type redisProvider struct {
27
- pool Pool
27
+ pool RedisPool
28
28
}
29
29
30
- func NewRedisProvider (redisPool Pool ) (Provider , error ) {
30
+ func NewRedisProvider (redisPool RedisPool ) (Provider , error ) {
31
31
return & redisProvider {
32
32
pool : redisPool ,
33
33
}, nil
@@ -37,7 +37,7 @@ func (p *redisProvider) Name() string {
37
37
return "redis"
38
38
}
39
39
40
- func (p * redisProvider ) Lock (lock LockInfo ) error {
40
+ func (p * redisProvider ) Lock (lock NamedLock ) error {
41
41
conn := p .pool .Get ()
42
42
defer conn .Close ()
43
43
@@ -59,7 +59,7 @@ func (p *redisProvider) Lock(lock LockInfo) error {
59
59
return ErrAlreadyLocked
60
60
}
61
61
62
- func (p * redisProvider ) Unlock (lock LockInfo ) error {
62
+ func (p * redisProvider ) Unlock (lock NamedLock ) error {
63
63
conn := p .pool .Get ()
64
64
defer conn .Close ()
65
65
You can’t perform that action at this time.
0 commit comments