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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章