In JedisConnection:103-105 the database is selected only if dbIndex > 0.
The problem is, if a connection pool is used and a database > 0 has been selected for a Jedis connection and it is later being requested from JedisConnectionFactory with dbIndex == 0, then it will not execute select(0) and thus still be connected to the other database.
Select(dbIndex) needs to be executed every time
DATAREDIS-714 JedisConnection always executes SELECT via RedisTemplate
Actually, what would be really great in terms of reducing calls to the redis server and ensuring the correct database is selected woul dbe to somehow get the connection pool to test connections on borrow using the adequate select command instead of ping. But that is probably not possible because connections rae borrowed from the pool before the databas eindex is set on them
The ideal solution really is to handle this in the driver as it provides the pooling as well and handle the reuse.
However I've added some extra logic to reset the connections returned to the pool so any db selection made by Spring Redis, is reverted back.