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.
|
||||
func (r *StandaloneRedisLock) TryLock(req *lock.TryLockRequest) (*lock.TryLockResponse, error) {
|
||||
// 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 {
|
||||
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
|
||||
ownerID1 := uuid.New().String()
|
||||
resp, err := comp.TryLock(&lock.TryLockRequest{
|
||||
ResourceID: resourceID,
|
||||
LockOwner: ownerID1,
|
||||
Expire: 10,
|
||||
ResourceID: resourceID,
|
||||
LockOwner: ownerID1,
|
||||
ExpiryInSeconds: 10,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, resp.Success)
|
||||
|
@ -111,9 +111,9 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
|||
go func() {
|
||||
owner2 := uuid.New().String()
|
||||
resp2, err2 := comp.TryLock(&lock.TryLockRequest{
|
||||
ResourceID: resourceID,
|
||||
LockOwner: owner2,
|
||||
Expire: 10,
|
||||
ResourceID: resourceID,
|
||||
LockOwner: owner2,
|
||||
ExpiryInSeconds: 10,
|
||||
})
|
||||
assert.NoError(t, err2)
|
||||
assert.False(t, resp2.Success)
|
||||
|
@ -132,9 +132,9 @@ func TestStandaloneRedisLock_TryLock(t *testing.T) {
|
|||
go func() {
|
||||
owner2 := uuid.New().String()
|
||||
resp2, err2 := comp.TryLock(&lock.TryLockRequest{
|
||||
ResourceID: resourceID,
|
||||
LockOwner: owner2,
|
||||
Expire: 10,
|
||||
ResourceID: resourceID,
|
||||
LockOwner: owner2,
|
||||
ExpiryInSeconds: 10,
|
||||
})
|
||||
assert.NoError(t, err2)
|
||||
assert.True(t, resp2.Success, "client2 failed to get lock?!")
|
||||
|
|
|
@ -15,9 +15,9 @@ package lock
|
|||
|
||||
// Lock acquire request.
|
||||
type TryLockRequest struct {
|
||||
ResourceID string
|
||||
LockOwner string
|
||||
Expire int32
|
||||
ResourceID string
|
||||
LockOwner string
|
||||
ExpiryInSeconds int32
|
||||
}
|
||||
|
||||
// Lock release request.
|
||||
|
|
Loading…
Reference in New Issue