当前位置:网站首页>怎么用redis限制同一ip重复刷浏览量
怎么用redis限制同一ip重复刷浏览量
2022-08-03 02:42:00 【CSDN问答】
在写一个博客项目,想加一个限制同一ip重复刷浏览量的功能,要怎么去实现呢?
另外浏览量放入redis虽然实现了,但是感觉写的也不太好,能不能给点建议优化一下。
@Override public Result findArticleById(Long id) { Article article=this.articleMapper.selectById(id); ArticleVo articleVo=copy(article,true,true,true,true); //使用redis实现增加阅读次数 String key="mszlu"+article.getId(); if (redisTemplate.opsForValue().get(key)==null) { redisTemplate.boundValueOps(key).increment(article.getViewCounts()+1); }else { redisTemplate.boundValueOps(key).increment(1); } //threadService.updateArticleViewCount(articleMapper,article); articleVo.setViewCounts(Integer.valueOf(redisTemplate.opsForValue().get(key))); return Result.success(articleVo); }边栏推荐
- Incorrect datetime value: '2022-01-01' for function str_to_date
- YYGH-BUG-06
- 网易数帆陈谔:云原生“牵手”低代码,加速企业数字化转型
- JVM internal structure and various modules operation mechanism
- 常用工具链和虚拟环境-WSL
- The LVS load balancing cluster and the deployment of the LVS - NAT experiment
- 【Flink】使用arthas在线诊断flink的那些事
- 实现统一账号登录,sonarqube集成ldap
- 【GraphQL】使用Hot Chocolate和.NET 6构建GraphQL应用
- win下使用vscode+wsl2
猜你喜欢
随机推荐
[Arduino] Reborn Arduino Monk (2)----Arduino Language
ROS通信模块:秒懂话题通信
Linux定时任务脚本执行时mysqldump备份异常的问题
重定向printf到USB CDC、串口2
能添加任意贴图超级复布局的初级智能文本提示器(超级版)
leetcode:140. 单词拆分 II
网易数帆陈谔:云原生“牵手”低代码,加速企业数字化转型
openCV第一篇
服务器在线测速系统源码
Incorrect datetime value: ‘2022-01-01‘ for function str_to_date
企业上云规划与云原生环境设计
【数据分析】基于MATLAB实现SVDD决策边界可视化
Spark SQL简介
【Objective-C语言中的@property增强】
征集 |《新程序员》专访“Apache之父”Brian Behlendorf,你最想问什么?
易购数码类电商商城网页设计与实现项目源码
用 SQL 做数据分析的十大常用功能,附面试原题解答!!
C语言入门--指针
Go新项目-编译项目的细节(4)
选中按钮上色









