<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
package com.example.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.StringRedisTemplate;import org.springframework.web.bind.annotation.*;@RestControllerpublic class TestController { @Autowired StringRedisTemplate redisTemplate; @RequestMapping(value = "/index",method = RequestMethod.GET) public String index() { redisTemplate.opsForValue().increment("count",1L); String value = redisTemplate.opsForValue().get("count"); return "当前网站的访问人数为:" +value; }}