美文网首页
RedisTemplate 指定操作库

RedisTemplate 指定操作库

作者: 白驹过隙_忽然而已 | 来源:发表于2020-01-06 14:12 被阅读0次

redis是有多个库的,开发中发现A服务操作的数据,B服务中查不到。排查出A服务操作的是db0,B服务操作的db1。

指定库的方法:

RedisConnection redisConnection = redisTemplate.getConnectionFactory().getConnection();
DefaultStringRedisConnection stringRedisConnection = new DefaultStringRedisConnection(redisConnection);
stringRedisConnection.select(db);

遇到报错:

Selecting a new database not supported due to shared connection.
Use separate ConnectionFactorys to work with multiple databases

解决方案参考:
https://blog.csdn.net/qq_38846242/article/details/83151489

相关文章

网友评论

      本文标题:RedisTemplate 指定操作库

      本文链接:https://www.haomeiwen.com/subject/iuffactx.html