关于基于redis实现分布式锁之lua脚本优化所出现的bug
io.lettuce.core.RedisCommandExecutionException: ERR Error compiling script (new function): user_script:1: 'end' expected near 'elsereturn'
//释放锁 String script = "if redis.call('get',KEYS[1]) == ARGV[1] " + "then " + "return redis.call('del',KEYS[1]) " + "else" + "return 0 " + "end"; this.redisTemplate.execute(new DefaultRedisScript<>(script), Arrays.asList("lock"), uuid);
在这里需要加入返回结果集类型,虽然不需要但是必须指定.否则会报错
this.redisTemplate.execute(new DefaultRedisScript<>(script,Boolean.class), Arrays.asList("lock"), uuid);
加入lua脚本后可以保证原子性和防误删