Redis setnx Distributed Lock, redissetnx
Private final String RedisLockKey = "RedLock"; private final long altTimeout = 1*60*60 * 1000L; // 1 hour/*** get the redis Distributed Lock ** @ author Administrator * @ version 1.0 * @ return true: get the lock permission false: no lock permission */private synchronized boolean getRedLock () {Long flag = jedis. setnx (RedisLockKey, String. valueOf (System. currentTimeMillis () + altTimeout + 1L); if (flag = 0L) {String value = jedis. get (RedisLockKey); long longVal = Long. parseLong (value); if (longVal> System. currentTimeMillis () {// return Boolean. FALSE;} else {// expired String _ value = jedis. getSet (RedisLockKey, String. valueOf (System. currentTimeMillis () + altTimeout + 1L); long _ longVal = Long. parseLong (_ value); if (_ longVal> System. currentTimeMillis () {return Boolean. FALSE;} else {return Boolean. TRUE ;}} else {return Boolean. TRUE ;}}