springBoot 编写接口
@Slf4j @RestController public class testController { @Autowired StringRedisTemplate redis; @RequestMapping(value = "/login") public String login() { //int i = 1 / 0; log.info("login"); redis.opsForValue().set("key", "1"); return "login"; } }
@Slf4j 日志
idea中要安装lombok 插件
如图
pom中要加入日志依赖包
<!--日志--> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency>
@Autowired 注入,引入redis对象
pom中加上其依赖
<!--redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
redis.hasKey(key);
redis.opsForValue().set(key, value);
String value = redis.opsForValue().get(key);
redis.delete(key);
欢迎指正:haizi2014@qq.com