DistributedLock icon indicating copy to clipboard operation
DistributedLock copied to clipboard

这里有个问题

Open wingahi opened this issue 6 years ago • 0 comments

		if (isTimeExpired(currLockInfo.getExpires())) {
			// 锁超时了
			LockInfo oldLockInfo = LockInfo.fromString(jedis.getSet(lockKey, newLockInfoJson));
                            //,这里需要判断redis所内容是否为当前锁,要不然并发情况会被多个线程获得锁
                            //String newSetLockInfoJson = redisTemplate.opsForValue().get(lockKey);
			//if (oldLockInfo != null && isTimeExpired(oldLockInfo.getExpires()) && 
                            //newSetLockInfoJson.equals(newLockInfoJson)) {
			if (oldLockInfo != null && isTimeExpired(oldLockInfo.getExpires())) {
				// 成功获取到锁, 设置相关标识
				logger.debug("{} get lock(new), lockInfo: {}", Thread.currentThread().getName(), newLockInfoJson);
				locked = true;
				return true;
			}
		}

wingahi avatar Sep 18 '18 10:09 wingahi