引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
Redis 配置
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=123456XX
引入RedisTemplate
@Autowired
private RedisTemplate redisTemplate;
取数据
Integer count = (Integer) this.redisTemplate.opsForValue().get(key);
设置数据,设置过期时间
this.redisTemplate.opsForValue().set(key, count, seconds, TimeUnit.SECONDS);
重新设置数据
this.redisTemplate.opsForValue().set(key, count, 0);