Expire -> ExpiryInSeconds (#1721)
Signed-off-by: seeflood <349895584@qq.com>
This commit is contained in:
parent
5e4bd89afd
commit
9bb86a08a6
|
@ -131,7 +131,7 @@ func (r *StandaloneRedisLock) parseConnectedSlaves(res string) int {
|
||||||
// Try to acquire a redis lock.
|
// Try to acquire a redis lock.
|
||||||
func (r *StandaloneRedisLock) TryLock(req *lock.TryLockRequest) (*lock.TryLockResponse, error) {
|
func (r *StandaloneRedisLock) TryLock(req *lock.TryLockRequest) (*lock.TryLockResponse, error) {
|
||||||
// 1.Setting redis expiration time
|
// 1.Setting redis expiration time
|
||||||
nx := r.client.SetNX(r.ctx, req.ResourceID, req.LockOwner, time.Second*time.Duration(req.Expire))
|
nx := r.client.SetNX(r.ctx, req.ResourceID, req.LockOwner, time.Second*time.Duration(req.ExpiryInSeconds))
|
||||||
if nx == nil {
|
if nx == nil {
|
||||||
return &lock.TryLockResponse{}, fmt.Errorf("[standaloneRedisLock]: SetNX returned nil.ResourceID: %s", req.ResourceID)
|
return &lock.TryLockResponse{}, fmt.Errorf("[standaloneRedisLock]: SetNX returned nil.ResourceID: %s", req.ResourceID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,9 +99,9 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
||||||
// 1. client1 trylock
|
// 1. client1 trylock
|
||||||
ownerID1 := uuid.New().String()
|
ownerID1 := uuid.New().String()
|
||||||
resp, err := comp.TryLock(&lock.TryLockRequest{
|
resp, err := comp.TryLock(&lock.TryLockRequest{
|
||||||
ResourceID: resourceID,
|
ResourceID: resourceID,
|
||||||
LockOwner: ownerID1,
|
LockOwner: ownerID1,
|
||||||
Expire: 10,
|
ExpiryInSeconds: 10,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, resp.Success)
|
assert.True(t, resp.Success)
|
||||||
|
@ -111,9 +111,9 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
||||||
go func() {
|
go func() {
|
||||||
owner2 := uuid.New().String()
|
owner2 := uuid.New().String()
|
||||||
resp2, err2 := comp.TryLock(&lock.TryLockRequest{
|
resp2, err2 := comp.TryLock(&lock.TryLockRequest{
|
||||||
ResourceID: resourceID,
|
ResourceID: resourceID,
|
||||||
LockOwner: owner2,
|
LockOwner: owner2,
|
||||||
Expire: 10,
|
ExpiryInSeconds: 10,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err2)
|
assert.NoError(t, err2)
|
||||||
assert.False(t, resp2.Success)
|
assert.False(t, resp2.Success)
|
||||||
|
@ -132,9 +132,9 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
||||||
go func() {
|
go func() {
|
||||||
owner2 := uuid.New().String()
|
owner2 := uuid.New().String()
|
||||||
resp2, err2 := comp.TryLock(&lock.TryLockRequest{
|
resp2, err2 := comp.TryLock(&lock.TryLockRequest{
|
||||||
ResourceID: resourceID,
|
ResourceID: resourceID,
|
||||||
LockOwner: owner2,
|
LockOwner: owner2,
|
||||||
Expire: 10,
|
ExpiryInSeconds: 10,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err2)
|
assert.NoError(t, err2)
|
||||||
assert.True(t, resp2.Success, "client2 failed to get lock?!")
|
assert.True(t, resp2.Success, "client2 failed to get lock?!")
|
||||||
|
|
|
@ -15,9 +15,9 @@ package lock
|
||||||
|
|
||||||
// Lock acquire request.
|
// Lock acquire request.
|
||||||
type TryLockRequest struct {
|
type TryLockRequest struct {
|
||||||
ResourceID string
|
ResourceID string
|
||||||
LockOwner string
|
LockOwner string
|
||||||
Expire int32
|
ExpiryInSeconds int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock release request.
|
// Lock release request.
|
||||||
|
|
Loading…
Reference in New Issue