-- 获取锁标识,是否与当前线程一致?
if(redis.call('get', KEYS[1]) == ARGV[1]) then
-- 一致,删除
return redis.call('del', KEYS[1])
end
-- 不一致,直接返回
return 0
1
2
3
4
5
6
7
package com.platform.lock;
public interface ILock {
/**
* 获取锁
* @param timeoutSec
* @return
*/
public boolean tryLock(long timeoutSec);
/**
* 锁标识、释放锁
*/
public void unlock();
}