package com.xu.boot; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.concurrent.TimeUnit; /** * Created by Administrator on 2017/9/4. */ @SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan @RestController public class
springboot redis 统计
这是一个关于如何使用SpringBoot结合Redis实现API访问统计的示例。代码中定义了一个RedisTest类,通过@RestController注解使其成为RESTful控制器。主要方法包括/api用于增加访问计数,/show用于展示过去30秒的访问次数,/start和/stop控制统计开关,/reset清空统计。使用RedisTemplate操作Redis,设置key-value以及zset进行时间戳相关的计数管理。
摘要由CSDN通过智能技术生成