Jedis jedis = redisUtil.getJedis(); String tokenExists = jedis.get(tokenKey); Transaction transaction = jedis.multi(); transaction.watch(tokenKey); if (tokenExists!=null&&tokenExists.equals(token)){//如果在处理判断成功执行删除之间,间隔10s,正好第二个请求过来就会返回两个true,不符合原子性 jedis.del(tokenExists); jedis.close(); } List<Object> list = transaction.exec(); if (list!= null&&list.size()>0&&list.get(0).equals("1")){ return true; }else { return false; }
来源:oschina
链接:https://my.oschina.net/u/3668429/blog/4807642