我是Redis和Redisson的新手,我正在使用Redisson Client从其他线程锁定某个键,我想检查某些键是否已锁定,而没有尝试锁定该键(即trylock)
我相信,如果我们检查redis中是否存在密钥,那应该可以,但是我不确定。下面是我用来锁定键的代码。
boolean responseCode = false;
logger.info("[redis-lock] Attempting to lock resource on Key : " + lock.getKey().toString());
try {
RLock fairLock = redissonClient.getFairLock(lock.getKey().toString());
responseCode = fairLock.tryLock(0, 300, TimeUnit.SECONDS);
if (responseCode)
logger.info("[redis-lock] Locked resource succesfully on Key : " + lock.getKey().toString());
} catch (Exception e) {
e.printStackTrace();
logger.info("[redis-lock] Locked resource failed on Key : " + lock.getKey().toString());
lockResponse = new LockResponse(false, e.getMessage());