美文网首页
redis+lua实现分布式锁

redis+lua实现分布式锁

作者: 南柯一梦00 | 来源:发表于2020-06-06 09:45 被阅读0次
     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<String> 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实现分布式锁

          本文链接:https://www.haomeiwen.com/subject/pnmbzhtx.html