getClientList();
}
diff --git a/src/main/java/org/springframework/data/redis/connection/convert/StringToRedisClientInfoConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/StringToRedisClientInfoConverter.java
new file mode 100644
index 0000000000..8c1fe74498
--- /dev/null
+++ b/src/main/java/org/springframework/data/redis/connection/convert/StringToRedisClientInfoConverter.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.redis.connection.convert;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.data.redis.core.types.RedisClientInfo;
+import org.springframework.data.redis.core.types.RedisClientInfo.RedisClientInfoBuilder;
+
+/**
+ * {@link Converter} implementation to create one {@link RedisClientInfo} per line entry in given {@link String} array.
+ *
+ *
+ * ## sample of single line
+ * addr=127.0.0.1:60311 fd=6 name= age=4059 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
+ *
+ *
+ * @author Christoph Strobl
+ * @since 1.3
+ */
+public class StringToRedisClientInfoConverter implements Converter> {
+
+ @Override
+ public List convert(String[] lines) {
+
+ if (lines == null) {
+ return Collections.emptyList();
+ }
+ List infos = new ArrayList(lines.length);
+ for (String line : lines) {
+ infos.add(RedisClientInfoBuilder.fromString(line));
+ }
+ return infos;
+ }
+
+}
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 406142381d..7671f965f7 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
@@ -42,6 +42,7 @@
import org.springframework.data.redis.connection.Subscription;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.convert.TransactionResultConverter;
+import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@@ -2854,6 +2855,18 @@ public String getClientName() {
return jedis.clientGetname();
}
+ /*
+ * @see org.springframework.data.redis.connection.RedisServerCommands#getClientName()
+ */
+ @Override
+ public List getClientList() {
+
+ if (isQueueing() || isPipelined()) {
+ throw new UnsupportedOperationException("'CLIENT LIST' is not supported in in pipeline / multi mode.");
+ }
+ return JedisConverters.toListOfRedisClientInformation(this.jedis.clientList());
+ }
+
/**
* Specifies if pipelined results should be converted to the expected data type. If false, results of
* {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Jedis driver
diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java
index 69c6a26639..b1bc248322 100644
--- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java
+++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 the original author or authors.
+ * Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package org.springframework.data.redis.connection.jedis;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -31,7 +33,10 @@
import org.springframework.data.redis.connection.convert.ListConverter;
import org.springframework.data.redis.connection.convert.MapConverter;
import org.springframework.data.redis.connection.convert.SetConverter;
+import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
+import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.BitOP;
@@ -42,6 +47,7 @@
* Jedis type converters
*
* @author Jennifer Hickey
+ * @author Christoph Strobl
*/
abstract public class JedisConverters extends Converters {
@@ -51,6 +57,7 @@ abstract public class JedisConverters extends Converters {
private static final MapConverter STRING_MAP_TO_BYTE_MAP;
private static final SetConverter TUPLE_SET_TO_TUPLE_SET;
private static final Converter EXCEPTION_CONVERTER = new JedisExceptionConverter();
+ private static final Converter> STRING_TO_CLIENT_INFO_CONVERTER = new StringToRedisClientInfoConverter();
static {
STRING_TO_BYTES = new Converter() {
@@ -114,6 +121,19 @@ public static String toString(byte[] source) {
return source == null ? null : SafeEncoder.encode(source);
}
+ /**
+ * @param source
+ * @return
+ * @since 1.3
+ */
+ public static List toListOfRedisClientInformation(String source) {
+
+ if (!StringUtils.hasText(source)) {
+ return Collections.emptyList();
+ }
+ return STRING_TO_CLIENT_INFO_CONVERTER.convert(source.split("\\r?\\n"));
+ }
+
public static DataAccessException toDataAccessException(Exception ex) {
return EXCEPTION_CONVERTER.convert(ex);
}
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 24613a97f3..1f2b538a4f 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
@@ -43,6 +43,7 @@
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.Subscription;
+import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@@ -1204,4 +1205,8 @@ public void setClientName(byte[] name) {
public String getClientName() {
throw new UnsupportedOperationException("The 'CLIENT GETNAME' command is not supported by the JRedis driver.");
}
+
+ public List getClientList() {
+ throw new UnsupportedOperationException();
+ }
}
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 aa1750e253..4483b6c5ac 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
@@ -49,6 +49,7 @@
import org.springframework.data.redis.connection.Subscription;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.convert.TransactionResultConverter;
+import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -2959,6 +2960,21 @@ public String getClientName() {
}
}
+ @Override
+ public List getClientList() {
+
+ if (isPipelined()) {
+ throw new UnsupportedOperationException("Cannot be called in pipeline mode.");
+ }
+ if (isQueueing()) {
+ transaction(new LettuceTxResult(getAsyncConnection().clientList(),
+ LettuceConverters.stringToRedisClientListConverter()));
+ return null;
+ }
+
+ return LettuceConverters.toListOfRedisClientInformation(getConnection().clientList());
+ }
+
/**
* Specifies if pipelined and transaction results should be converted to the expected data type. If false, results of
* {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Lettuce driver
diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java
index 11cac3959a..6e5604c181 100644
--- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java
+++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java
@@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
@@ -31,7 +32,10 @@
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.SortParameters.Order;
import org.springframework.data.redis.connection.convert.Converters;
+import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
+import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
import com.lambdaworks.redis.KeyValue;
import com.lambdaworks.redis.ScoredValue;
@@ -55,6 +59,8 @@ abstract public class LettuceConverters extends Converters {
private static final Converter, Tuple> SCORED_VALUE_TO_TUPLE;
private static final Converter EXCEPTION_CONVERTER = new LettuceExceptionConverter();
+ private static final Converter> STRING_TO_LIST_OF_CLIENT_INFO = new StringToRedisClientInfoConverter();
+
static {
DATE_TO_LONG = new Converter() {
public Long convert(Date source) {
@@ -115,6 +121,20 @@ public Tuple convert(ScoredValue source) {
};
}
+ public static Converter> stringToRedisClientListConverter() {
+ return new Converter>() {
+
+ @Override
+ public List convert(String source) {
+ if (!StringUtils.hasText(source)) {
+ return Collections.emptyList();
+ }
+
+ return STRING_TO_LIST_OF_CLIENT_INFO.convert(source.split("\\r?\\n"));
+ }
+ };
+ }
+
public static Converter dateToLong() {
return DATE_TO_LONG;
}
@@ -235,4 +255,8 @@ public static SortArgs toSortArgs(SortParameters params) {
}
return args;
}
+
+ public static List toListOfRedisClientInformation(String clientList) {
+ return stringToRedisClientListConverter().convert(clientList);
+ }
}
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 7ebb9a5c43..65afaed30c 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
@@ -40,6 +40,7 @@
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.Subscription;
+import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
import redis.Command;
@@ -2280,6 +2281,19 @@ public String getClientName() {
}
}
+ @Override
+ public List getClientList() {
+ if (isQueueing()) {
+ throw new UnsupportedOperationException();
+ }
+ if (isPipelined()) {
+ pipeline(new SrpGenericResult(pipeline.client_list(), SrpConverters.replyToListOfRedisClientInfo()));
+ return null;
+ }
+
+ return SrpConverters.toListOfRedisClientInformation(this.client.client_list());
+ }
+
private List