美文网首页
使用Redis的incr命令防止重复请求

使用Redis的incr命令防止重复请求

作者: linweiyu21 | 来源:发表于2017-08-23 11:42 被阅读0次
    String countKey = MessageFormat.format(CREATE_COMMENT_TOKEN_KEY,userId,sourceId,content,type,commentType,commentId,source);
    Long countValue = jedis.incrBy(countKey, 1L);
    if (countValue > 1) {
        throw new ServiceException(Code.FAIL, "不要重复提交哦");
    }
    if (countValue == 1) {
        jedis.expire(countKey, 3);
    }
    

    参考

    防重复请求处理的实践与总结
    使用Redis计数器防止并发请求

    相关文章

      网友评论

          本文标题:使用Redis的incr命令防止重复请求

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