redis+lua实现分布式锁

 RedisScript redisScript =
                RedisScript.of("local tmp = redis.call('get', KEYS[1])\n" +
                                "if tmp == false then\n" +
                                "   redis.call('set',KEYS[1],KEYS[2])\n" +
                                "   return 1\n" +
                                "end\n" +
                                "return 0\n",
                        Long.class);
        List list = new ArrayList<>();
        list.add("test-lock");
        list.add("test-lock");
        Long execute = (Long) redisTemplate.execute(redisScript, list, "60");
        System.err.println("执行结果:" + execute);

你可能感兴趣的:(redis+lua实现分布式锁)