分佈式锁的Redisson实现

  • 时间:
  • 来源:互联网

Redis 官方推荐使用Redisson实现分布式锁

 
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
 
public class RedissonLockTest {
  static int fixNum=5;
  public static void main(String []args) throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(fixNum);
 
    // 默认连接 127.0.0.1:6379
    RedissonClient redisson = Redisson.create();
 
    ExecutorService exec = Executors.newFixedThreadPool(fixNum);
    for(int i=0;i<fixNum;i++){
      exec.submit(new TestLock("CLIENT-"+i,redisson,latch));
    }
    exec.shutdown();
    latch.await();
    System.out.println("所有任务执行完毕!");
  }
 
}
 
 class TestLock implements Runnable{
   private String name;
   private RedissonClient redisson;
   private CountDownLatch latch;
   @Override
   public void run() {
     RLock lock = redisson.getLock("TestLock");
 
     try{
       System.out.println("***************"+this.name+"*************等待获取锁");
       if(lock.tryLock(300,30, TimeUnit.MILLISECONDS)){
          try{
            System.out.println("******************"+this.name+"************获得锁开始处理*********");
            System.out.println("*************"+this.name+"*********** 数据 **************************");
            Thread.sleep(2*100);
            System.out.println("******************"+this.name+"锁使用完毕*****");
            latch.countDown();
          }
          finally {
            lock.unlock();
            System.out.println("*************"+this.name+"释放锁*************");
          }
       }
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
 
   public TestLock(String name, RedissonClient redisson, CountDownLatch latch){
     this.name=name;
     this.redisson=redisson;
     this.latch=latch;
   }
 
 }

执行结果:

14:55:22.874 [redisson-netty-1-4] INFO org.redisson.connection.pool.MasterConnectionPool - 5 connections initialized for /39.107.107.185:6379
14:55:22.874 [redisson-netty-1-7] INFO org.redisson.connection.pool.SinglePubSubConnectionPool - 1 connections initialized for /39.107.107.185:6379
***************CLIENT-2*************等待获取锁
***************CLIENT-1*************等待获取锁
***************CLIENT-0*************等待获取锁
***************CLIENT-4*************等待获取锁
***************CLIENT-3*************等待获取锁
14:55:22.893 [pool-2-thread-4] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.895 [pool-2-thread-1] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:24] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.895 [pool-2-thread-2] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:25] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.895 [pool-2-thread-5] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.895 [pool-2-thread-3] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.899 [redisson-netty-1-2] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@2003486257 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x62642011, L:/192.168.100.47:59766 - R:/39.107.107.185:6379]]
14:55:22.900 [redisson-netty-1-4] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:24] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1314792434 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26147cfc, L:/192.168.100.47:59767 - R:/39.107.107.185:6379]]
******************CLIENT-0************获得锁开始处理*********
*************CLIENT-0*********** 数据 **************************
14:55:22.901 [redisson-netty-1-3] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1698707786 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x35892539, L:/192.168.100.47:59764 - R:/39.107.107.185:6379]]
14:55:22.901 [redisson-netty-1-6] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:25] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@293076392 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26082049, L:/192.168.100.47:59763 - R:/39.107.107.185:6379]]
14:55:22.901 [redisson-netty-1-5] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@662583616 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x46e9e148, L:/192.168.100.47:59762 - R:/39.107.107.185:6379]]
14:55:22.913 [pool-2-thread-3] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.914 [pool-2-thread-5] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.916 [pool-2-thread-4] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.919 [redisson-netty-1-4] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1314792434 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26147cfc, L:/192.168.100.47:59767 - R:/39.107.107.185:6379]]
14:55:22.920 [redisson-netty-1-2] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@2003486257 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x62642011, L:/192.168.100.47:59766 - R:/39.107.107.185:6379]]
14:55:22.921 [pool-2-thread-2] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:25] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.924 [redisson-netty-1-3] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1698707786 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x35892539, L:/192.168.100.47:59764 - R:/39.107.107.185:6379]]
14:55:22.927 [redisson-netty-1-5] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:25] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@662583616 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x46e9e148, L:/192.168.100.47:59762 - R:/39.107.107.185:6379]]
14:55:22.932 [pool-2-thread-2] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:25] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.932 [pool-2-thread-3] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.934 [pool-2-thread-5] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.934 [pool-2-thread-4] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.937 [redisson-netty-1-4] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:25] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1314792434 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26147cfc, L:/192.168.100.47:59767 - R:/39.107.107.185:6379]]
******************CLIENT-1************获得锁开始处理*********
*************CLIENT-1*********** 数据 **************************
14:55:22.938 [redisson-netty-1-6] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@293076392 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26082049, L:/192.168.100.47:59763 - R:/39.107.107.185:6379]]
14:55:22.939 [redisson-netty-1-2] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@2003486257 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x62642011, L:/192.168.100.47:59766 - R:/39.107.107.185:6379]]
14:55:22.940 [redisson-netty-1-3] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1698707786 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x35892539, L:/192.168.100.47:59764 - R:/39.107.107.185:6379]]
14:55:22.969 [pool-2-thread-4] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.969 [pool-2-thread-5] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.970 [pool-2-thread-3] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:22.978 [redisson-netty-1-4] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1314792434 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26147cfc, L:/192.168.100.47:59767 - R:/39.107.107.185:6379]]
14:55:22.978 [redisson-netty-1-5] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@662583616 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x46e9e148, L:/192.168.100.47:59762 - R:/39.107.107.185:6379]]
******************CLIENT-4************获得锁开始处理*********
*************CLIENT-4*********** 数据 **************************
14:55:22.978 [redisson-netty-1-6] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@293076392 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26082049, L:/192.168.100.47:59763 - R:/39.107.107.185:6379]]
14:55:23.009 [pool-2-thread-4] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:23.009 [pool-2-thread-3] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:23.018 [redisson-netty-1-2] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@2003486257 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x62642011, L:/192.168.100.47:59766 - R:/39.107.107.185:6379]]
******************CLIENT-3************获得锁开始处理*********
*************CLIENT-3*********** 数据 **************************
14:55:23.018 [redisson-netty-1-3] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1698707786 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x35892539, L:/192.168.100.47:59764 - R:/39.107.107.185:6379]]
14:55:23.050 [pool-2-thread-3] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:23.057 [redisson-netty-1-4] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then redis.call('hincrby', KEYS[1], ARGV[2], 1); redis.call('pexpire', KEYS[1], ARGV[1]); return nil; end; return redis.call('pttl', KEYS[1]);, 1, TestLock, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1314792434 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26147cfc, L:/192.168.100.47:59767 - R:/39.107.107.185:6379]]
******************CLIENT-2************获得锁开始处理*********
*************CLIENT-2*********** 数据 **************************
******************CLIENT-0锁使用完毕*****
14:55:23.102 [pool-2-thread-1] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:24] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
******************CLIENT-1锁使用完毕*****
14:55:23.138 [pool-2-thread-2] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:25] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:23.141 [redisson-netty-1-5] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:24] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@662583616 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x46e9e148, L:/192.168.100.47:59762 - R:/39.107.107.185:6379]]
*************CLIENT-0释放锁*************
******************CLIENT-4锁使用完毕*****
14:55:23.178 [pool-2-thread-5] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:23.184 [redisson-netty-1-6] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:25] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@293076392 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26082049, L:/192.168.100.47:59763 - R:/39.107.107.185:6379]]
*************CLIENT-1释放锁*************
******************CLIENT-3锁使用完毕*****
14:55:23.219 [pool-2-thread-4] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:23.221 [redisson-netty-1-2] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:28] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@2003486257 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x62642011, L:/192.168.100.47:59766 - R:/39.107.107.185:6379]]
*************CLIENT-4释放锁*************
******************CLIENT-2锁使用完毕*****
所有任务执行完毕!
14:55:23.260 [pool-2-thread-3] DEBUG org.redisson.command.CommandAsyncService - aquired connection for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using node /39.107.107.185:6379
14:55:23.265 [redisson-netty-1-3] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:27] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1698707786 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x35892539, L:/192.168.100.47:59764 - R:/39.107.107.185:6379]]
*************CLIENT-3释放锁*************
14:55:23.304 [redisson-netty-1-4] DEBUG org.redisson.command.CommandAsyncService - connection released for command (EVAL) and params [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TestLock, redisson_lock__channel:{TestLock}, 0, 30, a78ae226-8e0e-4872-a829-fc77336d55e6:26] from slot NodeSource [slot=null, addr=null, redirect=null] using connection RedisConnection@1314792434 [redisClient=[addr=/39.107.107.185:6379], channel=[id: 0x26147cfc, L:/192.168.100.47:59767 - R:/39.107.107.185:6379]]
*************CLIENT-2释放锁*************

 

咸鱼(。・∀・)ノ゙嗨
发布了91 篇原创文章 · 获赞 169 · 访问量 4万+
私信 关注

本文链接http://element-ui.cn/news/show-1770.aspx