RedisTemplate 指定操作库

2020-01-06  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读