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
网友评论