概述
可能会有这样一个需求,在一个类中,需要多个redistemplate访问不同的redis库,在springboot中以注入方式创建一个redistemplate,另外的redistemplate的话,可以通过new来创建(非注入方式创建)redistemplate
demo
引入pom
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
redis创建方法
public RedisTemplate getRedisTemplate(){
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration("localhost", 6379);
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(configuration);
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(jedisConnectionFactory);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
最后
以上就是害羞咖啡最近收集整理的关于springboot访问多个redis库的全部内容,更多相关springboot访问多个redis库内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复