spring 整合redis
1.maven项目引入依赖
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>2.1.15.RELEASE</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.2.0</version> </dependency>
2.配置redis参数
spring.redis.host=127.0.0.1 spring.redis.port=6379 spring.redis.password=*** spring.redis.database=0
3.操作redis 的俩种方式: I.StringRedisTemplate II.RedisTemplate 。
StringRedisTemplate 操作示例如下:
@Autowired private StringRedisTemplate stringRedisTemplate; //redis的操作类 @GetMapping("redis-op") public void redisOp(){ stringRedisTemplate.opsForValue().set("test", "100",60*10, TimeUnit.SECONDS);//向redis里存入数据和设置缓存