数据库
首页 > 数据库> > Springboot 实现Redis 同数据源动态切换db

Springboot 实现Redis 同数据源动态切换db

作者:互联网

 

 

 

public void setDataBase(int num) {
        LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory();
        if (connectionFactory != null && num != connectionFactory.getDatabase()) {
            connectionFactory.setDatabase(num);
            this.redisTemplate.setConnectionFactory(connectionFactory);
            connectionFactory.resetConnection();
        }
    }

 

 

 

参考:https://developer.aliyun.com/article/952648

 

 

###########################

标签:connectionFactory,Springboot,数据源,Redis,LettuceConnectionFactory,num,aliyun,redis
来源: https://www.cnblogs.com/herd/p/16526770.html