Fix database selection on dedicated connection.
We now select the database on the dedicated connection. Previously, this call never happened on the dedicated connection and the only way a database could be selected is through the ConnectionFactory configuration. Closes: #2984 Original Pull Request: #2990
This commit is contained in:
committed by
Christoph Strobl
parent
fd31e433c0
commit
8777cf7fc6
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.redis;
|
||||
|
||||
import org.springframework.dao.UncategorizedDataAccessException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Exception thrown when we can't classify a Redis exception into one of Spring generic data access exceptions.
|
||||
@@ -28,7 +29,7 @@ public class RedisSystemException extends UncategorizedDataAccessException {
|
||||
* @param msg the detail message.
|
||||
* @param cause the root cause from the data access API in use.
|
||||
*/
|
||||
public RedisSystemException(String msg, Throwable cause) {
|
||||
public RedisSystemException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
|
||||
@@ -512,7 +512,7 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
if (this.asyncDedicatedConnection != null) {
|
||||
try {
|
||||
if (customizedDatabaseIndex()) {
|
||||
potentiallySelectDatabase(this.defaultDbIndex);
|
||||
potentiallySelectDatabase(this.asyncDedicatedConnection, this.defaultDbIndex);
|
||||
}
|
||||
this.connectionProvider.release(this.asyncDedicatedConnection);
|
||||
this.asyncDedicatedConnection = null;
|
||||
@@ -965,7 +965,7 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
StatefulConnection<byte[], byte[]> connection = getConnectionProvider().getConnection(StatefulConnection.class);
|
||||
|
||||
if (customizedDatabaseIndex()) {
|
||||
potentiallySelectDatabase(this.dbIndex);
|
||||
potentiallySelectDatabase(connection, this.dbIndex);
|
||||
}
|
||||
|
||||
return connection;
|
||||
@@ -1062,9 +1062,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
return defaultDbIndex != dbIndex;
|
||||
}
|
||||
|
||||
private void potentiallySelectDatabase(int dbIndex) {
|
||||
private static void potentiallySelectDatabase(StatefulConnection<byte[], byte[]> connection, int dbIndex) {
|
||||
|
||||
if (asyncDedicatedConnection instanceof StatefulRedisConnection<byte[], byte[]> statefulConnection) {
|
||||
if (connection instanceof StatefulRedisConnection<byte[], byte[]> statefulConnection) {
|
||||
statefulConnection.sync().select(dbIndex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user