@Test public void testTryLockTrue() { redis1.del(lockKey); boolean b = dLock.tryLock(lockKey, 30, TimeUnit.SECONDS); Assert.assertTrue(b); System.out.println(String.format("[CRAFT-ATOM-REDIS] (^_^) <%s> Case -> test try lock true. ", CaseCounter.incr(1))); }
@Override public boolean tryLock(String lockKey, int ttl, TimeUnit unit) { if (lockKey == null || unit == null) { throw new IllegalArgumentException(String.format("Args=<lockKey=%s, unit=%s>", lockKey, unit)); } int ttlSeconds = (int) TimeUnit.SECONDS.convert(ttl, unit); if (ttlSeconds == 0) { ttlSeconds = 1; } boolean success = true; try { redis.watch(lockKey); if (redis.get(lockKey) == null) { success = tryLock0(lockKey, ttlSeconds); } else { success = false; } } catch (Exception e) { LOG.error("[CRAFT-ATOM-LOCK] Try lock fail, |lockKey={}, ttl={}, unit={}|", lockKey, ttl, unit, e); success = false; } finally { redis.unwatch(); } return success; }
Redis24DLock implements DLock { @Override public boolean tryLock(String lockKey, int ttl, TimeUnit unit) { if (lockKey == null || unit == null) { throw new IllegalArgumentException(String.format("Args=<lockKey=%s, unit=%s>", lockKey, unit)); } int ttlSeconds = (int) TimeUnit.SECONDS.convert(ttl, unit); if (ttlSeconds == 0) { ttlSeconds = 1; } boolean success = true; try { redis.watch(lockKey); if (redis.get(lockKey) == null) { success = tryLock0(lockKey, ttlSeconds); } else { success = false; } } catch (Exception e) { LOG.error("[CRAFT-ATOM-LOCK] Try lock fail, |lockKey={}, ttl={}, unit={}|", lockKey, ttl, unit, e); success = false; } finally { redis.unwatch(); } return success; } }
Redis24DLock implements DLock { @Override public boolean tryLock(String lockKey, int ttl, TimeUnit unit) { if (lockKey == null || unit == null) { throw new IllegalArgumentException(String.format("Args=<lockKey=%s, unit=%s>", lockKey, unit)); } int ttlSeconds = (int) TimeUnit.SECONDS.convert(ttl, unit); if (ttlSeconds == 0) { ttlSeconds = 1; } boolean success = true; try { redis.watch(lockKey); if (redis.get(lockKey) == null) { success = tryLock0(lockKey, ttlSeconds); } else { success = false; } } catch (Exception e) { LOG.error("[CRAFT-ATOM-LOCK] Try lock fail, |lockKey={}, ttl={}, unit={}|", lockKey, ttl, unit, e); success = false; } finally { redis.unwatch(); } return success; } Redis24DLock();  Redis24DLock(RedisCommand redis); }
Redis24DLock implements DLock { @Override public boolean tryLock(String lockKey, int ttl, TimeUnit unit) { if (lockKey == null || unit == null) { throw new IllegalArgumentException(String.format("Args=<lockKey=%s, unit=%s>", lockKey, unit)); } int ttlSeconds = (int) TimeUnit.SECONDS.convert(ttl, unit); if (ttlSeconds == 0) { ttlSeconds = 1; } boolean success = true; try { redis.watch(lockKey); if (redis.get(lockKey) == null) { success = tryLock0(lockKey, ttlSeconds); } else { success = false; } } catch (Exception e) { LOG.error("[CRAFT-ATOM-LOCK] Try lock fail, |lockKey={}, ttl={}, unit={}|", lockKey, ttl, unit, e); success = false; } finally { redis.unwatch(); } return success; } Redis24DLock();  Redis24DLock(RedisCommand redis); @Override boolean tryLock(String lockKey, int ttl, TimeUnit unit); @Override boolean unlock(String lockKey); }
Redis24DLock implements DLock { @Override public boolean tryLock(String lockKey, int ttl, TimeUnit unit) { if (lockKey == null || unit == null) { throw new IllegalArgumentException(String.format("Args=<lockKey=%s, unit=%s>", lockKey, unit)); } int ttlSeconds = (int) TimeUnit.SECONDS.convert(ttl, unit); if (ttlSeconds == 0) { ttlSeconds = 1; } boolean success = true; try { redis.watch(lockKey); if (redis.get(lockKey) == null) { success = tryLock0(lockKey, ttlSeconds); } else { success = false; } } catch (Exception e) { LOG.error("[CRAFT-ATOM-LOCK] Try lock fail, |lockKey={}, ttl={}, unit={}|", lockKey, ttl, unit, e); success = false; } finally { redis.unwatch(); } return success; } Redis24DLock();  Redis24DLock(RedisCommand redis); @Override boolean tryLock(String lockKey, int ttl, TimeUnit unit); @Override boolean unlock(String lockKey);  }