@Test public void tryGetDistributedLockTest() throws Exception { String key = "testDistributedLockKey"; String requestId = UUID.randomUUID().toString(); boolean getDistributedLockResult = RedisLockUtil.tryGetDistributedLock(JEDIS, key, requestId, 60 * 1000 * 60); System.out.println("getDistributedLockResult=" + getDistributedLockResult); Assert.assertTrue(getDistributedLockResult); }
public static boolean tryGetDistributedLock(Jedis jedis, String lockKey, String requestId, int expireTime) { String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME_UNIT, expireTime); return LOCK_SUCCESS.equals(result); }
RedisLockUtil { public static boolean tryGetDistributedLock(Jedis jedis, String lockKey, String requestId, int expireTime) { String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME_UNIT, expireTime); return LOCK_SUCCESS.equals(result); } }
RedisLockUtil { public static boolean tryGetDistributedLock(Jedis jedis, String lockKey, String requestId, int expireTime) { String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME_UNIT, expireTime); return LOCK_SUCCESS.equals(result); }  }
RedisLockUtil { public static boolean tryGetDistributedLock(Jedis jedis, String lockKey, String requestId, int expireTime) { String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME_UNIT, expireTime); return LOCK_SUCCESS.equals(result); }  static boolean tryGetDistributedLock(Jedis jedis, String lockKey, String requestId, int expireTime); static boolean releaseDistributedLock(Jedis jedis, String lockKey, String requestId); }
RedisLockUtil { public static boolean tryGetDistributedLock(Jedis jedis, String lockKey, String requestId, int expireTime) { String result = jedis.set(lockKey, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME_UNIT, expireTime); return LOCK_SUCCESS.equals(result); }  static boolean tryGetDistributedLock(Jedis jedis, String lockKey, String requestId, int expireTime); static boolean releaseDistributedLock(Jedis jedis, String lockKey, String requestId);  }