diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 91d812c4d..e6c849129 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -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(); } diff --git a/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java index 001c92335..d3a220579 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java @@ -41,6 +41,8 @@ public interface RedisServerCommands { Properties info(); + Properties info(String section); + void shutdown(); List getConfig(String pattern); diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index a22f604ed..f532e700a 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -476,6 +476,11 @@ public class JedisConnection implements RedisConnection { } + public Properties info(String section) { + throw new UnsupportedOperationException(); + } + + public Long lastSave() { try { if (isQueueing()) { diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java index ef76bacae..6470497e4 100644 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java @@ -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(); diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index e5aab9e44..0a47192aa 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -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()) { diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java index 0d0a19b43..3b9394062 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java @@ -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()) { diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index 70922eaef..68454e611 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -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 { diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java index 2a32a90fb..ec4173e89 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java @@ -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"; diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java index f2a3468c3..29da1df34 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java @@ -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 diff --git a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java index dcadd5a8e..a5e78a682 100644 --- a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -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() { diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineIntegrationTests.java index 48f039637..420c62ecd 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineIntegrationTests.java @@ -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 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 vals = new HashMap(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineTxIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineTxIntegrationTests.java index 4f4c5197e..2784009a7 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineTxIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineTxIntegrationTests.java @@ -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 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() { diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineIntegrationTests.java index 142409422..d41df0a98 100644 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineIntegrationTests.java @@ -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 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");