一、 启动redis
- cd 到Redis 安装目录 cd D:\Program" "Files\Redis,注意win10 系统空格在命令行里面使用 " "代替
- 输入启动启动redis命令: redis-server.exe redis.windows.conf。
二、配置pom文件redis maven依赖
<!-- 引入redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
三、添加application.yml 配置
spring: redis: host: 127.0.0.1 port: 6379 database: 0 timeout: 2000
四、注入reids,调用相应方法
@Autowired
private StringRedisTemplate redisTemplate;
String saveValueKey = "save-order"; if (redisTemplate != null) { String sendValue = redisTemplate.opsForValue().get(saveValueKey); new Thread(() -> { if (StringUtils.isBlank(sendValue)) { System.out.println("======================error,send to user commit!!"); redisTemplate.opsForValue().set(saveValueKey, "send-fail message!!", 20, TimeUnit.SECONDS); } else { System.out.println("****** small than 20 sec,dont send!!!!"); } }).start(); }else { System.out.println("****** redis is null ======================================="); }