On reconnection, select the correct db index
This commit is contained in:
@@ -53,7 +53,11 @@ public class BinaryClient extends Connection {
|
||||
if (!isConnected()) {
|
||||
super.connect();
|
||||
if (password != null) {
|
||||
sendCommand(AUTH, password);
|
||||
auth(password);
|
||||
getStatusCodeReply();
|
||||
}
|
||||
if (db > 0) {
|
||||
select(Long.valueOf(db).intValue());
|
||||
getStatusCodeReply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ public class Connection {
|
||||
private int pipelinedCommands = 0;
|
||||
private int timeout = Protocol.DEFAULT_TIMEOUT;
|
||||
|
||||
public Socket getSocket() {
|
||||
return socket;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -59,4 +60,13 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
public void failWhenSendingNullValues() {
|
||||
jedis.set("foo", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReconnectToSameDB() throws IOException {
|
||||
jedis.select(1);
|
||||
jedis.set("foo", "bar");
|
||||
jedis.getClient().getSocket().shutdownInput();
|
||||
jedis.getClient().getSocket().shutdownOutput();
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user