On reconnection, select the correct db index

This commit is contained in:
Jonathan Leibiusky
2011-05-15 22:17:21 -03:00
parent 20ee796fa8
commit 607d31d96b
3 changed files with 19 additions and 1 deletions

View File

@@ -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();
}
}

View File

@@ -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;
}

View File

@@ -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"));
}
}