目录
- 入口org.redisson.api.RedissonClient
- 进入org.redisson.Redisson.getLock
- 进入org.redisson.RedissonLock
- rLock.tryLock(60, TimeUnit.SECONDS);
- 进入org.redisson.RedissonLock
- 进入Lua脚本的第2个参数getLockName
入口org.redisson.api.RedissonClient
@Resource
private RedissonClient redissonClient;
...
RLock rLock = redissonClient.getLock(lockName);
进入org.redisson.Redisson.getLock
@Override
public RLock getLock(String name) {
return new RedissonLock(commandExecutor, name);
}
进入org.redisson.RedissonLock
直接进行构建方法里面的super(commandExecutor, name);
public RedissonBaseLock(CommandAsyncExecutor commandExecutor, String name) {
super(commandExecutor, name);
this.id = getServiceManager().getId();
this.internalLockLeaseTime = getServiceManager().getCfg().getLockWatchdogTimeout();
this.entryName = id + ":" + name;
}
rLock.tryLock(60, TimeUnit.SECONDS);
尝试获取锁
进入org.redisson.RedissonLock
<T> RFuture<T> tryLockInnerAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId, RedisStrictCommand<T> command) {
return commandExecutor.syncedEval(getRawName(), LongCodec.INSTANCE, command,
"if ((redis.call('exists', KEYS[1]) == 0) " +
"or (redis.call('hexists', KEYS[1], ARGV[2]) == 1)) then " +
"redis.call('hincrby', KEYS[1], ARGV[2], 1); " +
"redis.call('pexpire', KEYS[1], ARGV[1]); " +
"return nil; " +
"end; " +
"return redis.call('pttl', KEYS[1]);",
Collections.singletonList(getRawName()), unit.toMillis(leaseTime), getLockName(threadId));
}
Long ttl = tryAcquire(waitTime, leaseTime, unit, threadId);
// lock acquired
if (ttl == null) {
return true;
}
进入Lua脚本的第2个参数getLockName
protected String getLockName(long threadId) {
return id + ":" + threadId;
}