String redisKey = userName ;
//记数器,是原子性的,不存在并发问题
long count = redisTemplate.opsForValue().increment(redisKey, 1);if(count == 1){
//key保存到redis上一分钟,它失败后,记数器同时失效
redisTemplate.expire(redisKey, 60, TimeUnit.SECONDS);}if(count > 1){logger.info("+++++++++++++++++++++++++++++++++++++++++"+"太频繁");}logger.info("---------------------------------------------"+count);
redis的安装配置,和sPRing的集成,可参看前面二篇文章
新闻热点
疑难解答