Add Redis 2.6 info(section) method to Connections

DATAREDIS-183
This commit is contained in:
Jennifer Hickey
2013-06-24 18:15:39 -07:00
parent e9d1901298
commit 83a507bf1d
13 changed files with 106 additions and 0 deletions

View File

@@ -236,6 +236,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return delegate.info();
}
public Properties info(String section) {
return delegate.info(section);
}
public boolean isClosed() {
return delegate.isClosed();
}

View File

@@ -41,6 +41,8 @@ public interface RedisServerCommands {
Properties info();
Properties info(String section);
void shutdown();
List<String> getConfig(String pattern);

View File

@@ -476,6 +476,11 @@ public class JedisConnection implements RedisConnection {
}
public Properties info(String section) {
throw new UnsupportedOperationException();
}
public Long lastSave() {
try {
if (isQueueing()) {

View File

@@ -276,6 +276,11 @@ public class JredisConnection implements RedisConnection {
}
public Properties info(String section) {
throw new UnsupportedOperationException();
}
public Long lastSave() {
try {
return (Long)jredis.lastsave();

View File

@@ -406,6 +406,19 @@ public class LettuceConnection implements RedisConnection {
}
public Properties info(String section) {
try {
if (isPipelined()) {
pipeline(getAsyncConnection().info(section));
return null;
}
return LettuceUtils.info(getConnection().info(section));
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}
public Long lastSave() {
try {
if (isPipelined()) {

View File

@@ -322,6 +322,19 @@ public class SrpConnection implements RedisConnection {
}
public Properties info(String section) {
try {
if (isPipelined()) {
pipeline(pipeline.info(section));
return null;
}
return SrpUtils.info(client.info(section));
} catch (Exception ex) {
throw convertSrpAccessException(ex);
}
}
public Long lastSave() {
try {
if (isPipelined()) {

View File

@@ -458,6 +458,16 @@ public abstract class AbstractConnectionIntegrationTests {
assertNotNull(version);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
Properties info = connection.info("server");
assertNotNull(info);
assertTrue("at least 5 settings should be present", info.size() >= 5);
String version = info.getProperty("redis_version");
assertNotNull(version);
}
@Test
public void testNullKey() throws Exception {
try {

View File

@@ -176,6 +176,12 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
super.testSRandMemberCountNegative();
}
@Test(expected=UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
super.testInfoBySection();
}
@Test
public void testIncrDecrByLong() {
String key = "test.count";

View File

@@ -363,6 +363,12 @@ public class JedisConnectionPipelineIntegrationTests extends
super.testSRandMemberCountNegative();
}
@Test(expected=UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
super.testInfoBySection();
}
// Overrides, usually due to return values being Long vs Boolean or Set vs
// List

View File

@@ -517,6 +517,12 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
super.testSRandMemberCountNegative();
}
@Test(expected=UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
super.testInfoBySection();
}
// Jredis returns null for rPush
@Test
public void testSort() {

View File

@@ -174,6 +174,18 @@ public class LettuceConnectionPipelineIntegrationTests extends
assertNotNull(version);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
assertNull(connection.info("server"));
List<Object> results = getResults();
assertEquals(1, results.size());
Properties info = LettuceUtils.info((String) results.get(0));
assertTrue("at least 5 settings should be present", info.size() >= 5);
String version = info.getProperty("redis_version");
assertNotNull(version);
}
@Test
public void testMSetNx() {
Map<String, String> vals = new HashMap<String, String>();

View File

@@ -50,6 +50,18 @@ public class LettuceConnectionPipelineTxIntegrationTests extends
assertNotNull(version);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
assertNull(connection.info("server"));
List<Object> results = getResults();
assertEquals(2, results.size());
Properties info = LettuceUtils.info((String) results.get(1));
assertTrue("at least 5 settings should be present", info.size() >= 5);
String version = info.getProperty("redis_version");
assertNotNull(version);
}
@Test(expected=RedisPipelineException.class)
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testRestoreBadData() {

View File

@@ -119,6 +119,18 @@ public class SrpConnectionPipelineIntegrationTests extends
assertNotNull(version);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6")
public void testInfoBySection() throws Exception {
assertNull(connection.info("server"));
List<Object> results = getResults();
assertEquals(1, results.size());
Properties info = SrpUtils.info(new BulkReply((byte[]) results.get(0)));
assertTrue("at least 5 settings should be present", info.size() >= 5);
String version = info.getProperty("redis_version");
assertNotNull(version);
}
@Test
public void testExists() {
connection.set("existent", "true");