spring boot Redis使用
2017-09-12 00:00
281 查看
一、导入关联jar
二、在application.properties文件中增加redis相关配置信息
三、如何使用?
可以通过阅读 StringRedisTemplate 或 RedisTemplate 源码编写根据自己需求的cache操作类
<!-- Redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
二、在application.properties文件中增加redis相关配置信息
# REDIS (RedisProperties) # Redis数据库索引(默认为0) spring.redis.database=8 # Redis服务器地址 spring.redis.host=121.40.133.100 # Redis服务器连接端口 spring.redis.port=13017 # Redis服务器连接密码(默认为空) spring.redis.password=m7ua80gbm7cdm # 连接池最大连接数(使用负值表示没有限制) spring.redis.pool.max-active=8 # 连接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.pool.max-wait=10000 # 连接池中的最大空闲连接 spring.redis.pool.max-idle=200 # 连接池中的最小空闲连接 spring.redis.pool.min-idle=3 # 连接超时时间(毫秒) spring.redis.timeout=6000
三、如何使用?
//导入redis模板 @Autowired private StringRedisTemplate stringRedisTemplate;
stringRedisTemplate.opsForValue().get(key); stringRedisTemplate.opsForValue().set(key,value); //设置单个键值及有效期 times时间长度long类型,TimeUtil具体存活时间单位;微秒、毫秒、秒、分、时等等 stringRedisTemplate.opsForValue().set(key,value,times,TimeUtil); //........更多操作键值可进行阅读StringRedisTemplate或RedisTemplate源码进行获取
可以通过阅读 StringRedisTemplate 或 RedisTemplate 源码编写根据自己需求的cache操作类
相关文章推荐
- Spring Boot使用redis做数据缓存
- 使用Java(Springboot)操作Redis
- 1 Springboot中使用redis,自动缓存、更新、删除
- [spring-boot] 使用redis
- 使用springboot+redis实现session共享
- Spring Boot中使用Redis数据库
- Spring Boot使用Redis进行消息的发布订阅
- Spring Boot 使用 Redis 提升天气预报应用的并发访问能力
- (转)SpringBoot系列—Redis使用
- spring boot(三):Spring Boot中Redis的使用
- Spring Boot中使用Redis数据库
- 排忧解难之使用Spring Boot与Redis集成报错 NoClassDefFoundError...RedisConnectionFactory
- Spring-boot通过redisTemplate使用redis(无须手动序列化)
- Spring Boot中使用Redis数据库
- Spring Boot中使用Redis数据库
- Spring-Boot (四) cache/ehcache/redis-cache集成使用
- Spring Boot使用redis做数据缓存
- 使用Java(Springboot)操作Redis
- 使用springboot+redis实现session共享
- Spring Cloud Spring Boot mybatis分布式微服务云架构(三十六)使用Redis做集中式缓存(2)