SpringBoot学习-(二十二)SpringBoot整合Redis(使用Jedis)
2018-03-07 15:18
811 查看
基本步骤:
添加pom文件依赖
创建redis配置文件
创建java配置文件
项目中应用
添加pom文件依赖
创建redis配置文件
创建java配置文件
项目中应用
添加pom文件依赖
<!-- 操作redis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency>
创建redis配置文件
在resources目录下创建redis。properties文件spring.redis.host=127.0.0.1 spring.redis.port=6379
创建java配置文件
package com.ahut.config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; /** * * @ClassName: RedisConfig * @Description: redis配置 * @author cheng * @date 2018年3月7日 上午11:53:11 */ @Configuration @PropertySource(value = { "classpath:redis.properties" }) public class RedisConfig { /** * 日志管理 */ private Logger log = LoggerFactory.getLogger(RedisConfig.class); @Value("${spring.redis.host}") private String host; @Value("${spring.redis.port}") private int port; /** * * @Title: getJedisPool * @Description: 获取jedisPool * @return */ @Bean public JedisPool getJedisPool() { log.info("==>初始化jedis连接池"); JedisPoolConfig config = new JedisPoolConfig(); JedisPool pool = new JedisPool(config, host, port); return pool; } }
项目中应用
/** * jedis */ @Autowired private JedisPool jedisPool; 代码获取jedis: Jedis jedis = jedisPool.getResource();
相关文章推荐
- jedis与spring整合及简单的使用RedisTemplate操作
- springboot整合redis使用nginx实现负载均衡实现session共享
- [置顶] 在Springboot上使用jedis来操作缓存redis --jedis的配置
- Spring Boot学习(八)之使用NoSQL数据库(一):Redis
- Redis学习总结(2)——Redis整合Spring结合使用缓存实例
- spring-data-redis与Jedis整合使用
- Redis学习总结(3)——Redis整合Spring结合使用缓存实例
- (一)由浅入深学习springboot中使用redis
- spring boot 整合 redis,使用@Cacheable,@CacheEvict,@CachePut,jedisPool操作redis数据库
- jedis,spring-redis-data 整合使用,版本问题异常以及解决。
- 使用Redis的jedis客户端整合spring
- spring-data-redis与Jedis整合使用
- Redis学习总结(3)——Redis整合Spring结合使用缓存实例
- Spring Boot 学习笔记--整合Redis
- REDIS学习(3.2)spring boot 使用redis作为缓存
- spring boot中使用redis -Jedis
- Spring Boot学习之整合Redis实现缓存
- jedis与spring整合及简单的使用RedisTemplate操作
- SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)
- jedis,spring-redis-data 整合使用,版本问题异常