首页 > 数据库技术 > 详细

redis切换db

时间:2020-12-24 17:03:59      阅读:37      评论:0      收藏:0      [点我收藏+]
@Component
public class RedisDBChangeUtil {
@Autowired
private StringRedisTemplate redisTemplate;

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

redis单线程为什么那么快:
  • 纯内存操作
  • 使用IO多路复用技术
  • 非CPU密集型任务

redis切换db

原文:https://www.cnblogs.com/sun27/p/14184143.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!