redistemplate动态切换dbindex

redisTemplate.getConnectionFactory().getConnection().select(uvIndex);  依据api  此代码可以切换dbindex,不过实际没有生效!

 

找了找原因:是我用法有问题

 

正确写法应该是

JedisConnectionFactory factory = 
(JedisConnectionFactory) redisTemplate.getConnectionFactory();
factory.setDatabase(dbIndex);//dbindex就是你想切换的db
redisTemplate.setConnectionFactory(factory);

 参考链接 https://blog.csdn.net/jlh912008548/article/details/78982008

你可能感兴趣的:(随笔记录)