diff --git a/src/main/java/org/springframework/data/redis/RedisSystemException.java b/src/main/java/org/springframework/data/redis/RedisSystemException.java index 9174189ce..a7de1a349 100644 --- a/src/main/java/org/springframework/data/redis/RedisSystemException.java +++ b/src/main/java/org/springframework/data/redis/RedisSystemException.java @@ -20,7 +20,7 @@ import org.springframework.dao.UncategorizedDataAccessException; /** * Exception thrown when we can't classify a Redis exception into one of Spring generic data access exceptions. - * + * * @author Costin Leau */ public class RedisSystemException extends UncategorizedDataAccessException { diff --git a/src/main/java/org/springframework/data/redis/cache/DefaultRedisCachePrefix.java b/src/main/java/org/springframework/data/redis/cache/DefaultRedisCachePrefix.java index 4df5abe7e..80ecd4b06 100644 --- a/src/main/java/org/springframework/data/redis/cache/DefaultRedisCachePrefix.java +++ b/src/main/java/org/springframework/data/redis/cache/DefaultRedisCachePrefix.java @@ -20,7 +20,8 @@ import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; /** - * Default implementation for {@link RedisCachePrefix} which uses the given cache name and a delimiter for creating the prefix. + * Default implementation for {@link RedisCachePrefix} which uses the given cache name and a delimiter for creating the + * prefix. * * @author Costin Leau */ diff --git a/src/main/java/org/springframework/data/redis/cache/RedisCache.java b/src/main/java/org/springframework/data/redis/cache/RedisCache.java index 1c3ba0630..5beddb9e1 100644 --- a/src/main/java/org/springframework/data/redis/cache/RedisCache.java +++ b/src/main/java/org/springframework/data/redis/cache/RedisCache.java @@ -39,8 +39,7 @@ class RedisCache implements Cache { private static final int PAGE_SIZE = 128; private final String name; - @SuppressWarnings("rawtypes") - private final RedisTemplate template; + @SuppressWarnings("rawtypes") private final RedisTemplate template; private final byte[] prefix; private final byte[] setName; private final byte[] cacheLockName; @@ -48,9 +47,8 @@ class RedisCache implements Cache { private final long expiration; /** - * * Constructs a new RedisCache instance. - * + * * @param name cache name * @param prefix * @param template @@ -76,10 +74,8 @@ class RedisCache implements Cache { } /** - * {@inheritDoc} - * - * This implementation simply returns the RedisTemplate used for configuring the cache, giving access - * to the underlying Redis store. + * {@inheritDoc} This implementation simply returns the RedisTemplate used for configuring the cache, giving access to + * the underlying Redis store. */ public Object getNativeCache() { return template; @@ -96,14 +92,14 @@ class RedisCache implements Cache { } }, true); } - + /** - * Return the value to which this cache maps the specified key, generically specifying a type that return value will be cast to. + * Return the value to which this cache maps the specified key, generically specifying a type that return value will + * be cast to. * * @param key * @param type * @return - * * @see DATAREDIS-243 */ public T get(Object key, Class type) { @@ -112,7 +108,6 @@ class RedisCache implements Cache { return wrapper == null ? null : (T) wrapper.get(); } - public void put(final Object key, final Object value) { final byte[] k = computeKey(key); @@ -121,8 +116,8 @@ class RedisCache implements Cache { waitForLock(connection); connection.multi(); byte[] v; - if(template.getValueSerializer() == null && value instanceof byte[]) { - v = (byte[])value; + if (template.getValueSerializer() == null && value instanceof byte[]) { + v = (byte[]) value; } else { v = template.getValueSerializer().serialize(value); } @@ -141,7 +136,6 @@ class RedisCache implements Cache { }, true); } - public void evict(Object key) { final byte[] k = computeKey(key); @@ -155,7 +149,6 @@ class RedisCache implements Cache { }, true); } - public void clear() { // need to del each key individually template.execute(new RedisCallback() { @@ -173,8 +166,7 @@ class RedisCache implements Cache { do { // need to paginate the keys - Set keys = connection.zRange(setName, (offset) * PAGE_SIZE, (offset + 1) * PAGE_SIZE - - 1); + Set keys = connection.zRange(setName, (offset) * PAGE_SIZE, (offset + 1) * PAGE_SIZE - 1); finished = keys.size() < PAGE_SIZE; offset++; if (!keys.isEmpty()) { @@ -193,8 +185,8 @@ class RedisCache implements Cache { } private byte[] computeKey(Object key) { - if(template.getKeySerializer() == null && key instanceof byte[]) { - return (byte[])key; + if (template.getKeySerializer() == null && key instanceof byte[]) { + return (byte[]) key; } byte[] k = template.getKeySerializer().serialize(key); @@ -223,4 +215,4 @@ class RedisCache implements Cache { } while (retry); return foundLock; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java b/src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java index 9753d5dff..2238dcdde 100644 --- a/src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java +++ b/src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java @@ -27,10 +27,9 @@ import org.springframework.cache.CacheManager; import org.springframework.data.redis.core.RedisTemplate; /** - * CacheManager implementation for Redis. - * By default saves the keys directly, without appending a prefix (which acts as a namespace). - * To avoid clashes, it is recommended to change this (by setting 'usePrefix' to 'true'). - * For performance reasons, the current implementation uses a set for the keys in each cache. + * CacheManager implementation for Redis. By default saves the keys directly, without appending a prefix (which acts as + * a namespace). To avoid clashes, it is recommended to change this (by setting 'usePrefix' to 'true'). For performance + * reasons, the current implementation uses a set for the keys in each cache. * * @author Costin Leau */ @@ -81,7 +80,7 @@ public class RedisCacheManager implements CacheManager { /** * Sets the cachePrefix. Defaults to 'DefaultRedisCachePrefix'). - * + * * @param cachePrefix the cachePrefix to set */ public void setCachePrefix(RedisCachePrefix cachePrefix) { @@ -90,7 +89,7 @@ public class RedisCacheManager implements CacheManager { /** * Sets the default expire time (in seconds). - * + * * @param defaultExpireTime time in seconds. */ public void setDefaultExpiration(long defaultExpireTime) { @@ -99,10 +98,10 @@ public class RedisCacheManager implements CacheManager { /** * Sets the expire time (in seconds) for cache regions (by key). - * + * * @param expires time in seconds */ public void setExpires(Map expires) { this.expires = (expires != null ? new ConcurrentHashMap(expires) : null); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/cache/RedisCachePrefix.java b/src/main/java/org/springframework/data/redis/cache/RedisCachePrefix.java index d64ea2cfa..8a7aef4cb 100644 --- a/src/main/java/org/springframework/data/redis/cache/RedisCachePrefix.java +++ b/src/main/java/org/springframework/data/redis/cache/RedisCachePrefix.java @@ -17,17 +17,17 @@ package org.springframework.data.redis.cache; /** - * Contract for generating 'prefixes' for Cache keys saved in Redis. - * Due to the 'flat' nature of the Redis storage, the prefix is used as a 'namespace' for grouping the key/values inside a cache (and - * to avoid collision with other caches or keys inside Redis). + * Contract for generating 'prefixes' for Cache keys saved in Redis. Due to the 'flat' nature of the Redis storage, the + * prefix is used as a 'namespace' for grouping the key/values inside a cache (and to avoid collision with other caches + * or keys inside Redis). * * @author Costin Leau */ public interface RedisCachePrefix { /** - * Returns the prefix for the given cache (identified by name). - * Note the prefix is returned in raw form so it can be saved directly to Redis without any serialization. + * Returns the prefix for the given cache (identified by name). Note the prefix is returned in raw form so it can be + * saved directly to Redis without any serialization. * * @param cacheName the name of the cache using the prefix * @return the prefix for the given cache. diff --git a/src/main/java/org/springframework/data/redis/config/RedisCollectionParser.java b/src/main/java/org/springframework/data/redis/config/RedisCollectionParser.java index 5c7a40849..083148569 100644 --- a/src/main/java/org/springframework/data/redis/config/RedisCollectionParser.java +++ b/src/main/java/org/springframework/data/redis/config/RedisCollectionParser.java @@ -28,12 +28,10 @@ import org.w3c.dom.Element; */ class RedisCollectionParser extends AbstractSimpleBeanDefinitionParser { - protected Class getBeanClass(Element element) { return RedisCollectionFactoryBean.class; } - protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { String template = element.getAttribute("template"); if (StringUtils.hasText(template)) { @@ -41,7 +39,6 @@ class RedisCollectionParser extends AbstractSimpleBeanDefinitionParser { } } - protected boolean isEligibleAttribute(String attributeName) { return super.isEligibleAttribute(attributeName) && (!"template".equals(attributeName)); } diff --git a/src/main/java/org/springframework/data/redis/config/RedisListenerContainerParser.java b/src/main/java/org/springframework/data/redis/config/RedisListenerContainerParser.java index ee81ed99f..2c66ca935 100644 --- a/src/main/java/org/springframework/data/redis/config/RedisListenerContainerParser.java +++ b/src/main/java/org/springframework/data/redis/config/RedisListenerContainerParser.java @@ -43,17 +43,15 @@ import org.w3c.dom.NamedNodeMap; */ class RedisListenerContainerParser extends AbstractSimpleBeanDefinitionParser { - protected Class getBeanClass(Element element) { return RedisMessageListenerContainer.class; } @SuppressWarnings("unchecked") - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { // parse attributes (but replace the value assignment with references) NamedNodeMap attributes = element.getAttributes(); - + for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); if (isEligibleAttribute(attribute, parserContext)) { @@ -87,13 +85,13 @@ class RedisListenerContainerParser extends AbstractSimpleBeanDefinitionParser { } } - protected boolean isEligibleAttribute(String attributeName) { return (!"phase".equals(attributeName)); } /** - * Parses a listener definition. Returns the listener bean reference definition (as the array first entry) and its associated topics (also as bean definitions). + * Parses a listener definition. Returns the listener bean reference definition (as the array first entry) and its + * associated topics (also as bean definitions). * * @param element * @return @@ -103,17 +101,17 @@ class RedisListenerContainerParser extends AbstractSimpleBeanDefinitionParser { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessageListenerAdapter.class); builder.addConstructorArgReference(element.getAttribute("ref")); - + String method = element.getAttribute("method"); - if (StringUtils.hasText(method)){ - builder.addPropertyValue("defaultListenerMethod", method); + if (StringUtils.hasText(method)) { + builder.addPropertyValue("defaultListenerMethod", method); } - + String serializer = element.getAttribute("serializer"); - if (StringUtils.hasText(serializer)){ + if (StringUtils.hasText(serializer)) { builder.addPropertyReference("serializer", serializer); } - + // assemble topics Collection topics = new ArrayList(); @@ -132,8 +130,7 @@ class RedisListenerContainerParser extends AbstractSimpleBeanDefinitionParser { return ret; } - protected boolean shouldGenerateId() { return true; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/config/RedisNamespaceHandler.java b/src/main/java/org/springframework/data/redis/config/RedisNamespaceHandler.java index e8825f6f8..080681251 100644 --- a/src/main/java/org/springframework/data/redis/config/RedisNamespaceHandler.java +++ b/src/main/java/org/springframework/data/redis/config/RedisNamespaceHandler.java @@ -25,7 +25,6 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport; */ class RedisNamespaceHandler extends NamespaceHandlerSupport { - public void init() { registerBeanDefinitionParser("listener-container", new RedisListenerContainerParser()); registerBeanDefinitionParser("collection", new RedisCollectionParser()); diff --git a/src/main/java/org/springframework/data/redis/connection/ConnectionUtils.java b/src/main/java/org/springframework/data/redis/connection/ConnectionUtils.java index 65d4abb47..9ba1ccca8 100644 --- a/src/main/java/org/springframework/data/redis/connection/ConnectionUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/ConnectionUtils.java @@ -22,10 +22,9 @@ import org.springframework.data.redis.connection.srp.SrpConnectionFactory; /** * Utilities for examining a {@link RedisConnection} - * + * * @author Jennifer Hickey * @author Thomas Darimont - * */ public abstract class ConnectionUtils { diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultMessage.java b/src/main/java/org/springframework/data/redis/connection/DefaultMessage.java index db003f47f..946728c5f 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultMessage.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultMessage.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.connection; - /** * Default message implementation. * @@ -32,19 +31,16 @@ public class DefaultMessage implements Message { this.channel = channel; } - public byte[] getChannel() { return (channel != null ? channel.clone() : null); } - public byte[] getBody() { return (body != null ? body.clone() : null); } - public String toString() { - if (toString == null){ + if (toString == null) { toString = new String(body); } return toString; diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultSortParameters.java b/src/main/java/org/springframework/data/redis/connection/DefaultSortParameters.java index 6965abf9b..d4303e05c 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultSortParameters.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultSortParameters.java @@ -18,7 +18,6 @@ package org.springframework.data.redis.connection; import java.util.ArrayList; import java.util.List; - /** * Default implementation for {@link SortParameters}. * @@ -41,7 +40,7 @@ public class DefaultSortParameters implements SortParameters { /** * Constructs a new DefaultSortParameters instance. - * + * * @param limit * @param order * @param alphabetic @@ -52,7 +51,7 @@ public class DefaultSortParameters implements SortParameters { /** * Constructs a new DefaultSortParameters instance. - * + * * @param byPattern * @param limit * @param getPattern @@ -68,7 +67,6 @@ public class DefaultSortParameters implements SortParameters { setGetPattern(getPattern); } - public byte[] getByPattern() { return byPattern; } @@ -77,7 +75,6 @@ public class DefaultSortParameters implements SortParameters { this.byPattern = byPattern; } - public Range getLimit() { return limit; } @@ -86,7 +83,6 @@ public class DefaultSortParameters implements SortParameters { this.limit = limit; } - public byte[][] getGetPattern() { return getPattern.toArray(new byte[getPattern.size()][]); } @@ -98,7 +94,7 @@ public class DefaultSortParameters implements SortParameters { public void setGetPattern(byte[][] gPattern) { getPattern.clear(); - if(gPattern == null) { + if (gPattern == null) { return; } @@ -107,7 +103,6 @@ public class DefaultSortParameters implements SortParameters { } } - public Order getOrder() { return order; } @@ -116,7 +111,6 @@ public class DefaultSortParameters implements SortParameters { this.order = order; } - public Boolean isAlphabetic() { return alphabetic; } @@ -168,4 +162,4 @@ public class DefaultSortParameters implements SortParameters { setLimit(new Range(start, count)); return this; } -} \ No newline at end of file +} 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 0a493e170..d5693c450 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -47,26 +47,26 @@ public class DefaultStringRedisConnection implements StringRedisConnection { private final Log log = LogFactory.getLog(DefaultStringRedisConnection.class); private final RedisConnection delegate; private final RedisSerializer serializer; - private Converter bytesToString = new DeserializingConverter(); - private SetConverter tupleToStringTuple = new SetConverter(new TupleConverter()); - private SetConverter stringTupleToTuple = new SetConverter(new StringTupleConverter()); - private ListConverter byteListToStringList = new ListConverter(bytesToString); - private MapConverter byteMapToStringMap = new MapConverter(bytesToString); - private SetConverter byteSetToStringSet = new SetConverter(bytesToString); - @SuppressWarnings("rawtypes") - private Queue pipelineConverters = new LinkedList(); - @SuppressWarnings("rawtypes") - private Queue txConverters = new LinkedList(); + private Converter bytesToString = new DeserializingConverter(); + private SetConverter tupleToStringTuple = new SetConverter( + new TupleConverter()); + private SetConverter stringTupleToTuple = new SetConverter( + new StringTupleConverter()); + private ListConverter byteListToStringList = new ListConverter(bytesToString); + private MapConverter byteMapToStringMap = new MapConverter(bytesToString); + private SetConverter byteSetToStringSet = new SetConverter(bytesToString); + @SuppressWarnings("rawtypes") private Queue pipelineConverters = new LinkedList(); + @SuppressWarnings("rawtypes") private Queue txConverters = new LinkedList(); private boolean deserializePipelineAndTxResults = false; private IdentityConverter identityConverter = new IdentityConverter(); - private class DeserializingConverter implements Converter { + private class DeserializingConverter implements Converter { public String convert(byte[] source) { return serializer.deserialize(source); } } - private class TupleConverter implements Converter { + private class TupleConverter implements Converter { public StringTuple convert(Tuple source) { return new DefaultStringTuple(source, serializer.deserialize(source.getValue())); } @@ -98,9 +98,9 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } /** - * Constructs a new DefaultStringRedisConnection instance. - * Uses {@link StringRedisSerializer} as underlying serializer. - * + * Constructs a new DefaultStringRedisConnection instance. Uses {@link StringRedisSerializer} as + * underlying serializer. + * * @param connection Redis connection */ public DefaultStringRedisConnection(RedisConnection connection) { @@ -111,7 +111,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { /** * Constructs a new DefaultStringRedisConnection instance. - * + * * @param connection Redis connection * @param serializer String serializer */ @@ -123,8 +123,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Long append(byte[] key, byte[] value) { - Long result = delegate.append(key,value); - if(isFutureConversion()) { + Long result = delegate.append(key, value); + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -140,7 +140,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List bLPop(int timeout, byte[]... keys) { List results = delegate.bLPop(timeout, keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -148,7 +148,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List bRPop(int timeout, byte[]... keys) { List results = delegate.bRPop(timeout, keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -156,7 +156,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { byte[] result = delegate.bRPopLPush(timeout, srcKey, dstKey); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -168,7 +168,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long dbSize() { Long result = delegate.dbSize(); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -176,7 +176,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long decr(byte[] key) { Long result = delegate.decr(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -184,7 +184,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long decrBy(byte[] key, long value) { Long result = delegate.decrBy(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -192,7 +192,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long del(byte[]... keys) { Long result = delegate.del(keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -208,7 +208,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] echo(byte[] message) { byte[] result = delegate.echo(message); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -218,7 +218,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List exec() { try { List results = delegate.exec(); - if(isPipelined()) { + if (isPipelined()) { pipelineConverters.add(new TransactionResultConverter(new LinkedList(txConverters))); return results; } @@ -229,8 +229,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } public Boolean exists(byte[] key) { - Boolean result = delegate.exists(key); - if(isFutureConversion()) { + Boolean result = delegate.exists(key); + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -238,7 +238,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean expire(byte[] key, long seconds) { Boolean result = delegate.expire(key, seconds); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -246,7 +246,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean expireAt(byte[] key, long unixTime) { Boolean result = delegate.expireAt(key, unixTime); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -262,7 +262,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] get(byte[] key) { byte[] result = delegate.get(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -270,7 +270,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean getBit(byte[] key, long offset) { Boolean result = delegate.getBit(key, offset); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -278,7 +278,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List getConfig(String pattern) { List results = delegate.getConfig(pattern); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -286,7 +286,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Object getNativeConnection() { Object result = delegate.getNativeConnection(); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -294,7 +294,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] getRange(byte[] key, long start, long end) { byte[] result = delegate.getRange(key, start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -302,7 +302,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] getSet(byte[] key, byte[] value) { byte[] result = delegate.getSet(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -314,7 +314,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long hDel(byte[] key, byte[]... fields) { Long result = delegate.hDel(key, fields); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -322,7 +322,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean hExists(byte[] key, byte[] field) { Boolean result = delegate.hExists(key, field); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -330,15 +330,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] hGet(byte[] key, byte[] field) { byte[] result = delegate.hGet(key, field); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } public Map hGetAll(byte[] key) { - Map results = delegate.hGetAll(key); - if(isFutureConversion()) { + Map results = delegate.hGetAll(key); + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -346,7 +346,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long hIncrBy(byte[] key, byte[] field, long delta) { Long result = delegate.hIncrBy(key, field, delta); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -354,7 +354,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Double hIncrBy(byte[] key, byte[] field, double delta) { Double result = delegate.hIncrBy(key, field, delta); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -362,7 +362,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set hKeys(byte[] key) { Set results = delegate.hKeys(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -370,7 +370,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long hLen(byte[] key) { Long result = delegate.hLen(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -378,7 +378,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List hMGet(byte[] key, byte[]... fields) { List results = delegate.hMGet(key, fields); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -390,7 +390,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean hSet(byte[] key, byte[] field, byte[] value) { Boolean result = delegate.hSet(key, field, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -398,7 +398,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { Boolean result = delegate.hSetNX(key, field, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -406,7 +406,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List hVals(byte[] key) { List results = delegate.hVals(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -414,7 +414,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long incr(byte[] key) { Long result = delegate.incr(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -422,7 +422,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long incrBy(byte[] key, long value) { Long result = delegate.incrBy(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -430,7 +430,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Double incrBy(byte[] key, double value) { Double result = delegate.incrBy(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -438,7 +438,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Properties info() { Properties result = delegate.info(); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -446,7 +446,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Properties info(String section) { Properties result = delegate.info(section); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -466,7 +466,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set keys(byte[] pattern) { Set results = delegate.keys(pattern); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -474,7 +474,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long lastSave() { Long result = delegate.lastSave(); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -482,7 +482,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] lIndex(byte[] key, long index) { byte[] result = delegate.lIndex(key, index); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -490,7 +490,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { Long result = delegate.lInsert(key, where, pivot, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -498,7 +498,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long lLen(byte[] key) { Long result = delegate.lLen(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -506,7 +506,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] lPop(byte[] key) { byte[] result = delegate.lPop(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -514,7 +514,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long lPush(byte[] key, byte[]... values) { Long result = delegate.lPush(key, values); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -522,7 +522,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long lPushX(byte[] key, byte[] value) { Long result = delegate.lPushX(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -530,7 +530,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List lRange(byte[] key, long start, long end) { List results = delegate.lRange(key, start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -538,7 +538,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long lRem(byte[] key, long count, byte[] value) { Long result = delegate.lRem(key, count, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -554,7 +554,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List mGet(byte[]... keys) { List results = delegate.mGet(keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -566,7 +566,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean mSetNX(Map tuple) { Boolean result = delegate.mSetNX(tuple); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -578,7 +578,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean persist(byte[] key) { Boolean result = delegate.persist(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -586,7 +586,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean move(byte[] key, int dbIndex) { Boolean result = delegate.move(key, dbIndex); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -594,7 +594,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public String ping() { String result = delegate.ping(); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -606,7 +606,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long publish(byte[] channel, byte[] message) { Long result = delegate.publish(channel, message); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -614,7 +614,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] randomKey() { byte[] result = delegate.randomKey(); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -626,7 +626,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean renameNX(byte[] oldName, byte[] newName) { Boolean result = delegate.renameNX(oldName, newName); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -638,7 +638,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] rPop(byte[] key) { byte[] result = delegate.rPop(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -646,7 +646,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { byte[] result = delegate.rPopLPush(srcKey, dstKey); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -654,7 +654,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long rPush(byte[] key, byte[]... values) { Long result = delegate.rPush(key, values); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -662,7 +662,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long rPushX(byte[] key, byte[] value) { Long result = delegate.rPushX(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -670,7 +670,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long sAdd(byte[] key, byte[]... values) { Long result = delegate.sAdd(key, values); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -682,7 +682,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long sCard(byte[] key) { Long result = delegate.sCard(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -690,7 +690,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set sDiff(byte[]... keys) { Set results = delegate.sDiff(keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -698,7 +698,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long sDiffStore(byte[] destKey, byte[]... keys) { Long result = delegate.sDiffStore(destKey, keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -726,7 +726,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean setNX(byte[] key, byte[] value) { Boolean result = delegate.setNX(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -742,7 +742,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set sInter(byte[]... keys) { Set results = delegate.sInter(keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -750,7 +750,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long sInterStore(byte[] destKey, byte[]... keys) { Long result = delegate.sInterStore(destKey, keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -758,7 +758,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean sIsMember(byte[] key, byte[] value) { Boolean result = delegate.sIsMember(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -766,7 +766,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set sMembers(byte[] key) { Set results = delegate.sMembers(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -774,7 +774,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { Boolean result = delegate.sMove(srcKey, destKey, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -782,7 +782,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long sort(byte[] key, SortParameters params, byte[] storeKey) { Long result = delegate.sort(key, params, storeKey); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -790,7 +790,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List sort(byte[] key, SortParameters params) { List results = delegate.sort(key, params); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -798,7 +798,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] sPop(byte[] key) { byte[] result = delegate.sPop(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -806,7 +806,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] sRandMember(byte[] key) { byte[] result = delegate.sRandMember(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -814,7 +814,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List sRandMember(byte[] key, long count) { List results = delegate.sRandMember(key, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -822,7 +822,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long sRem(byte[] key, byte[]... values) { Long result = delegate.sRem(key, values); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -830,7 +830,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long strLen(byte[] key) { Long result = delegate.strLen(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -838,7 +838,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long bitCount(byte[] key) { Long result = delegate.bitCount(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -846,7 +846,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long bitCount(byte[] key, long begin, long end) { Long result = delegate.bitCount(key, begin, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -854,7 +854,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { Long result = delegate.bitOp(op, destination, keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -866,7 +866,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set sUnion(byte[]... keys) { Set results = delegate.sUnion(keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -874,7 +874,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long sUnionStore(byte[] destKey, byte[]... keys) { Long result = delegate.sUnionStore(destKey, keys); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -882,7 +882,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long ttl(byte[] key) { Long result = delegate.ttl(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -890,7 +890,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public DataType type(byte[] key) { DataType result = delegate.type(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -906,7 +906,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean zAdd(byte[] key, double score, byte[] value) { Boolean result = delegate.zAdd(key, score, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -914,7 +914,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zAdd(byte[] key, Set tuples) { Long result = delegate.zAdd(key, tuples); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -922,7 +922,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zCard(byte[] key) { Long result = delegate.zCard(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -930,7 +930,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zCount(byte[] key, double min, double max) { Long result = delegate.zCount(key, min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -938,7 +938,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Double zIncrBy(byte[] key, double increment, byte[] value) { Double result = delegate.zIncrBy(key, increment, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -946,7 +946,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { Long result = delegate.zInterStore(destKey, aggregate, weights, sets); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -954,7 +954,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zInterStore(byte[] destKey, byte[]... sets) { Long result = delegate.zInterStore(destKey, sets); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -962,7 +962,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRange(byte[] key, long start, long end) { Set results = delegate.zRange(key, start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -970,7 +970,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { Set results = delegate.zRangeByScore(key, min, max, offset, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -978,7 +978,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRangeByScore(byte[] key, double min, double max) { Set results = delegate.zRangeByScore(key, min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -986,7 +986,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { Set results = delegate.zRangeByScoreWithScores(key, min, max, offset, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -994,7 +994,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRangeByScoreWithScores(byte[] key, double min, double max) { Set results = delegate.zRangeByScoreWithScores(key, min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1002,7 +1002,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRangeWithScores(byte[] key, long start, long end) { Set results = delegate.zRangeWithScores(key, start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1010,7 +1010,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { Set results = delegate.zRevRangeByScore(key, min, max, offset, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1018,7 +1018,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRevRangeByScore(byte[] key, double min, double max) { Set results = delegate.zRevRangeByScore(key, min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1026,7 +1026,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { Set results = delegate.zRevRangeByScoreWithScores(key, min, max, offset, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1034,7 +1034,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { Set results = delegate.zRevRangeByScoreWithScores(key, min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1042,7 +1042,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zRank(byte[] key, byte[] value) { Long result = delegate.zRank(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1050,7 +1050,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zRem(byte[] key, byte[]... values) { Long result = delegate.zRem(key, values); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1058,7 +1058,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zRemRange(byte[] key, long start, long end) { Long result = delegate.zRemRange(key, start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1066,7 +1066,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zRemRangeByScore(byte[] key, double min, double max) { Long result = delegate.zRemRangeByScore(key, min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1074,7 +1074,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRevRange(byte[] key, long start, long end) { Set results = delegate.zRevRange(key, start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1082,7 +1082,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRevRangeWithScores(byte[] key, long start, long end) { Set results = delegate.zRevRangeWithScores(key, start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1090,7 +1090,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zRevRank(byte[] key, byte[] value) { Long result = delegate.zRevRank(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1098,7 +1098,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Double zScore(byte[] key, byte[] value) { Double result = delegate.zScore(key, value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1106,7 +1106,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { Long result = delegate.zUnionStore(destKey, aggregate, weights, sets); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1114,7 +1114,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zUnionStore(byte[] destKey, byte[]... sets) { Long result = delegate.zUnionStore(destKey, sets); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1122,7 +1122,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean pExpire(byte[] key, long millis) { Boolean result = delegate.pExpire(key, millis); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1130,7 +1130,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { Boolean result = delegate.pExpireAt(key, unixTimeInMillis); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1138,7 +1138,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long pTtl(byte[] key) { Long result = delegate.pTtl(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1146,7 +1146,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public byte[] dump(byte[] key) { byte[] result = delegate.dump(key); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1166,7 +1166,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public String scriptLoad(byte[] script) { String result = delegate.scriptLoad(script); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1174,7 +1174,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List scriptExists(String... scriptSha1) { List results = delegate.scriptExists(scriptSha1); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return results; @@ -1182,7 +1182,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { T result = delegate.eval(script, returnType, numKeys, keysAndArgs); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1190,7 +1190,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { T result = delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1216,7 +1216,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { private Map serialize(Map hashes) { Map ret = new LinkedHashMap(hashes.size()); - + for (Map.Entry entry : hashes.entrySet()) { ret.put(serializer.serialize(entry.getKey()), serializer.serialize(entry.getValue())); } @@ -1224,181 +1224,161 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return ret; } - public Long append(String key, String value) { Long result = delegate.append(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public List bLPop(int timeout, String... keys) { List results = delegate.bLPop(timeout, serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteListToStringList); } return byteListToStringList.convert(results); } - public List bRPop(int timeout, String... keys) { List results = delegate.bRPop(timeout, serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteListToStringList); } return byteListToStringList.convert(results); } - public String bRPopLPush(int timeout, String srcKey, String dstKey) { byte[] result = delegate.bRPopLPush(timeout, serialize(srcKey), serialize(dstKey)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public Long decr(String key) { Long result = delegate.decr(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long decrBy(String key, long value) { Long result = delegate.decrBy(serialize(key), value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long del(String... keys) { Long result = delegate.del(serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public String echo(String message) { byte[] result = delegate.echo(serialize(message)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public Boolean exists(String key) { Boolean result = delegate.exists(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Boolean expire(String key, long seconds) { Boolean result = delegate.expire(serialize(key), seconds); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Boolean expireAt(String key, long unixTime) { Boolean result = delegate.expireAt(serialize(key), unixTime); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public String get(String key) { byte[] result = delegate.get(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public Boolean getBit(String key, long offset) { Boolean result = delegate.getBit(serialize(key), offset); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public String getRange(String key, long start, long end) { byte[] result = delegate.getRange(serialize(key), start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public String getSet(String key, String value) { byte[] result = delegate.getSet(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public Long hDel(String key, String... fields) { Long result = delegate.hDel(serialize(key), serializeMulti(fields)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Boolean hExists(String key, String field) { Boolean result = delegate.hExists(serialize(key), serialize(field)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public String hGet(String key, String field) { byte[] result = delegate.hGet(serialize(key), serialize(field)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public Map hGetAll(String key) { - Map results = delegate.hGetAll(serialize(key)); - if(isFutureConversion()) { + Map results = delegate.hGetAll(serialize(key)); + if (isFutureConversion()) { addResultConverter(byteMapToStringMap); } return byteMapToStringMap.convert(results); } - public Long hIncrBy(String key, String field, long delta) { Long result = delegate.hIncrBy(serialize(key), serialize(field), delta); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1406,82 +1386,75 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Double hIncrBy(String key, String field, double delta) { Double result = delegate.hIncrBy(serialize(key), serialize(field), delta); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - + public Set hKeys(String key) { Set results = delegate.hKeys(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Long hLen(String key) { Long result = delegate.hLen(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public List hMGet(String key, String... fields) { List results = delegate.hMGet(serialize(key), serializeMulti(fields)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteListToStringList); } return byteListToStringList.convert(results); } - + public void hMSet(String key, Map hashes) { delegate.hMSet(serialize(key), serialize(hashes)); } - public Boolean hSet(String key, String field, String value) { Boolean result = delegate.hSet(serialize(key), serialize(field), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Boolean hSetNX(String key, String field, String value) { Boolean result = delegate.hSetNX(serialize(key), serialize(field), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public List hVals(String key) { List results = delegate.hVals(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteListToStringList); } return byteListToStringList.convert(results); } - public Long incr(String key) { Long result = delegate.incr(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long incrBy(String key, long value) { Long result = delegate.incrBy(serialize(key), value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1489,7 +1462,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Double incrBy(String key, double value) { Double result = delegate.incrBy(serialize(key), value); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1497,340 +1470,299 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Collection keys(String pattern) { Set results = delegate.keys(serialize(pattern)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public String lIndex(String key, long index) { byte[] result = delegate.lIndex(serialize(key), index); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public Long lInsert(String key, Position where, String pivot, String value) { Long result = delegate.lInsert(serialize(key), where, serialize(pivot), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long lLen(String key) { Long result = delegate.lLen(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public String lPop(String key) { byte[] result = delegate.lPop(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public Long lPush(String key, String... values) { Long result = delegate.lPush(serialize(key), serializeMulti(values)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long lPushX(String key, String value) { Long result = delegate.lPushX(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public List lRange(String key, long start, long end) { List results = delegate.lRange(serialize(key), start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteListToStringList); } return byteListToStringList.convert(results); } - public Long lRem(String key, long count, String value) { Long result = delegate.lRem(serialize(key), count, serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public void lSet(String key, long index, String value) { delegate.lSet(serialize(key), index, serialize(value)); } - public void lTrim(String key, long start, long end) { delegate.lTrim(serialize(key), start, end); } - public List mGet(String... keys) { List results = delegate.mGet(serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteListToStringList); } return byteListToStringList.convert(results); } - public Boolean mSetNXString(Map tuple) { Boolean result = delegate.mSetNX(serialize(tuple)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public void mSetString(Map tuple) { delegate.mSet(serialize(tuple)); } - public Boolean persist(String key) { Boolean result = delegate.persist(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Boolean move(String key, int dbIndex) { Boolean result = delegate.move(serialize(key), dbIndex); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public void pSubscribe(MessageListener listener, String... patterns) { delegate.pSubscribe(listener, serializeMulti(patterns)); } - public Long publish(String channel, String message) { Long result = delegate.publish(serialize(channel), serialize(message)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public void rename(String oldName, String newName) { delegate.rename(serialize(oldName), serialize(newName)); } - public Boolean renameNX(String oldName, String newName) { Boolean result = delegate.renameNX(serialize(oldName), serialize(newName)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public String rPop(String key) { byte[] result = delegate.rPop(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public String rPopLPush(String srcKey, String dstKey) { byte[] result = delegate.rPopLPush(serialize(srcKey), serialize(dstKey)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public Long rPush(String key, String... values) { Long result = delegate.rPush(serialize(key), serializeMulti(values)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long rPushX(String key, String value) { Long result = delegate.rPushX(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long sAdd(String key, String... values) { Long result = delegate.sAdd(serialize(key), serializeMulti(values)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long sCard(String key) { Long result = delegate.sCard(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Set sDiff(String... keys) { Set results = delegate.sDiff(serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Long sDiffStore(String destKey, String... keys) { Long result = delegate.sDiffStore(serialize(destKey), serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public void set(String key, String value) { delegate.set(serialize(key), serialize(value)); } - public void setBit(String key, long offset, boolean value) { delegate.setBit(serialize(key), offset, value); } - public void setEx(String key, long seconds, String value) { delegate.setEx(serialize(key), seconds, serialize(value)); } - public Boolean setNX(String key, String value) { Boolean result = delegate.setNX(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public void setRange(String key, String value, long start) { delegate.setRange(serialize(key), serialize(value), start); } - public Set sInter(String... keys) { Set results = delegate.sInter(serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Long sInterStore(String destKey, String... keys) { Long result = delegate.sInterStore(serialize(destKey), serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Boolean sIsMember(String key, String value) { Boolean result = delegate.sIsMember(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Set sMembers(String key) { Set results = delegate.sMembers(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Boolean sMove(String srcKey, String destKey, String value) { Boolean result = delegate.sMove(serialize(srcKey), serialize(destKey), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long sort(String key, SortParameters params, String storeKey) { Long result = delegate.sort(serialize(key), params, serialize(storeKey)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public List sort(String key, SortParameters params) { List results = delegate.sort(serialize(key), params); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteListToStringList); } return byteListToStringList.convert(results); } - public String sPop(String key) { byte[] result = delegate.sPop(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); } - public String sRandMember(String key) { byte[] result = delegate.sRandMember(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(bytesToString); } return bytesToString.convert(result); @@ -1838,31 +1770,31 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public List sRandMember(String key, long count) { List results = delegate.sRandMember(serialize(key), count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteListToStringList); } return byteListToStringList.convert(results); } - + public Long sRem(String key, String... values) { Long result = delegate.sRem(serialize(key), serializeMulti(values)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - + public Long strLen(String key) { Long result = delegate.strLen(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - + public Long bitCount(String key) { Long result = delegate.bitCount(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1870,7 +1802,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long bitCount(String key, long begin, long end) { Long result = delegate.bitCount(serialize(key), begin, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1878,7 +1810,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long bitOp(BitOperation op, String destination, String... keys) { Long result = delegate.bitOp(op, serialize(destination), serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -1888,215 +1820,193 @@ public class DefaultStringRedisConnection implements StringRedisConnection { delegate.subscribe(listener, serializeMulti(channels)); } - public Set sUnion(String... keys) { Set results = delegate.sUnion(serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Long sUnionStore(String destKey, String... keys) { Long result = delegate.sUnionStore(serialize(destKey), serializeMulti(keys)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long ttl(String key) { Long result = delegate.ttl(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public DataType type(String key) { DataType result = delegate.type(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Boolean zAdd(String key, double score, String value) { Boolean result = delegate.zAdd(serialize(key), score, serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zAdd(String key, Set tuples) { Long result = delegate.zAdd(serialize(key), stringTupleToTuple.convert(tuples)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - + public Long zCard(String key) { Long result = delegate.zCard(serialize(key)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zCount(String key, double min, double max) { Long result = delegate.zCount(serialize(key), min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Double zIncrBy(String key, double increment, String value) { Double result = delegate.zIncrBy(serialize(key), increment, serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets) { Long result = delegate.zInterStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zInterStore(String destKey, String... sets) { Long result = delegate.zInterStore(serialize(destKey), serializeMulti(sets)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Set zRange(String key, long start, long end) { Set results = delegate.zRange(serialize(key), start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Set zRangeByScore(String key, double min, double max, long offset, long count) { Set results = delegate.zRangeByScore(serialize(key), min, max, offset, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Set zRangeByScore(String key, double min, double max) { Set results = delegate.zRangeByScore(serialize(key), min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Set zRangeByScoreWithScores(String key, double min, double max, long offset, long count) { Set results = delegate.zRangeByScoreWithScores(serialize(key), min, max, offset, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(tupleToStringTuple); } return tupleToStringTuple.convert(results); } - public Set zRangeByScoreWithScores(String key, double min, double max) { Set results = delegate.zRangeByScoreWithScores(serialize(key), min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(tupleToStringTuple); } return tupleToStringTuple.convert(results); } - public Set zRangeWithScores(String key, long start, long end) { Set results = delegate.zRangeWithScores(serialize(key), start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(tupleToStringTuple); } return tupleToStringTuple.convert(results); } - public Long zRank(String key, String value) { Long result = delegate.zRank(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zRem(String key, String... values) { Long result = delegate.zRem(serialize(key), serializeMulti(values)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zRemRange(String key, long start, long end) { Long result = delegate.zRemRange(serialize(key), start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zRemRangeByScore(String key, double min, double max) { Long result = delegate.zRemRangeByScore(serialize(key), min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Set zRevRange(String key, long start, long end) { Set results = delegate.zRevRange(serialize(key), start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Set zRevRangeWithScores(String key, long start, long end) { Set results = delegate.zRevRangeWithScores(serialize(key), start, end); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(tupleToStringTuple); } return tupleToStringTuple.convert(results); } - + public Set zRevRangeByScore(String key, double min, double max) { Set results = delegate.zRevRangeByScore(serialize(key), min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); @@ -2104,7 +2014,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRevRangeByScoreWithScores(String key, double min, double max) { Set results = delegate.zRevRangeByScoreWithScores(serialize(key), min, max); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(tupleToStringTuple); } return tupleToStringTuple.convert(results); @@ -2112,16 +2022,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Set zRevRangeByScore(String key, double min, double max, long offset, long count) { Set results = delegate.zRevRangeByScore(serialize(key), min, max, offset, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(byteSetToStringSet); } return byteSetToStringSet.convert(results); } - public Set zRevRangeByScoreWithScores(String key, double min, double max, - long offset, long count) { + public Set zRevRangeByScoreWithScores(String key, double min, double max, long offset, long count) { Set results = delegate.zRevRangeByScoreWithScores(serialize(key), min, max, offset, count); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(tupleToStringTuple); } return tupleToStringTuple.convert(results); @@ -2129,34 +2038,31 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Long zRevRank(String key, String value) { Long result = delegate.zRevRank(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Double zScore(String key, String value) { Double result = delegate.zScore(serialize(key), serialize(value)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets) { Long result = delegate.zUnionStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } - public Long zUnionStore(String destKey, String... sets) { Long result = delegate.zUnionStore(serialize(destKey), serializeMulti(sets)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -2174,7 +2080,6 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.isPipelined(); } - public void openPipeline() { delegate.openPipeline(); } @@ -2185,7 +2090,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public Object execute(String command, byte[]... args) { Object result = delegate.execute(command, args); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; @@ -2209,51 +2114,48 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public String scriptLoad(String script) { String result = delegate.scriptLoad(serialize(script)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } /** - * NOTE: This method will not deserialize Strings returned by Lua scripts, as - * they may not be encoded with the same serializer used here. They will - * be returned as byte[]s + * NOTE: This method will not deserialize Strings returned by Lua scripts, as they may not be encoded with the same + * serializer used here. They will be returned as byte[]s */ public T eval(String script, ReturnType returnType, int numKeys, String... keysAndArgs) { T result = delegate.eval(serialize(script), returnType, numKeys, serializeMulti(keysAndArgs)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } /** - * NOTE: This method will not deserialize Strings returned by Lua scripts, as - * they may not be encoded with the same serializer used here. They will - * be returned as byte[]s + * NOTE: This method will not deserialize Strings returned by Lua scripts, as they may not be encoded with the same + * serializer used here. They will be returned as byte[]s */ public T evalSha(String scriptSha1, ReturnType returnType, int numKeys, String... keysAndArgs) { T result = delegate.evalSha(scriptSha1, returnType, numKeys, serializeMulti(keysAndArgs)); - if(isFutureConversion()) { + if (isFutureConversion()) { addResultConverter(identityConverter); } return result; } /** - * Specifies if pipelined and tx results should be deserialized to Strings. - * If false, results of {@link #closePipeline()} and {@link #exec()} will be of the - * type returned by the underlying connection - * + * Specifies if pipelined and tx results should be deserialized to Strings. If false, results of + * {@link #closePipeline()} and {@link #exec()} will be of the type returned by the underlying connection + * * @param deserializePipelineAndTxResults Whether or not to deserialize pipeline and tx results */ public void setDeserializePipelineAndTxResults(boolean deserializePipelineAndTxResults) { this.deserializePipelineAndTxResults = deserializePipelineAndTxResults; } - private void addResultConverter(Converter converter) { - if(isQueueing()) { + private void addResultConverter(Converter converter) { + if (isQueueing()) { txConverters.add(converter); } else { pipelineConverters.add(converter); @@ -2261,23 +2163,23 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } private boolean isFutureConversion() { - return isPipelined() || isQueueing(); - } + return isPipelined() || isQueueing(); + } @SuppressWarnings({ "unchecked", "rawtypes" }) private List convertResults(List results, Queue converters) { - if(!deserializePipelineAndTxResults || results == null) { + if (!deserializePipelineAndTxResults || results == null) { return results; } - if(results.size() != converters.size()) { + if (results.size() != converters.size()) { // Some of the commands were done directly on the delegate, don't attempt to convert log.warn("Delegate returned an unexpected number of results. Abandoning type conversion."); return results; } List convertedResults = new ArrayList(); - for(Object result: results) { + for (Object result : results) { convertedResults.add(converters.remove().convert(result)); } return convertedResults; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringTuple.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringTuple.java index acbe48792..80f79daf5 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringTuple.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringTuple.java @@ -20,7 +20,7 @@ import org.springframework.data.redis.connection.StringRedisConnection.StringTup /** * Default implementation for {@link StringTuple} interface. - * + * * @author Costin Leau */ public class DefaultStringTuple extends DefaultTuple implements StringTuple { @@ -29,7 +29,7 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple { /** * Constructs a new DefaultStringTuple instance. - * + * * @param value * @param score */ @@ -41,7 +41,7 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple { /** * Constructs a new DefaultStringTuple instance. - * + * * @param tuple * @param valueAsString */ @@ -50,12 +50,10 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple { this.valueAsString = valueAsString; } - public String getValueAsString() { return valueAsString; } - public int hashCode() { final int prime = 31; int result = super.hashCode(); @@ -63,7 +61,6 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple { return result; } - public boolean equals(Object obj) { if (super.equals(obj)) { if (!(obj instanceof DefaultStringTuple)) @@ -72,8 +69,7 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple { if (valueAsString == null) { if (other.valueAsString != null) return false; - } - else if (!valueAsString.equals(other.valueAsString)) + } else if (!valueAsString.equals(other.valueAsString)) return false; return true; } @@ -83,4 +79,4 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple { public String toString() { return "DefaultStringTuple[value=" + getValueAsString() + ", score=" + getScore() + "]"; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultTuple.java b/src/main/java/org/springframework/data/redis/connection/DefaultTuple.java index 91ff287a9..de2fd984f 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultTuple.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultTuple.java @@ -29,10 +29,9 @@ public class DefaultTuple implements Tuple { private final Double score; private final byte[] value; - /** * Constructs a new DefaultTuple instance. - * + * * @param value * @param score */ @@ -41,17 +40,14 @@ public class DefaultTuple implements Tuple { this.value = value; } - public Double getScore() { return score; } - public byte[] getValue() { return value; } - public boolean equals(Object obj) { if (this == obj) return true; @@ -63,15 +59,13 @@ public class DefaultTuple implements Tuple { if (score == null) { if (other.score != null) return false; - } - else if (!score.equals(other.score)) + } else if (!score.equals(other.score)) return false; if (!Arrays.equals(value, other.value)) return false; return true; } - public int hashCode() { final int prime = 31; int result = 1; @@ -80,10 +74,9 @@ public class DefaultTuple implements Tuple { return result; } - public int compareTo(Double o) { Double d = (score == null ? Double.valueOf(0.0d) : score); Double a = (o == null ? Double.valueOf(0.0d) : o); return d.compareTo(a); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/FutureResult.java b/src/main/java/org/springframework/data/redis/connection/FutureResult.java index 2a1f82e19..c3e78689d 100644 --- a/src/main/java/org/springframework/data/redis/connection/FutureResult.java +++ b/src/main/java/org/springframework/data/redis/connection/FutureResult.java @@ -19,11 +19,9 @@ import org.springframework.core.convert.converter.Converter; /** * The result of an asynchronous operation - * + * * @author Jennifer Hickey - * - * @param - * The data type of the object that holds the future result (usually of type Future) + * @param The data type of the object that holds the future result (usually of type Future) */ abstract public class FutureResult { @@ -31,8 +29,7 @@ abstract public class FutureResult { protected boolean status = false; - @SuppressWarnings("rawtypes") - protected Converter converter; + @SuppressWarnings("rawtypes") protected Converter converter; public FutureResult(T resultHolder) { this.resultHolder = resultHolder; @@ -50,9 +47,8 @@ abstract public class FutureResult { /** * Converts the given result if a converter is specified, else returns the result - * - * @param result - * The result to convert + * + * @param result The result to convert * @return The converted result */ @SuppressWarnings("unchecked") @@ -69,9 +65,8 @@ abstract public class FutureResult { } /** - * Indicates if this result is the status of an operation. Typically status results will be - * discarded on conversion. - * + * Indicates if this result is the status of an operation. Typically status results will be discarded on conversion. + * * @return true if this is a status result (i.e. OK) */ public boolean isStatus() { @@ -79,9 +74,8 @@ abstract public class FutureResult { } /** - * Indicates if this result is the status of an operation. Typically status results will be - * discarded on conversion. - * + * Indicates if this result is the status of an operation. Typically status results will be discarded on conversion. + * * @return true if this is a status result (i.e. OK) */ public void setStatus(boolean status) { diff --git a/src/main/java/org/springframework/data/redis/connection/Message.java b/src/main/java/org/springframework/data/redis/connection/Message.java index 69109ef00..1547fb1f6 100644 --- a/src/main/java/org/springframework/data/redis/connection/Message.java +++ b/src/main/java/org/springframework/data/redis/connection/Message.java @@ -26,11 +26,11 @@ public interface Message extends Serializable { /** * Returns the body (or the payload) of the message. - * + * * @return message body */ byte[] getBody(); - + /** * Returns the channel associated with the message. * diff --git a/src/main/java/org/springframework/data/redis/connection/Pool.java b/src/main/java/org/springframework/data/redis/connection/Pool.java index 104f8c66d..990fa2926 100644 --- a/src/main/java/org/springframework/data/redis/connection/Pool.java +++ b/src/main/java/org/springframework/data/redis/connection/Pool.java @@ -15,32 +15,25 @@ */ package org.springframework.data.redis.connection; - /** * Pool of resources * * @author Jennifer Hickey - * */ public interface Pool { /** - * * @return A resource, if available */ T getResource(); /** - * - * @param resource - * A broken resource that should be invalidated + * @param resource A broken resource that should be invalidated */ void returnBrokenResource(final T resource); /** - * - * @param resource - * A resource to return to the pool + * @param resource A resource to return to the pool */ void returnResource(final T resource); diff --git a/src/main/java/org/springframework/data/redis/connection/PoolException.java b/src/main/java/org/springframework/data/redis/connection/PoolException.java index 4bb1d6307..a8abd7168 100644 --- a/src/main/java/org/springframework/data/redis/connection/PoolException.java +++ b/src/main/java/org/springframework/data/redis/connection/PoolException.java @@ -21,7 +21,6 @@ import org.springframework.core.NestedRuntimeException; * Exception thrown when there are issues with a resource pool * * @author Jennifer Hickey - * */ @SuppressWarnings("serial") public class PoolException extends NestedRuntimeException { diff --git a/src/main/java/org/springframework/data/redis/connection/RedisCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisCommands.java index 2a9b68cdc..24283111a 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisCommands.java @@ -16,7 +16,6 @@ package org.springframework.data.redis.connection; - /** * Interface for the commands supported by Redis. * @@ -26,15 +25,14 @@ public interface RedisCommands extends RedisKeyCommands, RedisStringCommands, Re RedisZSetCommands, RedisHashCommands, RedisTxCommands, RedisPubSubCommands, RedisConnectionCommands, RedisServerCommands, RedisScriptingCommands { - /** - * 'Native' or 'raw' execution of the given command along-side the given arguments. - * The command is executed as is, with as little 'interpretation' as possible - it is up to the caller - * to take care of any processing of arguments or the result. + * 'Native' or 'raw' execution of the given command along-side the given arguments. The command is executed as is, + * with as little 'interpretation' as possible - it is up to the caller to take care of any processing of arguments or + * the result. * * @param command Command to execute * @param args Possible command arguments (may be null) * @return execution result. */ Object execute(String command, byte[]... args); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/RedisConnection.java b/src/main/java/org/springframework/data/redis/connection/RedisConnection.java index ebcab7d17..a445696dd 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisConnection.java @@ -21,10 +21,8 @@ import java.util.List; import org.springframework.dao.DataAccessException; /** - * A connection to a Redis server. Acts as an common abstraction across various - * Redis client libraries (or drivers). Additionally performs exception translation - * between the underlying Redis client library and Spring DAO exceptions. - * + * A connection to a Redis server. Acts as an common abstraction across various Redis client libraries (or drivers). + * Additionally performs exception translation between the underlying Redis client library and Spring DAO exceptions. * The methods follow as much as possible the Redis names and conventions. * * @author Costin Leau @@ -33,7 +31,7 @@ public interface RedisConnection extends RedisCommands { /** * Closes (or quits) the connection. - * + * * @throws DataAccessException */ void close() throws DataAccessException; @@ -53,11 +51,9 @@ public interface RedisConnection extends RedisCommands { Object getNativeConnection(); /** - * Indicates whether the connection is in "queue"(or "MULTI") mode or not. - * When queueing, all commands are postponed until EXEC or DISCARD commands - * are issued. - * Since in queueing no results are returned, the connection will return NULL - * on all operations that interact with the data. + * Indicates whether the connection is in "queue"(or "MULTI") mode or not. When queueing, all commands are postponed + * until EXEC or DISCARD commands are issued. Since in queueing no results are returned, the connection will return + * NULL on all operations that interact with the data. * * @return true if the connection is in queue/MULTI mode, false otherwise */ @@ -65,7 +61,7 @@ public interface RedisConnection extends RedisCommands { /** * Indicates whether the connection is currently pipelined or not. - * + * * @return true if the connection is pipelined, false otherwise * @see #openPipeline() * @see #isQueueing() @@ -73,28 +69,27 @@ public interface RedisConnection extends RedisCommands { boolean isPipelined(); /** - * Activates the pipeline mode for this connection. When pipelined, all commands return null - * (the reply is read at the end through {@link #closePipeline()}. - * Calling this method when the connection is already pipelined has no effect. - * - * Pipelining is used for issuing commands without requesting the response right away but rather - * at the end of the batch. While somewhat similar to MULTI, pipelining does not - * guarantee atomicity - it only tries to improve performance when issuing a lot of - * commands (such as in batching scenarios). - * - *

Note:

Consider doing some performance testing before using this feature since - * in many cases the performance benefits are minimal yet the impact on usage are not. + * Activates the pipeline mode for this connection. When pipelined, all commands return null (the reply is read at the + * end through {@link #closePipeline()}. Calling this method when the connection is already pipelined has no effect. + * Pipelining is used for issuing commands without requesting the response right away but rather at the end of the + * batch. While somewhat similar to MULTI, pipelining does not guarantee atomicity - it only tries to improve + * performance when issuing a lot of commands (such as in batching scenarios). + *

+ * Note: + *

+ * Consider doing some performance testing before using this feature since in many cases the performance benefits are + * minimal yet the impact on usage are not. * * @see #multi() */ void openPipeline(); /** - * Executes the commands in the pipeline and returns their result. - * If the connection is not pipelined, an empty collection is returned. + * Executes the commands in the pipeline and returns their result. If the connection is not pipelined, an empty + * collection is returned. * * @throws RedisPipelineException if the pipeline contains any incorrect/invalid statements * @return the result of the executed commands. */ List closePipeline() throws RedisPipelineException; -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/RedisConnectionCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisConnectionCommands.java index 85994d486..689d0ff0a 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisConnectionCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisConnectionCommands.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.connection; - /** * Connection-specific commands supported by Redis. * @@ -28,4 +27,4 @@ public interface RedisConnectionCommands { byte[] echo(byte[] message); String ping(); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/RedisConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/RedisConnectionFactory.java index 1f3136abc..6c0df25da 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisConnectionFactory.java @@ -33,14 +33,11 @@ public interface RedisConnectionFactory extends PersistenceExceptionTranslator { RedisConnection getConnection(); /** - * Specifies if pipelined results should be converted to the expected data - * type. If false, results of {@link RedisConnection#closePipeline()} and {RedisConnection#exec()} - * will be of the type returned by the underlying driver - * - * This method is mostly for backwards compatibility with 1.0. It is generally - * always a good idea to allow results to be converted and deserialized. - * In fact, this is now the default behavior. - * + * Specifies if pipelined results should be converted to the expected data type. If false, results of + * {@link RedisConnection#closePipeline()} and {RedisConnection#exec()} will be of the type returned by the underlying + * driver This method is mostly for backwards compatibility with 1.0. It is generally always a good idea to allow + * results to be converted and deserialized. In fact, this is now the default behavior. + * * @return Whether or not to convert pipeline and tx results */ boolean getConvertPipelineAndTxResults(); diff --git a/src/main/java/org/springframework/data/redis/connection/RedisInvalidSubscriptionException.java b/src/main/java/org/springframework/data/redis/connection/RedisInvalidSubscriptionException.java index 450d452e0..0ce8448b5 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisInvalidSubscriptionException.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisInvalidSubscriptionException.java @@ -26,7 +26,7 @@ public class RedisInvalidSubscriptionException extends InvalidDataAccessResource /** * Constructs a new RedisInvalidSubscriptionException instance. - * + * * @param msg * @param cause */ @@ -36,7 +36,7 @@ public class RedisInvalidSubscriptionException extends InvalidDataAccessResource /** * Constructs a new RedisInvalidSubscriptionException instance. - * + * * @param msg */ public RedisInvalidSubscriptionException(String msg) { diff --git a/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java index 7e2c3d638..9737239fb 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisKeyCommands.java @@ -18,7 +18,6 @@ package org.springframework.data.redis.connection; import java.util.List; import java.util.Set; - /** * Key-specific commands supported by Redis. * @@ -64,4 +63,4 @@ public interface RedisKeyCommands { byte[] dump(byte[] key); void restore(byte[] key, long ttlInMillis, byte[] serializedValue); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/RedisListCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisListCommands.java index d300f988d..abf7dafcd 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisListCommands.java @@ -26,14 +26,14 @@ import java.util.List; public interface RedisListCommands { /** - * List insertion position. + * List insertion position. */ public enum Position { BEFORE, AFTER } Long rPush(byte[] key, byte[]... values); - + Long lPush(byte[] key, byte[]... value); Long rPushX(byte[] key, byte[] value); diff --git a/src/main/java/org/springframework/data/redis/connection/RedisPipelineException.java b/src/main/java/org/springframework/data/redis/connection/RedisPipelineException.java index 2b0239834..bf51783cd 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisPipelineException.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisPipelineException.java @@ -22,11 +22,11 @@ import java.util.List; import org.springframework.dao.InvalidDataAccessResourceUsageException; /** - * Exception thrown when executing/closing a pipeline that contains one or multiple invalid/incorrect statements. - * The exception might also contain the pipeline result (if the driver returns it), allowing for analysis and tracing. + * Exception thrown when executing/closing a pipeline that contains one or multiple invalid/incorrect statements. The + * exception might also contain the pipeline result (if the driver returns it), allowing for analysis and tracing. *

* Typically, the first exception returned by the pipeline is used as the cause of this exception for easier - * debugging. + * debugging. * * @author Costin Leau */ @@ -36,7 +36,7 @@ public class RedisPipelineException extends InvalidDataAccessResourceUsageExcept /** * Constructs a new RedisPipelineException instance. - * + * * @param msg the message * @param cause the cause * @param pipelineResult the pipeline result @@ -48,7 +48,7 @@ public class RedisPipelineException extends InvalidDataAccessResourceUsageExcept /** * Constructs a new RedisPipelineException instance using a default message. - * + * * @param cause the cause * @param pipelineResult the pipeline result */ @@ -57,9 +57,9 @@ public class RedisPipelineException extends InvalidDataAccessResourceUsageExcept } /** - * Constructs a new RedisPipelineException instance using a default message - * and an empty pipeline result list. - * + * Constructs a new RedisPipelineException instance using a default message and an empty pipeline result + * list. + * * @param cause the cause */ public RedisPipelineException(Exception cause) { @@ -78,13 +78,12 @@ public class RedisPipelineException extends InvalidDataAccessResourceUsageExcept } /** - * Optionally returns the result of the pipeline that caused the exception. - * Typically contains both the results of the successful statements but also - * the exceptions of the incorrect ones. + * Optionally returns the result of the pipeline that caused the exception. Typically contains both the results of the + * successful statements but also the exceptions of the incorrect ones. * * @return result of the pipeline */ public List getPipelineResult() { return results; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/RedisPubSubCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisPubSubCommands.java index 0a9b4edbf..ca63e1591 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisPubSubCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisPubSubCommands.java @@ -23,16 +23,14 @@ package org.springframework.data.redis.connection; public interface RedisPubSubCommands { /** - * Indicates whether the current connection is subscribed (to at least one channel) - * or not. + * Indicates whether the current connection is subscribed (to at least one channel) or not. * * @return true if the connection is subscribed, false otherwise */ boolean isSubscribed(); /** - * Returns the current subscription for this connection or null if the connection is - * not subscribed. + * Returns the current subscription for this connection or null if the connection is not subscribed. * * @return the current subscription, null if none is available */ @@ -48,13 +46,10 @@ public interface RedisPubSubCommands { Long publish(byte[] channel, byte[] message); /** - * Subscribes the connection to the given channels. - * Once subscribed, a connection - * enters listening mode and can only subscribe to other channels or unsubscribe. - * No other commands are accepted until the connection is unsubscribed. + * Subscribes the connection to the given channels. Once subscribed, a connection enters listening mode and can only + * subscribe to other channels or unsubscribe. No other commands are accepted until the connection is unsubscribed. *

- * Note that this operation is blocking and the current thread starts waiting - * for new messages immediately. + * Note that this operation is blocking and the current thread starts waiting for new messages immediately. * * @param listener message listener * @param channels channel names @@ -62,16 +57,14 @@ public interface RedisPubSubCommands { void subscribe(MessageListener listener, byte[]... channels); /** - * Subscribes the connection to all channels matching the given patterns. - * Once subscribed, a connection - * enters listening mode and can only subscribe to other channels or unsubscribe. - * No other commands are accepted until the connection is unsubscribed. + * Subscribes the connection to all channels matching the given patterns. Once subscribed, a connection enters + * listening mode and can only subscribe to other channels or unsubscribe. No other commands are accepted until the + * connection is unsubscribed. *

- * Note that this operation is blocking and the current thread starts waiting - * for new messages immediately. + * Note that this operation is blocking and the current thread starts waiting for new messages immediately. * * @param listener message listener * @param patterns channel name patterns */ void pSubscribe(MessageListener listener, byte[]... patterns); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/RedisScriptingCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisScriptingCommands.java index cd836dcf8..8012b67df 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisScriptingCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisScriptingCommands.java @@ -25,15 +25,15 @@ import java.util.List; */ public interface RedisScriptingCommands { - void scriptFlush(); + void scriptFlush(); - void scriptKill(); + void scriptKill(); - String scriptLoad(byte[] script); + String scriptLoad(byte[] script); - List scriptExists(String... scriptSha1); + List scriptExists(String... scriptSha1); - T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs); + T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs); - T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs); -} \ No newline at end of file + T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs); +} diff --git a/src/main/java/org/springframework/data/redis/connection/RedisSubscribedConnectionException.java b/src/main/java/org/springframework/data/redis/connection/RedisSubscribedConnectionException.java index 752ec2834..b87d9cea9 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisSubscribedConnectionException.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisSubscribedConnectionException.java @@ -18,8 +18,7 @@ package org.springframework.data.redis.connection; import org.springframework.dao.InvalidDataAccessApiUsageException; /** - * Exception thrown when issuing commands on a connection that is subscribed and waiting - * for events. + * Exception thrown when issuing commands on a connection that is subscribed and waiting for events. * * @author Costin Leau * @see org.springframework.data.redis.connection.RedisPubSubCommands @@ -28,7 +27,7 @@ public class RedisSubscribedConnectionException extends InvalidDataAccessApiUsag /** * Constructs a new RedisSubscribedConnectionException instance. - * + * * @param msg * @param cause */ @@ -38,7 +37,7 @@ public class RedisSubscribedConnectionException extends InvalidDataAccessApiUsag /** * Constructs a new RedisSubscribedConnectionException instance. - * + * * @param msg */ public RedisSubscribedConnectionException(String msg) { diff --git a/src/main/java/org/springframework/data/redis/connection/RedisTxCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisTxCommands.java index ee809f5ef..b4631ac0a 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisTxCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisTxCommands.java @@ -17,7 +17,6 @@ package org.springframework.data.redis.connection; import java.util.List; - /** * Transaction/Batch specific commands supported by Redis. * diff --git a/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java index 8652d596a..2b331d00a 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisZSetCommands.java @@ -18,7 +18,6 @@ package org.springframework.data.redis.connection; import java.util.Set; - /** * ZSet(SortedSet)-specific commands supported by Redis. * @@ -27,14 +26,14 @@ import java.util.Set; public interface RedisZSetCommands { /** - * Sort aggregation operations. + * Sort aggregation operations. */ public enum Aggregate { SUM, MIN, MAX; } /** - * ZSet tuple. + * ZSet tuple. */ public interface Tuple extends Comparable { byte[] getValue(); @@ -95,4 +94,4 @@ public interface RedisZSetCommands { Long zInterStore(byte[] destKey, byte[]... sets); Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/ReturnType.java b/src/main/java/org/springframework/data/redis/connection/ReturnType.java index 710d1465e..820c3c55d 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReturnType.java +++ b/src/main/java/org/springframework/data/redis/connection/ReturnType.java @@ -18,11 +18,10 @@ package org.springframework.data.redis.connection; import java.util.List; /** - * Represents a data type returned from Redis, currently used to denote the - * expected return type of Redis scripting commands + * Represents a data type returned from Redis, currently used to denote the expected return type of Redis scripting + * commands * * @author Jennifer Hickey - * */ public enum ReturnType { @@ -42,16 +41,16 @@ public enum ReturnType { VALUE; public static ReturnType fromJavaType(Class javaType) { - if(javaType == null) { + if (javaType == null) { return ReturnType.STATUS; } - if(javaType.isAssignableFrom(List.class)) { + if (javaType.isAssignableFrom(List.class)) { return ReturnType.MULTI; } - if(javaType.isAssignableFrom(Boolean.class)) { + if (javaType.isAssignableFrom(Boolean.class)) { return ReturnType.BOOLEAN; } - if(javaType.isAssignableFrom(Long.class)) { + if (javaType.isAssignableFrom(Long.class)) { return ReturnType.INTEGER; } return ReturnType.VALUE; diff --git a/src/main/java/org/springframework/data/redis/connection/SortParameters.java b/src/main/java/org/springframework/data/redis/connection/SortParameters.java index 2c30126e2..150205d84 100644 --- a/src/main/java/org/springframework/data/redis/connection/SortParameters.java +++ b/src/main/java/org/springframework/data/redis/connection/SortParameters.java @@ -31,7 +31,6 @@ public interface SortParameters { /** * Utility class wrapping the 'LIMIT' setting. - * */ static class Range { private final long start; @@ -59,34 +58,31 @@ public interface SortParameters { Order getOrder(); /** - * Indicates if the sorting is numeric (default) or alphabetical (lexicographical). - * Can be null if nothing is specified. + * Indicates if the sorting is numeric (default) or alphabetical (lexicographical). Can be null if nothing is + * specified. * * @return the type of sorting */ Boolean isAlphabetic(); /** - * Returns the pattern (if set) for sorting by external keys (BY). - * Can be null if nothing is specified. - * + * Returns the pattern (if set) for sorting by external keys (BY). Can be null if nothing is specified. + * * @return BY pattern. */ byte[] getByPattern(); /** - * Returns the pattern (if set) for retrieving external keys (GET). - * Can be null if nothing is specified. + * Returns the pattern (if set) for retrieving external keys (GET). Can be null if nothing is specified. * * @return GET pattern. */ byte[][] getGetPattern(); /** - * Returns the sorting limit (range or pagination). - * Can be null if nothing is specified. + * Returns the sorting limit (range or pagination). Can be null if nothing is specified. * * @return sorting limit/range */ Range getLimit(); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java index 2db7cc660..ed0a62deb 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -25,13 +25,13 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; /** - * Convenience extension of {@link RedisConnection} that accepts and returns {@link String}s instead of - * byte arrays. Uses a {@link RedisSerializer} underneath to perform the conversion. + * Convenience extension of {@link RedisConnection} that accepts and returns {@link String}s instead of byte arrays. + * Uses a {@link RedisSerializer} underneath to perform the conversion. * * @author Costin Leau * @see RedisCallback * @see RedisSerializer - * @see StringRedisTemplate + * @see StringRedisTemplate */ public interface StringRedisConnection extends RedisConnection { @@ -280,4 +280,4 @@ public interface StringRedisConnection extends RedisConnection { T eval(String script, ReturnType returnType, int numKeys, String... keysAndArgs); T evalSha(String scriptSha1, ReturnType returnType, int numKeys, String... keysAndArgs); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/Subscription.java b/src/main/java/org/springframework/data/redis/connection/Subscription.java index 370fe1923..91e380be1 100644 --- a/src/main/java/org/springframework/data/redis/connection/Subscription.java +++ b/src/main/java/org/springframework/data/redis/connection/Subscription.java @@ -18,10 +18,8 @@ package org.springframework.data.redis.connection; import java.util.Collection; /** - * Subscription for Redis channels. Just like the underlying {@link RedisConnection}, - * it should not be used by multiple threads. - * - * Note that once a subscription died, it cannot accept any more subscriptions. + * Subscription for Redis channels. Just like the underlying {@link RedisConnection}, it should not be used by multiple + * threads. Note that once a subscription died, it cannot accept any more subscriptions. * * @author Costin Leau */ @@ -60,7 +58,7 @@ public interface Subscription { /** * Cancels the subscription for all channels matching the given patterns. - * + * * @param patterns */ void pUnsubscribe(byte[]... patterns); @@ -87,10 +85,9 @@ public interface Subscription { MessageListener getListener(); /** - * Indicates whether this subscription is still 'alive' - * or not. + * Indicates whether this subscription is still 'alive' or not. * * @return true if the subscription still applies, false otherwise. */ boolean isAlive(); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/convert/Converters.java b/src/main/java/org/springframework/data/redis/connection/convert/Converters.java index c3315945e..6cf3fbf94 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/Converters.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/Converters.java @@ -26,9 +26,8 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; /** * Common type converters - * + * * @author Jennifer Hickey - * */ abstract public class Converters { @@ -68,7 +67,7 @@ abstract public class Converters { public static List toObjects(Set tuples) { List tupleArgs = new ArrayList(tuples.size() * 2); - for(Tuple tuple: tuples) { + for (Tuple tuple : tuples) { tupleArgs.add(tuple.getScore()); tupleArgs.add(tuple.getValue()); } diff --git a/src/main/java/org/springframework/data/redis/connection/convert/ListConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/ListConverter.java index 0d9e27cca..6ed35c122 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/ListConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/ListConverter.java @@ -7,23 +7,17 @@ import org.springframework.core.convert.converter.Converter; /** * Converts a List of values of one type to a List of values of another type - * + * * @author Jennifer Hickey - * - * @param - * The type of elements in the List to convert - * @param - * The type of elements in the converted List + * @param The type of elements in the List to convert + * @param The type of elements in the converted List */ public class ListConverter implements Converter, List> { private Converter itemConverter; /** - * - * @param itemConverter - * The {@link Converter} to use for converting individual List - * items + * @param itemConverter The {@link Converter} to use for converting individual List items */ public ListConverter(Converter itemConverter) { this.itemConverter = itemConverter; diff --git a/src/main/java/org/springframework/data/redis/connection/convert/LongToBooleanConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/LongToBooleanConverter.java index 221f80192..42414af66 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/LongToBooleanConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/LongToBooleanConverter.java @@ -19,9 +19,8 @@ import org.springframework.core.convert.converter.Converter; /** * Converts Longs to Booleans - * + * * @author Jennifer Hickey - * */ public class LongToBooleanConverter implements Converter { diff --git a/src/main/java/org/springframework/data/redis/connection/convert/MapConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/MapConverter.java index 73ec01377..50b48372c 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/MapConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/MapConverter.java @@ -22,25 +22,18 @@ import java.util.Map; import org.springframework.core.convert.converter.Converter; /** - * Converts a Map of values of one key/value type to a Map of values of another - * type - * + * Converts a Map of values of one key/value type to a Map of values of another type + * * @author Jennifer Hickey - * - * @param - * The type of keys and values in the Map to convert - * @param - * The type of keys and values in the converted Map + * @param The type of keys and values in the Map to convert + * @param The type of keys and values in the converted Map */ public class MapConverter implements Converter, Map> { private Converter itemConverter; /** - * - * @param itemConverter - * The {@link Converter} to use for converting individual Map - * keys and values + * @param itemConverter The {@link Converter} to use for converting individual Map keys and values */ public MapConverter(Converter itemConverter) { this.itemConverter = itemConverter; @@ -57,8 +50,7 @@ public class MapConverter implements Converter, Map> { results = new HashMap(); } for (Map.Entry result : source.entrySet()) { - results.put(itemConverter.convert(result.getKey()), - itemConverter.convert(result.getValue())); + results.put(itemConverter.convert(result.getKey()), itemConverter.convert(result.getValue())); } return results; } diff --git a/src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java index 7a922564b..78010c56d 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java @@ -23,23 +23,17 @@ import org.springframework.core.convert.converter.Converter; /** * Converts a Set of values of one type to a Set of values of another type - * + * * @author Jennifer Hickey - * - * @param - * The type of elements in the Set to convert - * @param - * The type of elements in the converted Set + * @param The type of elements in the Set to convert + * @param The type of elements in the converted Set */ public class SetConverter implements Converter, Set> { private Converter itemConverter; /** - * - * @param itemConverter - * The {@link Converter} to use for converting individual Set - * items + * @param itemConverter The {@link Converter} to use for converting individual Set items */ public SetConverter(Converter itemConverter) { this.itemConverter = itemConverter; diff --git a/src/main/java/org/springframework/data/redis/connection/convert/StringToDataTypeConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/StringToDataTypeConverter.java index 46d44b293..933143d5c 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/StringToDataTypeConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/StringToDataTypeConverter.java @@ -20,9 +20,8 @@ import org.springframework.data.redis.connection.DataType; /** * Converts Strings to {@link DataType}s - * + * * @author Jennifer Hickey - * */ public class StringToDataTypeConverter implements Converter { diff --git a/src/main/java/org/springframework/data/redis/connection/convert/StringToPropertiesConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/StringToPropertiesConverter.java index 16be5493f..ca8d99305 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/StringToPropertiesConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/StringToPropertiesConverter.java @@ -23,9 +23,8 @@ import org.springframework.data.redis.RedisSystemException; /** * Converts Strings to {@link Properties} - * + * * @author Jennifer Hickey - * */ public class StringToPropertiesConverter implements Converter { diff --git a/src/main/java/org/springframework/data/redis/connection/convert/TransactionResultConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/TransactionResultConverter.java index 1eae0fd47..a28bfe139 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/TransactionResultConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/TransactionResultConverter.java @@ -25,14 +25,11 @@ import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.FutureResult; /** - * Converts the results of transaction exec using a supplied Queue of {@link FutureResult}s. - * Converts any Exception objects returned in the list as well, using the supplied Exception - * {@link Converter} - * + * Converts the results of transaction exec using a supplied Queue of {@link FutureResult}s. Converts any Exception + * objects returned in the list as well, using the supplied Exception {@link Converter} + * * @author Jennifer Hickey - * - * @param - * The type of {@link FutureResult} of the individual tx operations + * @param The type of {@link FutureResult} of the individual tx operations */ public class TransactionResultConverter implements Converter, List> { @@ -51,9 +48,8 @@ public class TransactionResultConverter implements Converter, Li return null; } if (execResults.size() != txResults.size()) { - throw new IllegalArgumentException( - "Incorrect number of transaction results. Expected: " + txResults.size() - + " Actual: " + execResults.size()); + throw new IllegalArgumentException("Incorrect number of transaction results. Expected: " + txResults.size() + + " Actual: " + execResults.size()); } List convertedResults = new ArrayList(); for (Object result : execResults) { 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 2313bbc5c..37bb08995 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 @@ -92,12 +92,12 @@ public class JedisConnection implements RedisConnection { private volatile JedisSubscription subscription; private volatile Pipeline pipeline; private final int dbIndex; - private boolean convertPipelineAndTxResults=true; + private boolean convertPipelineAndTxResults = true; private List>> pipelinedResults = new ArrayList>>(); private Queue>> txResults = new LinkedList>>(); private class JedisResult extends FutureResult> { - public JedisResult(Response resultHolder, Converter converter) { + public JedisResult(Response resultHolder, Converter converter) { super(resultHolder, converter); } @@ -107,7 +107,7 @@ public class JedisConnection implements RedisConnection { @SuppressWarnings("unchecked") public Object get() { - if(convertPipelineAndTxResults && converter != null) { + if (convertPipelineAndTxResults && converter != null) { return converter.convert(resultHolder.get()); } return resultHolder.get(); @@ -123,7 +123,7 @@ public class JedisConnection implements RedisConnection { /** * Constructs a new JedisConnection instance. - * + * * @param jedis Jedis entity */ public JedisConnection(Jedis jedis) { @@ -131,9 +131,8 @@ public class JedisConnection implements RedisConnection { } /** - * * Constructs a new JedisConnection instance backed by a jedis pool. - * + * * @param jedis * @param pool can be null, if no pool is used */ @@ -161,7 +160,7 @@ public class JedisConnection implements RedisConnection { } protected DataAccessException convertJedisAccessException(Exception ex) { - if(ex instanceof NullPointerException) { + if (ex instanceof NullPointerException) { // An NPE before flush will leave data in the OutputStream of a pooled connection broken = true; } @@ -180,23 +179,24 @@ public class JedisConnection implements RedisConnection { Collections.addAll(mArgs, args); } - ReflectionUtils.invokeMethod(SEND_COMMAND, client, - Command.valueOf(command.trim().toUpperCase()), mArgs.toArray(new byte[mArgs.size()][])); + ReflectionUtils.invokeMethod(SEND_COMMAND, client, Command.valueOf(command.trim().toUpperCase()), + mArgs.toArray(new byte[mArgs.size()][])); if (isQueueing() || isPipelined()) { Object target = (isPipelined() ? pipeline : transaction); @SuppressWarnings("unchecked") - Response result = (Response)ReflectionUtils.invokeMethod(GET_RESPONSE, target, new Builder() { - public Object build(Object data) { - return data; - } + Response result = (Response) ReflectionUtils.invokeMethod(GET_RESPONSE, target, + new Builder() { + public Object build(Object data) { + return data; + } - public String toString() { - return "Object"; - } - }); - if(isPipelined()) { + public String toString() { + return "Object"; + } + }); + if (isPipelined()) { pipeline(new JedisResult(result)); - }else { + } else { transaction(new JedisResult(result)); } return null; @@ -215,18 +215,18 @@ public class JedisConnection implements RedisConnection { try { if (dbIndex > 0) { jedis.select(0); - } + } pool.returnResource(jedis); return; - } catch(Exception ex) { + } catch (Exception ex) { DataAccessException dae = convertJedisAccessException(ex); - if(broken) { + if (broken) { pool.returnBrokenResource(jedis); } else { pool.returnResource(jedis); } throw dae; - } + } } else { pool.returnBrokenResource(jedis); return; @@ -261,12 +261,10 @@ public class JedisConnection implements RedisConnection { throw convertJedisAccessException(exc); } - public Jedis getNativeConnection() { return jedis; } - public boolean isClosed() { try { return !jedis.isConnected(); @@ -275,17 +273,14 @@ public class JedisConnection implements RedisConnection { } } - public boolean isQueueing() { return client.isInMulti(); } - public boolean isPipelined() { return (pipeline != null); } - public void openPipeline() { if (pipeline == null) { pipeline = jedis.pipelined(); @@ -296,7 +291,7 @@ public class JedisConnection implements RedisConnection { if (pipeline != null) { try { return convertPipelineResults(); - }finally { + } finally { pipeline = null; pipelinedResults.clear(); } @@ -308,19 +303,19 @@ public class JedisConnection implements RedisConnection { List results = new ArrayList(); pipeline.sync(); Exception cause = null; - for(FutureResult> result: pipelinedResults) { + for (FutureResult> result : pipelinedResults) { try { Object data = result.get(); - if(!convertPipelineAndTxResults || !(result.isStatus())) { + if (!convertPipelineAndTxResults || !(result.isStatus())) { results.add(data); } - }catch(JedisDataException e) { + } catch (JedisDataException e) { DataAccessException dataAccessException = convertJedisAccessException(e); if (cause == null) { cause = dataAccessException; } results.add(dataAccessException); - }catch(DataAccessException e) { + } catch (DataAccessException e) { if (cause == null) { cause = e; } @@ -334,7 +329,7 @@ public class JedisConnection implements RedisConnection { } private void pipeline(FutureResult> result) { - if(isQueueing()) { + if (isQueueing()) { transaction(result); } else { pipelinedResults.add(result); @@ -353,8 +348,7 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { if (sortParams != null) { pipeline(new JedisResult(pipeline.sort(key, sortParams))); - } - else { + } else { pipeline(new JedisResult(pipeline.sort(key))); } @@ -363,8 +357,7 @@ public class JedisConnection implements RedisConnection { if (isQueueing()) { if (sortParams != null) { transaction(new JedisResult(transaction.sort(key, sortParams))); - } - else { + } else { transaction(new JedisResult(transaction.sort(key))); } @@ -376,7 +369,6 @@ public class JedisConnection implements RedisConnection { } } - public Long sort(byte[] key, SortParameters params, byte[] storeKey) { SortingParams sortParams = JedisConverters.toSortingParams(params); @@ -385,8 +377,7 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { if (sortParams != null) { pipeline(new JedisResult(pipeline.sort(key, sortParams, storeKey))); - } - else { + } else { pipeline(new JedisResult(pipeline.sort(key, storeKey))); } @@ -395,8 +386,7 @@ public class JedisConnection implements RedisConnection { if (isQueueing()) { if (sortParams != null) { transaction(new JedisResult(transaction.sort(key, sortParams, storeKey))); - } - else { + } else { transaction(new JedisResult(transaction.sort(key, storeKey))); } @@ -408,7 +398,6 @@ public class JedisConnection implements RedisConnection { } } - public Long dbSize() { try { if (isPipelined()) { @@ -425,8 +414,6 @@ public class JedisConnection implements RedisConnection { } } - - public void flushDb() { try { if (isPipelined()) { @@ -443,7 +430,6 @@ public class JedisConnection implements RedisConnection { } } - public void flushAll() { try { if (isPipelined()) { @@ -460,7 +446,6 @@ public class JedisConnection implements RedisConnection { } } - public void bgSave() { try { if (isPipelined()) { @@ -477,7 +462,6 @@ public class JedisConnection implements RedisConnection { } } - public void bgWriteAof() { try { if (isPipelined()) { @@ -494,7 +478,6 @@ public class JedisConnection implements RedisConnection { } } - public void save() { try { if (isPipelined()) { @@ -511,7 +494,6 @@ public class JedisConnection implements RedisConnection { } } - public List getConfig(String param) { try { if (isPipelined()) { @@ -528,7 +510,6 @@ public class JedisConnection implements RedisConnection { } } - public Properties info() { try { if (isPipelined()) { @@ -545,7 +526,6 @@ public class JedisConnection implements RedisConnection { } } - public Properties info(String section) { if (isPipelined()) { throw new UnsupportedOperationException(); @@ -560,7 +540,6 @@ public class JedisConnection implements RedisConnection { } } - public Long lastSave() { try { if (isPipelined()) { @@ -577,7 +556,6 @@ public class JedisConnection implements RedisConnection { } } - public void setConfig(String param, String value) { try { if (isPipelined()) { @@ -594,8 +572,6 @@ public class JedisConnection implements RedisConnection { } } - - public void resetConfigStats() { try { if (isPipelined()) { @@ -612,7 +588,6 @@ public class JedisConnection implements RedisConnection { } } - public void shutdown() { try { if (isPipelined()) { @@ -629,7 +604,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] echo(byte[] message) { try { if (isPipelined()) { @@ -646,7 +620,6 @@ public class JedisConnection implements RedisConnection { } } - public String ping() { try { if (isPipelined()) { @@ -663,7 +636,6 @@ public class JedisConnection implements RedisConnection { } } - public Long del(byte[]... keys) { try { if (isPipelined()) { @@ -680,7 +652,6 @@ public class JedisConnection implements RedisConnection { } } - public void discard() { try { if (isPipelined()) { @@ -695,13 +666,11 @@ public class JedisConnection implements RedisConnection { } } - public List exec() { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.exec(), - new TransactionResultConverter>(new LinkedList>>(txResults), - JedisConverters.exceptionConverter()))); + pipeline(new JedisResult(pipeline.exec(), new TransactionResultConverter>( + new LinkedList>>(txResults), JedisConverters.exceptionConverter()))); return null; } List results = transaction.exec(); @@ -730,7 +699,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean expire(byte[] key, long seconds) { try { if (isPipelined()) { @@ -747,7 +715,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean expireAt(byte[] key, long unixTime) { try { if (isPipelined()) { @@ -764,7 +731,6 @@ public class JedisConnection implements RedisConnection { } } - public Set keys(byte[] pattern) { try { if (isPipelined()) { @@ -781,7 +747,6 @@ public class JedisConnection implements RedisConnection { } } - public void multi() { if (isQueueing()) { return; @@ -797,7 +762,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean persist(byte[] key) { try { if (isPipelined()) { @@ -814,7 +778,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean move(byte[] key, int dbIndex) { try { if (isPipelined()) { @@ -831,7 +794,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] randomKey() { try { if (isPipelined()) { @@ -848,7 +810,6 @@ public class JedisConnection implements RedisConnection { } } - public void rename(byte[] oldName, byte[] newName) { try { if (isPipelined()) { @@ -865,7 +826,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean renameNX(byte[] oldName, byte[] newName) { try { if (isPipelined()) { @@ -882,7 +842,6 @@ public class JedisConnection implements RedisConnection { } } - public void select(int dbIndex) { try { if (isPipelined()) { @@ -899,7 +858,6 @@ public class JedisConnection implements RedisConnection { } } - public Long ttl(byte[] key) { try { if (isPipelined()) { @@ -919,13 +877,11 @@ public class JedisConnection implements RedisConnection { public Boolean pExpire(byte[] key, long millis) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.pexpire(key, (int) millis), - JedisConverters.longToBoolean())); + pipeline(new JedisResult(pipeline.pexpire(key, (int) millis), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.pexpire(key, (int) millis), - JedisConverters.longToBoolean())); + transaction(new JedisResult(transaction.pexpire(key, (int) millis), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(jedis.pexpire(key, (int) millis)); @@ -937,13 +893,11 @@ public class JedisConnection implements RedisConnection { public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.pexpireAt(key, unixTimeInMillis), - JedisConverters.longToBoolean())); + pipeline(new JedisResult(pipeline.pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.pexpireAt(key, unixTimeInMillis), - JedisConverters.longToBoolean())); + transaction(new JedisResult(transaction.pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(jedis.pexpireAt(key, unixTimeInMillis)); @@ -987,13 +941,11 @@ public class JedisConnection implements RedisConnection { public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) { try { if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.restore(key, (int) ttlInMillis, - serializedValue))); + pipeline(new JedisStatusResult(pipeline.restore(key, (int) ttlInMillis, serializedValue))); return; } if (isQueueing()) { - transaction(new JedisStatusResult(transaction.restore(key, (int) ttlInMillis, - serializedValue))); + transaction(new JedisStatusResult(transaction.restore(key, (int) ttlInMillis, serializedValue))); return; } jedis.restore(key, (int) ttlInMillis, serializedValue); @@ -1018,7 +970,6 @@ public class JedisConnection implements RedisConnection { } } - public void unwatch() { try { jedis.unwatch(); @@ -1027,7 +978,6 @@ public class JedisConnection implements RedisConnection { } } - public void watch(byte[]... keys) { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -1036,8 +986,7 @@ public class JedisConnection implements RedisConnection { for (byte[] key : keys) { if (isPipelined()) { pipeline(new JedisStatusResult(pipeline.watch(key))); - } - else { + } else { jedis.watch(key); } } @@ -1050,7 +999,6 @@ public class JedisConnection implements RedisConnection { // String commands // - public byte[] get(byte[] key) { try { if (isPipelined()) { @@ -1068,7 +1016,6 @@ public class JedisConnection implements RedisConnection { } } - public void set(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1085,8 +1032,6 @@ public class JedisConnection implements RedisConnection { } } - - public byte[] getSet(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1103,7 +1048,6 @@ public class JedisConnection implements RedisConnection { } } - public Long append(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1120,7 +1064,6 @@ public class JedisConnection implements RedisConnection { } } - public List mGet(byte[]... keys) { try { if (isPipelined()) { @@ -1137,7 +1080,6 @@ public class JedisConnection implements RedisConnection { } } - public void mSet(Map tuples) { try { if (isPipelined()) { @@ -1154,7 +1096,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean mSetNX(Map tuples) { try { if (isPipelined()) { @@ -1172,7 +1113,6 @@ public class JedisConnection implements RedisConnection { } } - public void setEx(byte[] key, long time, byte[] value) { try { if (isPipelined()) { @@ -1189,17 +1129,14 @@ public class JedisConnection implements RedisConnection { } } - public Boolean setNX(byte[] key, byte[] value) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.setnx(key, value), - JedisConverters.longToBoolean())); + pipeline(new JedisResult(pipeline.setnx(key, value), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.setnx(key, value), - JedisConverters.longToBoolean())); + transaction(new JedisResult(transaction.setnx(key, value), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(jedis.setnx(key, value)); @@ -1208,17 +1145,14 @@ public class JedisConnection implements RedisConnection { } } - public byte[] getRange(byte[] key, long start, long end) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.substr(key, (int) start, (int) end), - JedisConverters.stringToBytes())); + pipeline(new JedisResult(pipeline.substr(key, (int) start, (int) end), JedisConverters.stringToBytes())); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.substr(key, (int) start, (int) end), - JedisConverters.stringToBytes())); + transaction(new JedisResult(transaction.substr(key, (int) start, (int) end), JedisConverters.stringToBytes())); return null; } return jedis.substr(key, (int) start, (int) end); @@ -1227,7 +1161,6 @@ public class JedisConnection implements RedisConnection { } } - public Long decr(byte[] key) { try { if (isPipelined()) { @@ -1244,7 +1177,6 @@ public class JedisConnection implements RedisConnection { } } - public Long decrBy(byte[] key, long value) { try { if (isPipelined()) { @@ -1261,7 +1193,6 @@ public class JedisConnection implements RedisConnection { } } - public Long incr(byte[] key) { try { if (isPipelined()) { @@ -1278,7 +1209,6 @@ public class JedisConnection implements RedisConnection { } } - public Long incrBy(byte[] key, long value) { try { if (isPipelined()) { @@ -1334,7 +1264,6 @@ public class JedisConnection implements RedisConnection { } } - public void setBit(byte[] key, long offset, boolean value) { try { if (isPipelined()) { @@ -1351,7 +1280,6 @@ public class JedisConnection implements RedisConnection { } } - public void setRange(byte[] key, byte[] value, long start) { try { if (isPipelined()) { @@ -1368,7 +1296,6 @@ public class JedisConnection implements RedisConnection { } } - public Long strLen(byte[] key) { try { if (isPipelined()) { @@ -1385,7 +1312,6 @@ public class JedisConnection implements RedisConnection { } } - public Long bitCount(byte[] key) { try { if (isPipelined()) { @@ -1402,7 +1328,6 @@ public class JedisConnection implements RedisConnection { } } - public Long bitCount(byte[] key, long begin, long end) { try { if (isPipelined()) { @@ -1419,9 +1344,8 @@ public class JedisConnection implements RedisConnection { } } - public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { - if(op == BitOperation.NOT && keys.length > 1) { + if (op == BitOperation.NOT && keys.length > 1) { throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); } try { @@ -1459,7 +1383,6 @@ public class JedisConnection implements RedisConnection { } } - public Long rPush(byte[] key, byte[]... values) { try { if (isPipelined()) { @@ -1476,7 +1399,6 @@ public class JedisConnection implements RedisConnection { } } - public List bLPop(int timeout, byte[]... keys) { try { if (isPipelined()) { @@ -1493,7 +1415,6 @@ public class JedisConnection implements RedisConnection { } } - public List bRPop(int timeout, byte[]... keys) { try { if (isPipelined()) { @@ -1510,7 +1431,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] lIndex(byte[] key, long index) { try { if (isPipelined()) { @@ -1527,17 +1447,14 @@ public class JedisConnection implements RedisConnection { } } - public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.linsert(key, JedisConverters.toListPosition(where), - pivot, value))); + pipeline(new JedisResult(pipeline.linsert(key, JedisConverters.toListPosition(where), pivot, value))); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.linsert(key, JedisConverters.toListPosition(where), - pivot, value))); + transaction(new JedisResult(transaction.linsert(key, JedisConverters.toListPosition(where), pivot, value))); return null; } return jedis.linsert(key, JedisConverters.toListPosition(where), pivot, value); @@ -1546,7 +1463,6 @@ public class JedisConnection implements RedisConnection { } } - public Long lLen(byte[] key) { try { if (isPipelined()) { @@ -1563,7 +1479,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] lPop(byte[] key) { try { if (isPipelined()) { @@ -1580,7 +1495,6 @@ public class JedisConnection implements RedisConnection { } } - public List lRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1597,7 +1511,6 @@ public class JedisConnection implements RedisConnection { } } - public Long lRem(byte[] key, long count, byte[] value) { try { if (isPipelined()) { @@ -1614,7 +1527,6 @@ public class JedisConnection implements RedisConnection { } } - public void lSet(byte[] key, long index, byte[] value) { try { if (isPipelined()) { @@ -1631,7 +1543,6 @@ public class JedisConnection implements RedisConnection { } } - public void lTrim(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1648,7 +1559,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] rPop(byte[] key) { try { if (isPipelined()) { @@ -1665,7 +1575,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { if (isPipelined()) { @@ -1682,7 +1591,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { try { if (isPipelined()) { @@ -1699,7 +1607,6 @@ public class JedisConnection implements RedisConnection { } } - public Long lPushX(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1716,7 +1623,6 @@ public class JedisConnection implements RedisConnection { } } - public Long rPushX(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1733,12 +1639,10 @@ public class JedisConnection implements RedisConnection { } } - // // Set commands // - public Long sAdd(byte[] key, byte[]... values) { try { if (isPipelined()) { @@ -1755,7 +1659,6 @@ public class JedisConnection implements RedisConnection { } } - public Long sCard(byte[] key) { try { if (isPipelined()) { @@ -1772,7 +1675,6 @@ public class JedisConnection implements RedisConnection { } } - public Set sDiff(byte[]... keys) { try { if (isPipelined()) { @@ -1789,7 +1691,6 @@ public class JedisConnection implements RedisConnection { } } - public Long sDiffStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1806,7 +1707,6 @@ public class JedisConnection implements RedisConnection { } } - public Set sInter(byte[]... keys) { try { if (isPipelined()) { @@ -1823,7 +1723,6 @@ public class JedisConnection implements RedisConnection { } } - public Long sInterStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1840,7 +1739,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean sIsMember(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1857,7 +1755,6 @@ public class JedisConnection implements RedisConnection { } } - public Set sMembers(byte[] key) { try { if (isPipelined()) { @@ -1874,7 +1771,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { if (isPipelined()) { @@ -1882,8 +1778,7 @@ public class JedisConnection implements RedisConnection { return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.smove(srcKey, destKey, value), - JedisConverters.longToBoolean())); + transaction(new JedisResult(transaction.smove(srcKey, destKey, value), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(jedis.smove(srcKey, destKey, value)); @@ -1892,7 +1787,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] sPop(byte[] key) { try { if (isPipelined()) { @@ -1909,7 +1803,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] sRandMember(byte[] key) { try { if (isPipelined()) { @@ -1958,7 +1851,6 @@ public class JedisConnection implements RedisConnection { } } - public Set sUnion(byte[]... keys) { try { if (isPipelined()) { @@ -1975,7 +1867,6 @@ public class JedisConnection implements RedisConnection { } } - public Long sUnionStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1996,7 +1887,6 @@ public class JedisConnection implements RedisConnection { // ZSet commands // - public Boolean zAdd(byte[] key, double score, byte[] value) { try { if (isPipelined()) { @@ -2014,9 +1904,8 @@ public class JedisConnection implements RedisConnection { } public Long zAdd(byte[] key, Set tuples) { - if(isPipelined() || isQueueing()) { - throw new UnsupportedOperationException("zAdd of multiple fields not supported " + - "in pipeline or transaction"); + if (isPipelined() || isQueueing()) { + throw new UnsupportedOperationException("zAdd of multiple fields not supported " + "in pipeline or transaction"); } Map args = zAddArgs(tuples); try { @@ -2042,7 +1931,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zCount(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2059,7 +1947,6 @@ public class JedisConnection implements RedisConnection { } } - public Double zIncrBy(byte[] key, double increment, byte[] value) { try { if (isPipelined()) { @@ -2076,7 +1963,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { ZParams zparams = new ZParams().weights(weights).aggregate( @@ -2096,7 +1982,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zInterStore(byte[] destKey, byte[]... sets) { try { if (isPipelined()) { @@ -2113,7 +1998,6 @@ public class JedisConnection implements RedisConnection { } } - public Set zRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -2130,17 +2014,14 @@ public class JedisConnection implements RedisConnection { } } - public Set zRangeWithScores(byte[] key, long start, long end) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrangeWithScores(key, start, end), - JedisConverters.tupleSetToTupleSet())); + pipeline(new JedisResult(pipeline.zrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.zrangeWithScores(key, start, end), - JedisConverters.tupleSetToTupleSet())); + transaction(new JedisResult(transaction.zrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); return null; } return JedisConverters.toTupleSet(jedis.zrangeWithScores(key, start, end)); @@ -2149,7 +2030,6 @@ public class JedisConnection implements RedisConnection { } } - public Set zRangeByScore(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2166,12 +2046,10 @@ public class JedisConnection implements RedisConnection { } } - public Set zRangeByScoreWithScores(byte[] key, double min, double max) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrangeByScoreWithScores(key, min, max), - JedisConverters.tupleSetToTupleSet())); + pipeline(new JedisResult(pipeline.zrangeByScoreWithScores(key, min, max), JedisConverters.tupleSetToTupleSet())); return null; } if (isQueueing()) { @@ -2185,12 +2063,10 @@ public class JedisConnection implements RedisConnection { } } - public Set zRevRangeWithScores(byte[] key, long start, long end) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrevrangeWithScores(key, start, end), - JedisConverters.tupleSetToTupleSet())); + pipeline(new JedisResult(pipeline.zrevrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); return null; } if (isQueueing()) { @@ -2204,7 +2080,6 @@ public class JedisConnection implements RedisConnection { } } - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isPipelined()) { @@ -2221,7 +2096,6 @@ public class JedisConnection implements RedisConnection { } } - public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { try { if (isPipelined()) { @@ -2240,7 +2114,6 @@ public class JedisConnection implements RedisConnection { } } - public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isPipelined()) { @@ -2257,7 +2130,6 @@ public class JedisConnection implements RedisConnection { } } - public Set zRevRangeByScore(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2274,27 +2146,24 @@ public class JedisConnection implements RedisConnection { } } - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrevrangeByScoreWithScores(key, max, min, (int) offset, - (int) count), JedisConverters.tupleSetToTupleSet())); + pipeline(new JedisResult(pipeline.zrevrangeByScoreWithScores(key, max, min, (int) offset, (int) count), + JedisConverters.tupleSetToTupleSet())); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.zrevrangeByScoreWithScores(key, max, min, (int) offset, - (int) count), JedisConverters.tupleSetToTupleSet())); + transaction(new JedisResult(transaction.zrevrangeByScoreWithScores(key, max, min, (int) offset, (int) count), + JedisConverters.tupleSetToTupleSet())); return null; } - return JedisConverters.toTupleSet(jedis.zrevrangeByScoreWithScores(key, max, min, (int) offset, - (int) count)); + return JedisConverters.toTupleSet(jedis.zrevrangeByScoreWithScores(key, max, min, (int) offset, (int) count)); } catch (Exception ex) { throw convertJedisAccessException(ex); } } - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2313,7 +2182,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zRank(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -2330,7 +2198,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zRem(byte[] key, byte[]... values) { try { if (isPipelined()) { @@ -2347,7 +2214,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zRemRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -2364,7 +2230,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zRemRangeByScore(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2381,7 +2246,6 @@ public class JedisConnection implements RedisConnection { } } - public Set zRevRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -2398,7 +2262,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zRevRank(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -2415,7 +2278,6 @@ public class JedisConnection implements RedisConnection { } } - public Double zScore(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -2432,7 +2294,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { ZParams zparams = new ZParams().weights(weights).aggregate( @@ -2452,7 +2313,6 @@ public class JedisConnection implements RedisConnection { } } - public Long zUnionStore(byte[] destKey, byte[]... sets) { try { if (isPipelined()) { @@ -2473,7 +2333,6 @@ public class JedisConnection implements RedisConnection { // Hash commands // - public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { if (isPipelined()) { @@ -2481,8 +2340,7 @@ public class JedisConnection implements RedisConnection { return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.hset(key, field, value), - JedisConverters.longToBoolean())); + transaction(new JedisResult(transaction.hset(key, field, value), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(jedis.hset(key, field, value)); @@ -2491,17 +2349,14 @@ public class JedisConnection implements RedisConnection { } } - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.hsetnx(key, field, value), - JedisConverters.longToBoolean())); + pipeline(new JedisResult(pipeline.hsetnx(key, field, value), JedisConverters.longToBoolean())); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.hsetnx(key, field, value), - JedisConverters.longToBoolean())); + transaction(new JedisResult(transaction.hsetnx(key, field, value), JedisConverters.longToBoolean())); return null; } return JedisConverters.toBoolean(jedis.hsetnx(key, field, value)); @@ -2510,7 +2365,6 @@ public class JedisConnection implements RedisConnection { } } - public Long hDel(byte[] key, byte[]... fields) { try { if (isPipelined()) { @@ -2527,7 +2381,6 @@ public class JedisConnection implements RedisConnection { } } - public Boolean hExists(byte[] key, byte[] field) { try { if (isPipelined()) { @@ -2544,7 +2397,6 @@ public class JedisConnection implements RedisConnection { } } - public byte[] hGet(byte[] key, byte[] field) { try { if (isPipelined()) { @@ -2561,7 +2413,6 @@ public class JedisConnection implements RedisConnection { } } - public Map hGetAll(byte[] key) { try { if (isPipelined()) { @@ -2578,7 +2429,6 @@ public class JedisConnection implements RedisConnection { } } - public Long hIncrBy(byte[] key, byte[] field, long delta) { try { if (isPipelined()) { @@ -2627,7 +2477,6 @@ public class JedisConnection implements RedisConnection { } } - public Long hLen(byte[] key) { try { if (isPipelined()) { @@ -2644,7 +2493,6 @@ public class JedisConnection implements RedisConnection { } } - public List hMGet(byte[] key, byte[]... fields) { try { if (isPipelined()) { @@ -2661,7 +2509,6 @@ public class JedisConnection implements RedisConnection { } } - public void hMSet(byte[] key, Map tuple) { try { if (isPipelined()) { @@ -2678,7 +2525,6 @@ public class JedisConnection implements RedisConnection { } } - public List hVals(byte[] key) { try { if (isPipelined()) { @@ -2695,7 +2541,6 @@ public class JedisConnection implements RedisConnection { } } - // // Pub/Sub functionality // @@ -2716,17 +2561,14 @@ public class JedisConnection implements RedisConnection { } } - public Subscription getSubscription() { return subscription; } - public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } - public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( @@ -2750,7 +2592,6 @@ public class JedisConnection implements RedisConnection { } } - public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( @@ -2844,8 +2685,8 @@ public class JedisConnection implements RedisConnection { throw new UnsupportedOperationException(); } try { - return (T) new JedisScriptReturnConverter(returnType).convert( - jedis.eval(script, JedisConverters.toBytes(numKeys), keysAndArgs)); + return (T) new JedisScriptReturnConverter(returnType).convert(jedis.eval(script, + JedisConverters.toBytes(numKeys), keysAndArgs)); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -2860,18 +2701,17 @@ public class JedisConnection implements RedisConnection { throw new UnsupportedOperationException(); } try { - return (T) new JedisScriptReturnConverter(returnType).convert( - jedis.evalsha(scriptSha1, numKeys, JedisConverters.toStrings(keysAndArgs))); + return (T) new JedisScriptReturnConverter(returnType).convert(jedis.evalsha(scriptSha1, numKeys, + JedisConverters.toStrings(keysAndArgs))); } catch (Exception ex) { throw convertJedisAccessException(ex); } } /** - * 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 - * + * 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 + * * @param convertPipelineAndTxResults Whether or not to convert pipeline and tx results */ public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) { @@ -2887,12 +2727,12 @@ public class JedisConnection implements RedisConnection { return args.toArray(new byte[args.size()][]); } - private Map zAddArgs(Set tuples) { + private Map zAddArgs(Set tuples) { Map args = new HashMap(); - for(Tuple tuple: tuples) { - if(args.containsKey(tuple.getScore())) { - throw new UnsupportedOperationException("Bulk add of multiple elements with the same score is not supported. " + - "Add the elements individually."); + for (Tuple tuple : tuples) { + if (args.containsKey(tuple.getScore())) { + throw new UnsupportedOperationException("Bulk add of multiple elements with the same score is not supported. " + + "Add the elements individually."); } args.put(tuple.getScore(), tuple.getValue()); } diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java index daf509da3..2a69dcc9b 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java @@ -54,16 +54,15 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, private boolean convertPipelineAndTxResults = true; /** - * Constructs a new JedisConnectionFactory instance - * with default settings (default connection pooling, no shard information). + * Constructs a new JedisConnectionFactory instance with default settings (default connection pooling, no + * shard information). */ - public JedisConnectionFactory() { - } + public JedisConnectionFactory() {} /** - * Constructs a new JedisConnectionFactory instance. - * Will override the other connection parameters passed to the factory. - * + * Constructs a new JedisConnectionFactory instance. Will override the other connection parameters passed + * to the factory. + * * @param shardInfo shard information */ public JedisConnectionFactory(JedisShardInfo shardInfo) { @@ -71,19 +70,17 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, } /** - * Constructs a new JedisConnectionFactory instance using - * the given pool configuration. - * + * Constructs a new JedisConnectionFactory instance using the given pool configuration. + * * @param poolConfig pool configuration */ public JedisConnectionFactory(JedisPoolConfig poolConfig) { this.poolConfig = poolConfig; } - /** - * Returns a Jedis instance to be used as a Redis connection. - * The instance can be newly created or retrieved from a pool. + * Returns a Jedis instance to be used as a Redis connection. The instance can be newly created or retrieved from a + * pool. * * @return Jedis instance ready for wrapping into a {@link RedisConnection}. */ @@ -102,9 +99,8 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, } /** - * Post process a newly retrieved connection. Useful for decorating or executing - * initialization commands on a new connection. - * This implementation simply returns the connection. + * Post process a newly retrieved connection. Useful for decorating or executing initialization commands on a new + * connection. This implementation simply returns the connection. * * @param connection * @return processed connection @@ -145,20 +141,19 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, public JedisConnection getConnection() { Jedis jedis = fetchJedisConnector(); - JedisConnection connection = (usePool ? new JedisConnection(jedis, pool, dbIndex) : - new JedisConnection(jedis, null, dbIndex)); + JedisConnection connection = (usePool ? new JedisConnection(jedis, pool, dbIndex) : new JedisConnection(jedis, + null, dbIndex)); connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults); return postProcessConnection(connection); } - public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return JedisConverters.toDataAccessException(ex); } /** * Returns the Redis hostName. - * + * * @return Returns the hostName */ public String getHostName() { @@ -213,7 +208,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, /** * Returns the shardInfo. - * + * * @return Returns the shardInfo */ public JedisShardInfo getShardInfo() { @@ -231,7 +226,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, /** * Returns the timeout. - * + * * @return Returns the timeout */ public int getTimeout() { @@ -247,7 +242,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, /** * Indicates the use of a connection pool. - * + * * @return Returns the use of connection pooling. */ public boolean getUsePool() { @@ -265,7 +260,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, /** * Returns the poolConfig. - * + * * @return Returns the poolConfig */ public JedisPoolConfig getPoolConfig() { @@ -281,10 +276,9 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, this.poolConfig = poolConfig; } - /** * Returns the index of the database. - * + * * @return Returns the database index */ public int getDatabase() { @@ -292,8 +286,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, } /** - * Sets the index of the database used by this connection factory. - * Default is 0. + * Sets the index of the database used by this connection factory. Default is 0. * * @param index database index */ @@ -303,10 +296,10 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, } /** - * Specifies if pipelined results should be converted to the expected data - * type. If false, results of {@link JedisConnection#closePipeline()} and - * {@link JedisConnection#exec()} will be of the type returned by the Jedis driver - * + * Specifies if pipelined results should be converted to the expected data type. If false, results of + * {@link JedisConnection#closePipeline()} and {@link JedisConnection#exec()} will be of the type returned by the + * Jedis driver + * * @return Whether or not to convert pipeline and tx results */ public boolean getConvertPipelineAndTxResults() { @@ -314,13 +307,13 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, } /** - * Specifies if pipelined results should be converted to the expected data - * type. If false, results of {@link JedisConnection#closePipeline()} and - * {@link JedisConnection#exec()} will be of the type returned by the Jedis driver - * + * Specifies if pipelined results should be converted to the expected data type. If false, results of + * {@link JedisConnection#closePipeline()} and {@link JedisConnection#exec()} will be of the type returned by the + * Jedis driver + * * @param convertPipelineAndTxResults Whether or not to convert pipeline and tx results */ public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) { this.convertPipelineAndTxResults = convertPipelineAndTxResults; } -} \ No newline at end of file +} 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 8468a5a35..69c6a2663 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 @@ -40,9 +40,8 @@ import redis.clients.util.SafeEncoder; /** * Jedis type converters - * + * * @author Jennifer Hickey - * */ abstract public class JedisConverters extends Converters { @@ -51,7 +50,7 @@ abstract public class JedisConverters extends Converters { private static final SetConverter STRING_SET_TO_BYTE_SET; 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 EXCEPTION_CONVERTER = new JedisExceptionConverter(); static { STRING_TO_BYTES = new Converter() { @@ -91,7 +90,7 @@ abstract public class JedisConverters extends Converters { return TUPLE_SET_TO_TUPLE_SET; } - public static Converter exceptionConverter() { + public static Converter exceptionConverter() { return EXCEPTION_CONVERTER; } @@ -163,7 +162,7 @@ abstract public class JedisConverters extends Converters { } public static BitOP toBitOp(BitOperation bitOp) { - switch(bitOp) { + switch (bitOp) { case AND: return BitOP.AND; case OR: diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisExceptionConverter.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisExceptionConverter.java index 32a54decc..99b169f2d 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisExceptionConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisExceptionConverter.java @@ -30,9 +30,8 @@ import redis.clients.jedis.exceptions.JedisException; /** * Converts Exceptions thrown from Jedis to {@link DataAccessException}s - * + * * @author Jennifer Hickey - * */ public class JedisExceptionConverter implements Converter { diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisMessageListener.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisMessageListener.java index 18fe7365b..b826af4a1 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisMessageListener.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisMessageListener.java @@ -35,33 +35,27 @@ class JedisMessageListener extends BinaryJedisPubSub { this.listener = listener; } - public void onMessage(byte[] channel, byte[] message) { listener.onMessage(new DefaultMessage(channel, message), null); } - public void onPMessage(byte[] pattern, byte[] channel, byte[] message) { listener.onMessage(new DefaultMessage(channel, message), pattern); } - public void onPSubscribe(byte[] pattern, int subscribedChannels) { // no-op } - public void onPUnsubscribe(byte[] pattern, int subscribedChannels) { - // no-op + // no-op } - public void onSubscribe(byte[] channel, int subscribedChannels) { // no-op } - public void onUnsubscribe(byte[] channel, int subscribedChannels) { // no-op } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisScriptReturnConverter.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisScriptReturnConverter.java index 61b76451c..237f2bdf8 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisScriptReturnConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisScriptReturnConverter.java @@ -24,11 +24,9 @@ import org.springframework.data.redis.connection.ReturnType; import redis.clients.util.SafeEncoder; /** - * Converts the value returned by Jedis script eval to the expected - * {@link ReturnType} - * + * Converts the value returned by Jedis script eval to the expected {@link ReturnType} + * * @author Jennifer Hickey - * */ public class JedisScriptReturnConverter implements Converter { diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisSubscription.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisSubscription.java index 5540d7911..2cc21b09c 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisSubscription.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisSubscription.java @@ -34,43 +34,36 @@ class JedisSubscription extends AbstractSubscription { this.jedisPubSub = jedisPubSub; } - protected void doClose() { - if(!getChannels().isEmpty()) { + if (!getChannels().isEmpty()) { jedisPubSub.unsubscribe(); } - if(!getPatterns().isEmpty()) { + if (!getPatterns().isEmpty()) { jedisPubSub.punsubscribe(); } } - protected void doPsubscribe(byte[]... patterns) { jedisPubSub.psubscribe(patterns); } - protected void doPUnsubscribe(boolean all, byte[]... patterns) { if (all) { jedisPubSub.punsubscribe(); - } - else { + } else { jedisPubSub.punsubscribe(patterns); } } - protected void doSubscribe(byte[]... channels) { jedisPubSub.subscribe(channels); } - protected void doUnsubscribe(boolean all, byte[]... channels) { if (all) { jedisPubSub.unsubscribe(); - } - else { + } else { jedisPubSub.unsubscribe(channels); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisUtils.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisUtils.java index 5c3389d31..54d9f092b 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisUtils.java @@ -52,9 +52,8 @@ import redis.clients.jedis.exceptions.JedisException; import redis.clients.util.SafeEncoder; /** - * Helper class featuring methods for Jedis connection handling, providing support for exception translation. - * - * Deprecated in favor of {@link JedisConverters} + * Helper class featuring methods for Jedis connection handling, providing support for exception translation. Deprecated + * in favor of {@link JedisConverters} * * @author Costin Leau * @author Jennifer Hickey @@ -283,28 +282,28 @@ public abstract class JedisUtils { @SuppressWarnings("unchecked") static Object convertScriptReturn(ReturnType returnType, Object result) { - if(result instanceof String) { - //evalsha converts byte[] to String. Convert back for consistency - return SafeEncoder.encode((String)result); + if (result instanceof String) { + // evalsha converts byte[] to String. Convert back for consistency + return SafeEncoder.encode((String) result); } - if(returnType == ReturnType.STATUS) { - return JedisUtils.asString((byte[])result); + if (returnType == ReturnType.STATUS) { + return JedisUtils.asString((byte[]) result); } - if(returnType == ReturnType.BOOLEAN) { + if (returnType == ReturnType.BOOLEAN) { // Lua false comes back as a null bulk reply - if(result == null) { + if (result == null) { return Boolean.FALSE; } - return ((Long)result == 1); + return ((Long) result == 1); } - if(returnType == ReturnType.MULTI) { + if (returnType == ReturnType.MULTI) { List resultList = (List) result; List convertedResults = new ArrayList(); - for(Object res: resultList) { - if(res instanceof String) { - //evalsha converts byte[] to String. Convert back for consistency - convertedResults.add(SafeEncoder.encode((String)res)); - }else { + for (Object res : resultList) { + if (res instanceof String) { + // evalsha converts byte[] to String. Convert back for consistency + convertedResults.add(SafeEncoder.encode((String) res)); + } else { convertedResults.add(res); } } @@ -313,4 +312,4 @@ public abstract class JedisUtils { return result; } -} \ No newline at end of file +} 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 046a4d020..ec900708b 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 @@ -64,14 +64,13 @@ public class JredisConnection implements RedisConnection { private boolean broken = false; static { - SERVICE_REQUEST = ReflectionUtils.findMethod(JRedisSupport.class, "serviceRequest", Command.class, - byte[][].class); + SERVICE_REQUEST = ReflectionUtils.findMethod(JRedisSupport.class, "serviceRequest", Command.class, byte[][].class); ReflectionUtils.makeAccessible(SERVICE_REQUEST); } /** * Constructs a new JredisConnection instance. - * + * * @param jredis JRedis connection */ public JredisConnection(JRedis jredis) { @@ -90,7 +89,7 @@ public class JredisConnection implements RedisConnection { } if (ex instanceof ClientRuntimeException) { - if(ex instanceof NotConnectedException || ex instanceof ConnectionException) { + if (ex instanceof NotConnectedException || ex instanceof ConnectionException) { broken = true; } return JredisUtils.convertJredisAccessException((ClientRuntimeException) ex); @@ -115,7 +114,7 @@ public class JredisConnection implements RedisConnection { } public void close() throws RedisSystemException { - if(isClosed()) { + if (isClosed()) { return; } isClosed = true; @@ -123,7 +122,7 @@ public class JredisConnection implements RedisConnection { if (pool != null) { if (!broken) { pool.returnResource(jredis); - }else { + } else { pool.returnBrokenResource(jredis); } return; @@ -141,32 +140,26 @@ public class JredisConnection implements RedisConnection { return jredis; } - public boolean isClosed() { return isClosed; } - public boolean isQueueing() { return false; } - public boolean isPipelined() { return false; } - public void openPipeline() { throw new UnsupportedOperationException("Pipelining not supported by JRedis"); } - public List closePipeline() { return Collections.emptyList(); } - public List sort(byte[] key, SortParameters params) { Sort sort = jredis.sort(key); JredisUtils.applySortingParams(sort, params, null); @@ -177,7 +170,6 @@ public class JredisConnection implements RedisConnection { } } - public Long sort(byte[] key, SortParameters params, byte[] storeKey) { Sort sort = jredis.sort(key); JredisUtils.applySortingParams(sort, params, storeKey); @@ -188,16 +180,14 @@ public class JredisConnection implements RedisConnection { } } - public Long dbSize() { try { - return (Long)jredis.dbsize(); + return (Long) jredis.dbsize(); } catch (Exception ex) { throw convertJredisAccessException(ex); } } - public void flushDb() { try { jredis.flushdb(); @@ -206,7 +196,6 @@ public class JredisConnection implements RedisConnection { } } - public void flushAll() { try { jredis.flushall(); @@ -215,7 +204,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] echo(byte[] message) { try { return jredis.echo(message); @@ -224,7 +212,6 @@ public class JredisConnection implements RedisConnection { } } - public String ping() { try { jredis.ping(); @@ -234,7 +221,6 @@ public class JredisConnection implements RedisConnection { } } - public void bgSave() { try { jredis.bgsave(); @@ -243,7 +229,6 @@ public class JredisConnection implements RedisConnection { } } - public void bgWriteAof() { try { jredis.bgrewriteaof(); @@ -252,7 +237,6 @@ public class JredisConnection implements RedisConnection { } } - public void save() { try { jredis.save(); @@ -261,12 +245,10 @@ public class JredisConnection implements RedisConnection { } } - public List getConfig(String pattern) { throw new UnsupportedOperationException(); } - public Properties info() { try { return JredisUtils.info(jredis.info()); @@ -275,36 +257,30 @@ public class JredisConnection implements RedisConnection { } } - public Properties info(String section) { throw new UnsupportedOperationException(); } - public Long lastSave() { try { - return (Long)jredis.lastsave(); + return (Long) jredis.lastsave(); } catch (Exception ex) { throw convertJredisAccessException(ex); } } - public void setConfig(String param, String value) { throw new UnsupportedOperationException(); } - public void resetConfigStats() { throw new UnsupportedOperationException(); } - public void shutdown() { throw new UnsupportedOperationException(); } - public Long del(byte[]... keys) { try { return jredis.del(keys); @@ -313,7 +289,6 @@ public class JredisConnection implements RedisConnection { } } - public void discard() { try { jredis.discard(); @@ -322,12 +297,10 @@ public class JredisConnection implements RedisConnection { } } - public List exec() { throw new UnsupportedOperationException(); } - public Boolean exists(byte[] key) { try { return jredis.exists(key); @@ -336,7 +309,6 @@ public class JredisConnection implements RedisConnection { } } - public Boolean expire(byte[] key, long seconds) { try { return jredis.expire(key, (int) seconds); @@ -345,7 +317,6 @@ public class JredisConnection implements RedisConnection { } } - public Boolean expireAt(byte[] key, long unixTime) { try { return jredis.expireat(key, unixTime); @@ -382,18 +353,14 @@ public class JredisConnection implements RedisConnection { } } - public void multi() { throw new UnsupportedOperationException(); } - public Boolean persist(byte[] key) { throw new UnsupportedOperationException(); } - - public Boolean move(byte[] key, int dbIndex) { try { return jredis.move(key, dbIndex); @@ -402,7 +369,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] randomKey() { try { return jredis.randomkey(); @@ -411,7 +377,6 @@ public class JredisConnection implements RedisConnection { } } - public void rename(byte[] oldName, byte[] newName) { try { jredis.rename(oldName, newName); @@ -420,7 +385,6 @@ public class JredisConnection implements RedisConnection { } } - public Boolean renameNX(byte[] oldName, byte[] newName) { try { return jredis.renamenx(oldName, newName); @@ -429,12 +393,10 @@ public class JredisConnection implements RedisConnection { } } - public void select(int dbIndex) { throw new UnsupportedOperationException(); } - public Long ttl(byte[] key) { try { return jredis.ttl(key); @@ -443,7 +405,6 @@ public class JredisConnection implements RedisConnection { } } - public DataType type(byte[] key) { try { return JredisUtils.convertDataType(jredis.type(key)); @@ -452,12 +413,10 @@ public class JredisConnection implements RedisConnection { } } - public void unwatch() { throw new UnsupportedOperationException(); } - public void watch(byte[]... keys) { throw new UnsupportedOperationException(); } @@ -466,7 +425,6 @@ public class JredisConnection implements RedisConnection { // String operations // - public byte[] get(byte[] key) { try { return jredis.get(key); @@ -475,7 +433,6 @@ public class JredisConnection implements RedisConnection { } } - public void set(byte[] key, byte[] value) { try { jredis.set(key, value); @@ -484,7 +441,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] getSet(byte[] key, byte[] value) { try { return jredis.getset(key, value); @@ -493,7 +449,6 @@ public class JredisConnection implements RedisConnection { } } - public Long append(byte[] key, byte[] value) { try { return jredis.append(key, value); @@ -502,7 +457,6 @@ public class JredisConnection implements RedisConnection { } } - public List mGet(byte[]... keys) { try { return jredis.mget(keys); @@ -511,7 +465,6 @@ public class JredisConnection implements RedisConnection { } } - public void mSet(Map tuple) { try { jredis.mset(tuple); @@ -520,7 +473,6 @@ public class JredisConnection implements RedisConnection { } } - public Boolean mSetNX(Map tuple) { try { return jredis.msetnx(tuple); @@ -529,12 +481,10 @@ public class JredisConnection implements RedisConnection { } } - public void setEx(byte[] key, long seconds, byte[] value) { throw new UnsupportedOperationException(); } - public Boolean setNX(byte[] key, byte[] value) { try { return jredis.setnx(key, value); @@ -543,7 +493,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] getRange(byte[] key, long start, long end) { try { return jredis.substr(key, start, end); @@ -552,7 +501,6 @@ public class JredisConnection implements RedisConnection { } } - public Long decr(byte[] key) { try { return jredis.decr(key); @@ -561,7 +509,6 @@ public class JredisConnection implements RedisConnection { } } - public Long decrBy(byte[] key, long value) { try { return jredis.decrby(key, (int) value); @@ -570,7 +517,6 @@ public class JredisConnection implements RedisConnection { } } - public Long incr(byte[] key) { try { return jredis.incr(key); @@ -579,7 +525,6 @@ public class JredisConnection implements RedisConnection { } } - public Long incrBy(byte[] key, long value) { try { return jredis.incrby(key, (int) value); @@ -588,21 +533,18 @@ public class JredisConnection implements RedisConnection { } } - public Double incrBy(byte[] key, double value) { throw new UnsupportedOperationException(); } - public Boolean getBit(byte[] key, long offset) { try { - return jredis.getbit(key, (int)offset); - } catch(Exception ex) { + return jredis.getbit(key, (int) offset); + } catch (Exception ex) { throw convertJredisAccessException(ex); } } - public void setBit(byte[] key, long offset, boolean value) { try { jredis.setbit(key, (int) offset, value); @@ -611,27 +553,22 @@ public class JredisConnection implements RedisConnection { } } - public void setRange(byte[] key, byte[] value, long start) { throw new UnsupportedOperationException(); } - public Long strLen(byte[] key) { throw new UnsupportedOperationException(); } - public Long bitCount(byte[] key) { throw new UnsupportedOperationException(); } - public Long bitCount(byte[] key, long begin, long end) { throw new UnsupportedOperationException(); } - public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { throw new UnsupportedOperationException(); } @@ -640,17 +577,14 @@ public class JredisConnection implements RedisConnection { // List commands // - public List bLPop(int timeout, byte[]... keys) { throw new UnsupportedOperationException(); } - public List bRPop(int timeout, byte[]... keys) { throw new UnsupportedOperationException(); } - public byte[] lIndex(byte[] key, long index) { try { return jredis.lindex(key, index); @@ -659,7 +593,6 @@ public class JredisConnection implements RedisConnection { } } - public Long lLen(byte[] key) { try { return jredis.llen(key); @@ -668,7 +601,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] lPop(byte[] key) { try { return jredis.lpop(key); @@ -677,9 +609,8 @@ public class JredisConnection implements RedisConnection { } } - public Long lPush(byte[] key, byte[]... values) { - if(values.length > 1) { + if (values.length > 1) { throw new UnsupportedOperationException("lPush of multiple fields not supported"); } try { @@ -690,7 +621,6 @@ public class JredisConnection implements RedisConnection { } } - public List lRange(byte[] key, long start, long end) { try { List lrange = jredis.lrange(key, start, end); @@ -701,7 +631,6 @@ public class JredisConnection implements RedisConnection { } } - public Long lRem(byte[] key, long count, byte[] value) { try { return jredis.lrem(key, value, (int) count); @@ -710,7 +639,6 @@ public class JredisConnection implements RedisConnection { } } - public void lSet(byte[] key, long index, byte[] value) { try { jredis.lset(key, index, value); @@ -719,7 +647,6 @@ public class JredisConnection implements RedisConnection { } } - public void lTrim(byte[] key, long start, long end) { try { jredis.ltrim(key, start, end); @@ -728,7 +655,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] rPop(byte[] key) { try { return jredis.rpop(key); @@ -737,7 +663,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { return jredis.rpoplpush(srcKey, dstKey); @@ -746,9 +671,8 @@ public class JredisConnection implements RedisConnection { } } - public Long rPush(byte[] key, byte[]... values) { - if(values.length > 1) { + if (values.length > 1) { throw new UnsupportedOperationException("rPush of multiple fields not supported"); } try { @@ -759,34 +683,28 @@ public class JredisConnection implements RedisConnection { } } - public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { throw new UnsupportedOperationException(); } - public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { throw new UnsupportedOperationException(); } - public Long lPushX(byte[] key, byte[] value) { throw new UnsupportedOperationException(); } - public Long rPushX(byte[] key, byte[] value) { throw new UnsupportedOperationException(); } - // // Set commands // - public Long sAdd(byte[] key, byte[]... values) { - if(values.length > 1) { + if (values.length > 1) { throw new UnsupportedOperationException("sAdd of multiple fields not supported"); } try { @@ -796,7 +714,6 @@ public class JredisConnection implements RedisConnection { } } - public Long sCard(byte[] key) { try { return jredis.scard(key); @@ -805,7 +722,6 @@ public class JredisConnection implements RedisConnection { } } - public Set sDiff(byte[]... keys) { byte[] destKey = keys[0]; byte[][] sets = Arrays.copyOfRange(keys, 1, keys.length); @@ -818,7 +734,6 @@ public class JredisConnection implements RedisConnection { } } - public Long sDiffStore(byte[] destKey, byte[]... keys) { try { jredis.sdiffstore(destKey, keys); @@ -828,7 +743,6 @@ public class JredisConnection implements RedisConnection { } } - public Set sInter(byte[]... keys) { byte[] set1 = keys[0]; byte[][] sets = Arrays.copyOfRange(keys, 1, keys.length); @@ -841,7 +755,6 @@ public class JredisConnection implements RedisConnection { } } - public Long sInterStore(byte[] destKey, byte[]... keys) { try { jredis.sinterstore(destKey, keys); @@ -851,7 +764,6 @@ public class JredisConnection implements RedisConnection { } } - public Boolean sIsMember(byte[] key, byte[] value) { try { return jredis.sismember(key, value); @@ -860,7 +772,6 @@ public class JredisConnection implements RedisConnection { } } - public Set sMembers(byte[] key) { try { return new LinkedHashSet(jredis.smembers(key)); @@ -869,7 +780,6 @@ public class JredisConnection implements RedisConnection { } } - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { return jredis.smove(srcKey, destKey, value); @@ -878,7 +788,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] sPop(byte[] key) { try { return jredis.spop(key); @@ -887,7 +796,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] sRandMember(byte[] key) { try { return jredis.srandmember(key); @@ -896,14 +804,12 @@ public class JredisConnection implements RedisConnection { } } - public List sRandMember(byte[] key, long count) { throw new UnsupportedOperationException(); } - public Long sRem(byte[] key, byte[]... values) { - if(values.length > 1) { + if (values.length > 1) { throw new UnsupportedOperationException("sRem of multiple fields not supported"); } try { @@ -913,7 +819,6 @@ public class JredisConnection implements RedisConnection { } } - public Set sUnion(byte[]... keys) { byte[] set1 = keys[0]; byte[][] sets = Arrays.copyOfRange(keys, 1, keys.length); @@ -925,7 +830,6 @@ public class JredisConnection implements RedisConnection { } } - public Long sUnionStore(byte[] destKey, byte[]... keys) { try { jredis.sunionstore(destKey, keys); @@ -935,12 +839,10 @@ public class JredisConnection implements RedisConnection { } } - // // ZSet commands // - public Boolean zAdd(byte[] key, double score, byte[] value) { try { return jredis.zadd(key, score, value); @@ -961,7 +863,6 @@ public class JredisConnection implements RedisConnection { } } - public Long zCount(byte[] key, double min, double max) { try { return jredis.zcount(key, min, max); @@ -970,7 +871,6 @@ public class JredisConnection implements RedisConnection { } } - public Double zIncrBy(byte[] key, double increment, byte[] value) { try { return jredis.zincrby(key, increment, value); @@ -979,17 +879,14 @@ public class JredisConnection implements RedisConnection { } } - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } - public Long zInterStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } - public Set zRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrange(key, start, end)); @@ -998,12 +895,10 @@ public class JredisConnection implements RedisConnection { } } - public Set zRangeWithScores(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } - public Set zRangeByScore(byte[] key, double min, double max) { try { return new LinkedHashSet(jredis.zrangebyscore(key, min, max)); @@ -1012,42 +907,34 @@ public class JredisConnection implements RedisConnection { } } - public Set zRangeByScoreWithScores(byte[] key, double min, double max) { throw new UnsupportedOperationException(); } - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - public Set zRevRangeByScore(byte[] key, double min, double max) { throw new UnsupportedOperationException(); } - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { throw new UnsupportedOperationException(); } - public Long zRank(byte[] key, byte[] value) { try { return jredis.zrank(key, value); @@ -1056,9 +943,8 @@ public class JredisConnection implements RedisConnection { } } - public Long zRem(byte[] key, byte[]... values) { - if(values.length > 1) { + if (values.length > 1) { throw new UnsupportedOperationException("zRem of multiple fields not supported"); } try { @@ -1068,7 +954,6 @@ public class JredisConnection implements RedisConnection { } } - public Long zRemRange(byte[] key, long start, long end) { try { return jredis.zremrangebyrank(key, start, end); @@ -1077,7 +962,6 @@ public class JredisConnection implements RedisConnection { } } - public Long zRemRangeByScore(byte[] key, double min, double max) { try { return jredis.zremrangebyscore(key, min, max); @@ -1086,7 +970,6 @@ public class JredisConnection implements RedisConnection { } } - public Set zRevRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrevrange(key, start, end)); @@ -1095,12 +978,10 @@ public class JredisConnection implements RedisConnection { } } - public Set zRevRangeWithScores(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } - public Long zRevRank(byte[] key, byte[] value) { try { return jredis.zrevrank(key, value); @@ -1109,7 +990,6 @@ public class JredisConnection implements RedisConnection { } } - public Double zScore(byte[] key, byte[] value) { try { return jredis.zscore(key, value); @@ -1118,24 +998,20 @@ public class JredisConnection implements RedisConnection { } } - // // Hash commands // - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } - public Long zUnionStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } - public Long hDel(byte[] key, byte[]... fields) { - if(fields.length > 1) { + if (fields.length > 1) { throw new UnsupportedOperationException("hDel of multiple fields not supported"); } try { @@ -1145,7 +1021,6 @@ public class JredisConnection implements RedisConnection { } } - public Boolean hExists(byte[] key, byte[] field) { try { return jredis.hexists(key, field); @@ -1154,7 +1029,6 @@ public class JredisConnection implements RedisConnection { } } - public byte[] hGet(byte[] key, byte[] field) { try { return jredis.hget(key, field); @@ -1163,7 +1037,6 @@ public class JredisConnection implements RedisConnection { } } - public Map hGetAll(byte[] key) { try { return jredis.hgetall(key); @@ -1172,7 +1045,6 @@ public class JredisConnection implements RedisConnection { } } - public Long hIncrBy(byte[] key, byte[] field, long delta) { throw new UnsupportedOperationException(); } @@ -1189,7 +1061,6 @@ public class JredisConnection implements RedisConnection { } } - public Long hLen(byte[] key) { try { return jredis.hlen(key); @@ -1198,17 +1069,14 @@ public class JredisConnection implements RedisConnection { } } - public List hMGet(byte[] key, byte[]... fields) { throw new UnsupportedOperationException(); } - public void hMSet(byte[] key, Map values) { throw new UnsupportedOperationException(); } - public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { return jredis.hset(key, field, value); @@ -1217,12 +1085,10 @@ public class JredisConnection implements RedisConnection { } } - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { throw new UnsupportedOperationException(); } - public List hVals(byte[] key) { try { return jredis.hvals(key); @@ -1235,31 +1101,25 @@ public class JredisConnection implements RedisConnection { // PubSub commands // - public Subscription getSubscription() { return null; } - public boolean isSubscribed() { return false; } - public void pSubscribe(MessageListener listener, byte[]... patterns) { throw new UnsupportedOperationException(); } - public Long publish(byte[] channel, byte[] message) { throw new UnsupportedOperationException(); } - - // - // Scripting commands - // - + // + // Scripting commands + // public void subscribe(MessageListener listener, byte[]... channels) { throw new UnsupportedOperationException(); @@ -1288,4 +1148,4 @@ public class JredisConnection implements RedisConnection { public T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { throw new UnsupportedOperationException(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnectionFactory.java index 873266c5d..6d339820d 100644 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnectionFactory.java @@ -32,7 +32,7 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * Connection factory using creating JRedis based connections. + * Connection factory using creating JRedis based connections. * * @author Costin Leau * @author Jennifer Hickey @@ -52,23 +52,21 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean private static final int DEFAULT_REDIS_DB = 0; private static final byte[] DEFAULT_REDIS_PASSWORD = null; - /** * Constructs a new JredisConnectionFactory instance. */ - public JredisConnectionFactory() { - } + public JredisConnectionFactory() {} /** - * Constructs a new JredisConnectionFactory instance. - * Will override the other connection parameters passed to the factory. - * + * Constructs a new JredisConnectionFactory instance. Will override the other connection parameters + * passed to the factory. + * * @param connectionSpec already configured connection. */ public JredisConnectionFactory(ConnectionSpec connectionSpec) { this.connectionSpec = connectionSpec; } - + public JredisConnectionFactory(Pool pool) { this.pool = pool; } @@ -88,9 +86,9 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean } } } - + public void destroy() throws Exception { - if(pool != null) { + if (pool != null) { pool.destroy(); pool = null; } @@ -98,18 +96,17 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean public RedisConnection getConnection() { JredisConnection connection; - if(pool != null) { + if (pool != null) { connection = new JredisConnection(pool.getResource(), pool); - }else { + } else { connection = new JredisConnection(new JRedisClient(connectionSpec), null); } return postProcessConnection(connection); } /** - * Post process a newly retrieved connection. Useful for decorating or executing - * initialization commands on a new connection. - * This implementation simply returns the connection. + * Post process a newly retrieved connection. Useful for decorating or executing initialization commands on a new + * connection. This implementation simply returns the connection. * * @param connection * @return processed connection @@ -118,7 +115,6 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean return connection; } - public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof ClientRuntimeException) { return JredisUtils.convertJredisAccessException((ClientRuntimeException) ex); @@ -126,10 +122,9 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean return null; } - /** * Returns the Redis host name of this factory. - * + * * @return Returns the hostName */ public String getHostName() { @@ -145,10 +140,9 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean this.hostName = hostName; } - /** * Returns the Redis port. - * + * * @return Returns the port */ public int getPort() { @@ -184,7 +178,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean /** * Returns the index of the database. - * + * * @return Returns the database index */ public int getDatabase() { @@ -192,8 +186,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean } /** - * Sets the index of the database used by this connection factory. - * Can be between 0 (default) and 15. + * Sets the index of the database used by this connection factory. Can be between 0 (default) and 15. * * @param index database index */ @@ -208,4 +201,4 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean public boolean getConvertPipelineAndTxResults() { return false; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisPool.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisPool.java index faf118a2c..85be77a42 100644 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisPool.java +++ b/src/main/java/org/springframework/data/redis/connection/jredis/JredisPool.java @@ -32,59 +32,44 @@ import org.springframework.util.StringUtils; * JRedis implementation of {@link Pool} * * @author Jennifer Hickey - * */ public class JredisPool implements Pool { private final GenericObjectPool internalPool; /** - * Uses the {@link Config} and {@link ConnectionSpec} defaults for - * configuring the connection pool - * - * @param hostName - * The Redis host - * @param port - * The Redis port + * Uses the {@link Config} and {@link ConnectionSpec} defaults for configuring the connection pool + * + * @param hostName The Redis host + * @param port The Redis port */ public JredisPool(String hostName, int port) { this(hostName, port, 0, null, 0, new Config()); } /** - * Uses the {@link ConnectionSpec} defaults for configuring the connection - * pool + * Uses the {@link ConnectionSpec} defaults for configuring the connection pool * - * @param hostName - * The Redis host - * @param port - * The Redis port - * @param poolConfig - * The pool {@link Config} + * @param hostName The Redis host + * @param port The Redis port + * @param poolConfig The pool {@link Config} */ public JredisPool(String hostName, int port, Config poolConfig) { this(hostName, port, 0, null, 0, poolConfig); } /** - * * Uses the {@link Config} defaults for configuring the connection pool - * - * @param connectionSpec - * The {@link ConnectionSpec} for connecting to Redis - * + * + * @param connectionSpec The {@link ConnectionSpec} for connecting to Redis */ public JredisPool(ConnectionSpec connectionSpec) { this.internalPool = new GenericObjectPool(new JredisFactory(connectionSpec), new Config()); } /** - * - * @param connectionSpec - * The {@link ConnectionSpec} for connecting to Redis - * - * @param poolConfig - * The pool {@link Config} + * @param connectionSpec The {@link ConnectionSpec} for connecting to Redis + * @param poolConfig The pool {@link Config} */ public JredisPool(ConnectionSpec connectionSpec, Config poolConfig) { this.internalPool = new GenericObjectPool(new JredisFactory(connectionSpec), poolConfig); @@ -92,45 +77,28 @@ public class JredisPool implements Pool { /** * Uses the {@link Config} defaults for configuring the connection pool - * - * @param hostName - * The Redis host - * @param port - * The Redis port - * @param dbIndex - * The index of the database all connections should use. The - * database will only be selected on initial creation of the - * pooled {@link JRedis} instances. Since calling select directly - * on {@link JRedis} is not supported, it is assumed that - * connections can be re-used without subsequent selects. - * @param password - * The password used for authenticating with the Redis server or - * null if no password required - * @param timeout - * The socket timeout or 0 to use the default socket timeout + * + * @param hostName The Redis host + * @param port The Redis port + * @param dbIndex The index of the database all connections should use. The database will only be selected on initial + * creation of the pooled {@link JRedis} instances. Since calling select directly on {@link JRedis} is not + * supported, it is assumed that connections can be re-used without subsequent selects. + * @param password The password used for authenticating with the Redis server or null if no password required + * @param timeout The socket timeout or 0 to use the default socket timeout */ public JredisPool(String hostName, int port, int dbIndex, String password, int timeout) { this(hostName, port, dbIndex, password, timeout, new Config()); } /** - * - * @param hostName - * The Redis host - * @param port - * The Redis port - * @param dbIndex - * The index of the database all connections should use - * @param password - * The password used for authenticating with the Redis server or - * null if no password required - * @param timeout - * The socket timeout or 0 to use the default socket timeout - * @param poolConfig - * The pool {@link Config} + * @param hostName The Redis host + * @param port The Redis port + * @param dbIndex The index of the database all connections should use + * @param password The password used for authenticating with the Redis server or null if no password required + * @param timeout The socket timeout or 0 to use the default socket timeout + * @param poolConfig The pool {@link Config} */ - public JredisPool(String hostName, int port, int dbIndex, String password, int timeout, - Config poolConfig) { + public JredisPool(String hostName, int port, int dbIndex, String password, int timeout, Config poolConfig) { ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec(hostName, port, dbIndex, null); connectionSpec.setConnectionFlag(Connection.Flag.RELIABLE, false); if (StringUtils.hasLength(password)) { @@ -191,7 +159,7 @@ public class JredisPool implements Pool { if (obj instanceof JRedis) { try { ((JRedis) obj).quit(); - }catch(Exception e) { + } catch (Exception e) { // Errors may happen if returning a broken resource } } diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisUtils.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisUtils.java index 5424fbb72..42523585b 100644 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/jredis/JredisUtils.java @@ -34,7 +34,7 @@ import org.springframework.data.redis.connection.SortParameters.Order; import org.springframework.data.redis.connection.SortParameters.Range; /** - * Helper class featuring methods for JRedis connection handling, providing support for exception translation. + * Helper class featuring methods for JRedis connection handling, providing support for exception translation. * * @author Costin Leau * @author Jennifer Hickey @@ -66,18 +66,18 @@ public abstract class JredisUtils { static DataType convertDataType(RedisType type) { switch (type) { - case NONE: - return DataType.NONE; - case string: - return DataType.STRING; - case list: - return DataType.LIST; - case set: - return DataType.SET; - //case zset: - // return DataType.ZSET; - case hash: - return DataType.HASH; + case NONE: + return DataType.NONE; + case string: + return DataType.STRING; + case list: + return DataType.LIST; + case set: + return DataType.SET; + // case zset: + // return DataType.ZSET; + case hash: + return DataType.HASH; } return null; @@ -114,7 +114,6 @@ public abstract class JredisUtils { jredisSort.STORE(storeKey); } - return jredisSort; } @@ -127,4 +126,4 @@ public abstract class JredisUtils { static Long toLong(Boolean source) { return source ? 1l : 0l; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClient.java b/src/main/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClient.java index fad5e3139..4ec46c934 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClient.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClient.java @@ -22,11 +22,9 @@ import com.lambdaworks.redis.codec.RedisCodec; import com.lambdaworks.redis.pubsub.RedisPubSubConnection; /** - * Extension of {@link RedisClient} that calls auth on all new connections using - * the supplied credentials + * Extension of {@link RedisClient} that calls auth on all new connections using the supplied credentials * * @author Jennifer Hickey - * */ public class AuthenticatingRedisClient extends RedisClient { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java b/src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java index 34b6f073e..cfd19079d 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePool.java @@ -31,7 +31,6 @@ import com.lambdaworks.redis.RedisClient; * Default implementation of {@link LettucePool} * * @author Jennifer Hickey - * */ public class DefaultLettucePool implements LettucePool, InitializingBean { private GenericObjectPool internalPool; @@ -44,20 +43,15 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { private long timeout = TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS); /** - * Constructs a new DefaultLettucePool instance with - * default settings. + * Constructs a new DefaultLettucePool instance with default settings. */ - public DefaultLettucePool() { - } + public DefaultLettucePool() {} /** - * Uses the {@link Config} and {@link RedisClient} defaults for configuring - * the connection pool + * Uses the {@link Config} and {@link RedisClient} defaults for configuring the connection pool * - * @param hostName - * The Redis host - * @param port - * The Redis port + * @param hostName The Redis host + * @param port The Redis port */ public DefaultLettucePool(String hostName, int port) { this.hostName = hostName; @@ -67,12 +61,9 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Uses the {@link RedisClient} defaults for configuring the connection pool * - * @param hostName - * The Redis host - * @param port - * The Redis port - * @param poolConfig - * The pool {@link Config} + * @param hostName The Redis host + * @param port The Redis port + * @param poolConfig The pool {@link Config} */ public DefaultLettucePool(String hostName, int port, Config poolConfig) { this.hostName = hostName; @@ -81,8 +72,8 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { } public void afterPropertiesSet() { - this.client = password != null ? new AuthenticatingRedisClient(hostName, port, password) : - new RedisClient(hostName, port); + this.client = password != null ? new AuthenticatingRedisClient(hostName, port, password) : new RedisClient( + hostName, port); client.setDefaultTimeout(timeout, TimeUnit.MILLISECONDS); this.internalPool = new GenericObjectPool(new LettuceFactory(client, dbIndex), poolConfig); } @@ -126,7 +117,6 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { } /** - * * @return The pool configuration */ public Config getPoolConfig() { @@ -134,7 +124,6 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { } /** - * * @param poolConfig The pool configuration to use */ public void setPoolConfig(Config poolConfig) { @@ -143,7 +132,7 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Returns the index of the database. - * + * * @return Returns the database index */ public int getDatabase() { @@ -151,11 +140,9 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { } /** - * Sets the index of the database used by this connection pool. Default - * is 0. - * - * @param index - * database index + * Sets the index of the database used by this connection pool. Default is 0. + * + * @param index database index */ public void setDatabase(int index) { Assert.isTrue(index >= 0, "invalid DB index (a positive index required)"); @@ -164,7 +151,7 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Returns the password used for authenticating with the Redis server. - * + * * @return password for authentication */ public String getPassword() { @@ -173,7 +160,7 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Sets the password used for authenticating with the Redis server. - * + * * @param password the password to set */ public void setPassword(String password) { @@ -182,7 +169,7 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Returns the current host. - * + * * @return the host */ public String getHostName() { @@ -191,9 +178,8 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Sets the host. - * - * @param host - * the host to set + * + * @param host the host to set */ public void setHostName(String host) { this.hostName = host; @@ -201,7 +187,7 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Returns the current port. - * + * * @return the port */ public int getPort() { @@ -210,9 +196,8 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Sets the port. - * - * @param port - * the port to set + * + * @param port the port to set */ public void setPort(int port) { this.port = port; @@ -220,7 +205,7 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Returns the connection timeout (in milliseconds). - * + * * @return connection timeout */ public long getTimeout() { @@ -229,9 +214,8 @@ public class DefaultLettucePool implements LettucePool, InitializingBean { /** * Sets the connection timeout (in milliseconds). - * - * @param timeout - * connection timeout + * + * @param timeout connection timeout */ public void setTimeout(long timeout) { this.timeout = timeout; 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 51d86c4e3..dcd0646b6 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 @@ -61,7 +61,7 @@ import com.lambdaworks.redis.pubsub.RedisPubSubConnection; /** * {@code RedisConnection} implementation on top of Lettuce Redis client. - * + * * @author Costin Leau * @author Jennifer Hickey */ @@ -87,22 +87,22 @@ public class LettuceConnection implements RedisConnection { private LettucePool pool; /** flag indicating whether the connection needs to be dropped or not */ private boolean broken = false; - private boolean convertPipelineAndTxResults=true; + private boolean convertPipelineAndTxResults = true; @SuppressWarnings("rawtypes") private class LettuceResult extends FutureResult> { - public LettuceResult(Future resultHolder, Converter converter) { - super((Command)resultHolder, converter); + public LettuceResult(Future resultHolder, Converter converter) { + super((Command) resultHolder, converter); } public LettuceResult(Future resultHolder) { - super((Command)resultHolder); + super((Command) resultHolder); } @SuppressWarnings("unchecked") @Override public Object get() { - if(convertPipelineAndTxResults && converter != null) { + if (convertPipelineAndTxResults && converter != null) { return converter.convert(resultHolder.get()); } return resultHolder.get(); @@ -118,7 +118,7 @@ public class LettuceConnection implements RedisConnection { } private class LettuceTxResult extends FutureResult { - public LettuceTxResult(Object resultHolder, Converter converter) { + public LettuceTxResult(Object resultHolder, Converter converter) { super(resultHolder, converter); } @@ -129,7 +129,7 @@ public class LettuceConnection implements RedisConnection { @SuppressWarnings("unchecked") @Override public Object get() { - if(convertPipelineAndTxResults && converter != null) { + if (convertPipelineAndTxResults && converter != null) { return converter.convert(resultHolder); } return resultHolder; @@ -152,14 +152,14 @@ public class LettuceConnection implements RedisConnection { @Override public List convert(List execResults) { // Lettuce Empty list means null (watched variable modified) - if(execResults.isEmpty()) { + if (execResults.isEmpty()) { return null; } return super.convert(execResults); } } - private class LettuceEvalResultsConverter implements Converter { + private class LettuceEvalResultsConverter implements Converter { private ReturnType returnType; public LettuceEvalResultsConverter(ReturnType returnType) { @@ -168,11 +168,11 @@ public class LettuceConnection implements RedisConnection { @SuppressWarnings({ "rawtypes", "unchecked" }) public T convert(Object source) { - if(returnType == ReturnType.MULTI) { + if (returnType == ReturnType.MULTI) { List resultList = (List) source; - for(Object obj: resultList) { - if(obj instanceof Exception) { - throw convertLettuceAccessException((Exception)obj); + for (Object obj : resultList) { + if (obj instanceof Exception) { + throw convertLettuceAccessException((Exception) obj); } } } @@ -182,12 +182,9 @@ public class LettuceConnection implements RedisConnection { /** * Instantiates a new lettuce connection. - * - * @param timeout - * The connection timeout (in milliseconds) - * @param client - * The {@link RedisClient} to use when instantiating a native - * connection + * + * @param timeout The connection timeout (in milliseconds) + * @param client The {@link RedisClient} to use when instantiating a native connection */ public LettuceConnection(long timeout, RedisClient client) { this(null, timeout, client, null); @@ -195,13 +192,10 @@ public class LettuceConnection implements RedisConnection { /** * Instantiates a new lettuce connection. - * - * @param timeout - * The connection timeout (in milliseconds) * @param client The - * {@link RedisClient} to use when instantiating a pub/sub - * connection - * @param pool - * The connection pool to use for all other native connections + * + * @param timeout The connection timeout (in milliseconds) * @param client The {@link RedisClient} to use when + * instantiating a pub/sub connection + * @param pool The connection pool to use for all other native connections */ public LettuceConnection(long timeout, RedisClient client, LettucePool pool) { this(null, timeout, client, pool); @@ -209,38 +203,28 @@ public class LettuceConnection implements RedisConnection { /** * Instantiates a new lettuce connection. - * - * @param sharedConnection - * A native connection that is shared with other - * {@link LettuceConnection}s. Will not be used for transactions - * or blocking operations - * @param timeout - * The connection timeout (in milliseconds) - * @param client - * The {@link RedisClient} to use when making pub/sub, blocking, - * and tx connections + * + * @param sharedConnection A native connection that is shared with other {@link LettuceConnection}s. Will not be used + * for transactions or blocking operations + * @param timeout The connection timeout (in milliseconds) + * @param client The {@link RedisClient} to use when making pub/sub, blocking, and tx connections */ - public LettuceConnection(com.lambdaworks.redis.RedisAsyncConnection sharedConnection, - long timeout, RedisClient client) { + public LettuceConnection(com.lambdaworks.redis.RedisAsyncConnection sharedConnection, long timeout, + RedisClient client) { this(sharedConnection, timeout, client, null); } /** * Instantiates a new lettuce connection. - * - * @param sharedConnection - * A native connection that is shared with other - * {@link LettuceConnection}s. Should not be used for - * transactions or blocking operations - * @param timeout - * The connection timeout (in milliseconds) - * @param client - * The {@link RedisClient} to use when making pub/sub connections - * @param pool - * The connection pool to use for blocking and tx operations + * + * @param sharedConnection A native connection that is shared with other {@link LettuceConnection}s. Should not be + * used for transactions or blocking operations + * @param timeout The connection timeout (in milliseconds) + * @param client The {@link RedisClient} to use when making pub/sub connections + * @param pool The connection pool to use for blocking and tx operations */ - public LettuceConnection(com.lambdaworks.redis.RedisAsyncConnection sharedConnection, - long timeout, RedisClient client, LettucePool pool) { + public LettuceConnection(com.lambdaworks.redis.RedisAsyncConnection sharedConnection, long timeout, + RedisClient client, LettucePool pool) { this.asyncSharedConn = sharedConnection; this.timeout = timeout; this.sharedConn = sharedConnection != null ? new com.lambdaworks.redis.RedisConnection( @@ -277,10 +261,12 @@ public class LettuceConnection implements RedisConnection { } if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().dispatch(cmd, new ByteArrayOutput(CODEC), cmdArg))); + pipeline(new LettuceResult(getAsyncConnection().dispatch(cmd, new ByteArrayOutput(CODEC), + cmdArg))); return null; - } else if(isQueueing()) { - transaction(new LettuceResult(getAsyncConnection().dispatch(cmd, new ByteArrayOutput(CODEC), cmdArg))); + } else if (isQueueing()) { + transaction(new LettuceResult(getAsyncConnection().dispatch(cmd, new ByteArrayOutput(CODEC), + cmdArg))); return null; } else { return await(getAsyncConnection().dispatch(cmd, new ByteArrayOutput(CODEC), cmdArg)); @@ -293,11 +279,11 @@ public class LettuceConnection implements RedisConnection { public void close() throws DataAccessException { isClosed = true; - if(asyncDedicatedConn != null) { - if(pool != null) { + if (asyncDedicatedConn != null) { + if (pool != null) { if (!broken) { pool.returnResource(asyncDedicatedConn); - }else { + } else { pool.returnBrokenResource(asyncDedicatedConn); } } else { @@ -310,7 +296,7 @@ public class LettuceConnection implements RedisConnection { } if (subscription != null) { - if(subscription.isAlive()) { + if (subscription.isAlive()) { subscription.doClose(); } subscription = null; @@ -325,7 +311,6 @@ public class LettuceConnection implements RedisConnection { return (subscription != null ? subscription.pubsub : getAsyncConnection()); } - public boolean isQueueing() { return isMulti; } @@ -334,7 +319,6 @@ public class LettuceConnection implements RedisConnection { return isPipelined; } - public void openPipeline() { if (!isPipelined) { isPipelined = true; @@ -346,7 +330,7 @@ public class LettuceConnection implements RedisConnection { if (isPipelined) { isPipelined = false; List> futures = new ArrayList>(); - for(LettuceResult result: ppline) { + for (LettuceResult result : ppline) { futures.add(result.getResultHolder()); } boolean done = getAsyncConnection().awaitAll(futures.toArray(new Command[futures.size()])); @@ -355,7 +339,7 @@ public class LettuceConnection implements RedisConnection { Exception problem = null; if (done) { - for (LettuceResult result: ppline) { + for (LettuceResult result : ppline) { if (result.getResultHolder().getOutput().hasError()) { Exception err = new InvalidDataAccessApiUsageException(result.getResultHolder().getOutput().getError()); // remember only the first error @@ -363,11 +347,10 @@ public class LettuceConnection implements RedisConnection { problem = err; } results.add(err); - } - else if(!convertPipelineAndTxResults || !(result.isStatus())) { + } else if (!convertPipelineAndTxResults || !(result.isStatus())) { try { results.add(result.get()); - }catch(DataAccessException e) { + } catch (DataAccessException e) { if (problem == null) { problem = e; } @@ -391,7 +374,6 @@ public class LettuceConnection implements RedisConnection { return Collections.emptyList(); } - public List sort(byte[] key, SortParameters params) { SortArgs args = LettuceConverters.toSortArgs(params); @@ -446,8 +428,6 @@ public class LettuceConnection implements RedisConnection { } } - - public void flushDb() { try { if (isPipelined()) { @@ -464,7 +444,6 @@ public class LettuceConnection implements RedisConnection { } } - public void flushAll() { try { if (isPipelined()) { @@ -481,7 +460,6 @@ public class LettuceConnection implements RedisConnection { } } - public void bgSave() { try { if (isPipelined()) { @@ -498,7 +476,6 @@ public class LettuceConnection implements RedisConnection { } } - public void bgWriteAof() { try { if (isPipelined()) { @@ -515,7 +492,6 @@ public class LettuceConnection implements RedisConnection { } } - public void save() { try { if (isPipelined()) { @@ -532,7 +508,6 @@ public class LettuceConnection implements RedisConnection { } } - public List getConfig(String param) { try { if (isPipelined()) { @@ -549,7 +524,6 @@ public class LettuceConnection implements RedisConnection { } } - public Properties info() { try { if (isPipelined()) { @@ -566,7 +540,6 @@ public class LettuceConnection implements RedisConnection { } } - public Properties info(String section) { try { if (isPipelined()) { @@ -583,7 +556,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long lastSave() { try { if (isPipelined()) { @@ -600,7 +572,6 @@ public class LettuceConnection implements RedisConnection { } } - public void setConfig(String param, String value) { try { if (isPipelined()) { @@ -617,8 +588,6 @@ public class LettuceConnection implements RedisConnection { } } - - public void resetConfigStats() { try { if (isPipelined()) { @@ -635,7 +604,6 @@ public class LettuceConnection implements RedisConnection { } } - public void shutdown() { try { if (isPipelined()) { @@ -648,7 +616,6 @@ public class LettuceConnection implements RedisConnection { } } - public byte[] echo(byte[] message) { try { if (isPipelined()) { @@ -665,7 +632,6 @@ public class LettuceConnection implements RedisConnection { } } - public String ping() { try { if (isPipelined()) { @@ -682,7 +648,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long del(byte[]... keys) { try { if (isPipelined()) { @@ -719,9 +684,8 @@ public class LettuceConnection implements RedisConnection { isMulti = false; try { if (isPipelined()) { - pipeline(new LettuceResult(getAsyncDedicatedConnection().exec(), - new LettuceTransactionResultConverter(new LinkedList>(txResults), - LettuceConverters.exceptionConverter()))); + pipeline(new LettuceResult(getAsyncDedicatedConnection().exec(), new LettuceTransactionResultConverter( + new LinkedList>(txResults), LettuceConverters.exceptionConverter()))); return null; } List results = getDedicatedConnection().exec(); @@ -734,7 +698,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean exists(byte[] key) { try { if (isPipelined()) { @@ -751,7 +714,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean expire(byte[] key, long seconds) { try { if (isPipelined()) { @@ -768,7 +730,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean expireAt(byte[] key, long unixTime) { try { if (isPipelined()) { @@ -881,7 +842,6 @@ public class LettuceConnection implements RedisConnection { } } - public void multi() { if (isQueueing()) { return; @@ -914,7 +874,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean move(byte[] key, int dbIndex) { try { if (isPipelined()) { @@ -931,7 +890,6 @@ public class LettuceConnection implements RedisConnection { } } - public byte[] randomKey() { try { if (isPipelined()) { @@ -964,7 +922,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean renameNX(byte[] oldName, byte[] newName) { try { if (isPipelined()) { @@ -981,17 +938,16 @@ public class LettuceConnection implements RedisConnection { } } - public void select(int dbIndex) { - if(asyncSharedConn != null) { - throw new UnsupportedOperationException("Selecting a new database not supported due to shared connection. " + - "Use separate ConnectionFactorys to work with multiple databases"); + if (asyncSharedConn != null) { + throw new UnsupportedOperationException("Selecting a new database not supported due to shared connection. " + + "Use separate ConnectionFactorys to work with multiple databases"); } if (isPipelined()) { throw new UnsupportedOperationException("Lettuce blocks for #select"); } try { - if(isQueueing()) { + if (isQueueing()) { transaction(new LettuceTxStatusResult(getConnection().select(dbIndex))); return; } @@ -1001,7 +957,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long ttl(byte[] key) { try { if (isPipelined()) { @@ -1051,7 +1006,7 @@ public class LettuceConnection implements RedisConnection { } public void watch(byte[]... keys) { - if(isQueueing()) { + if (isQueueing()) { throw new UnsupportedOperationException(); } try { @@ -1101,8 +1056,6 @@ public class LettuceConnection implements RedisConnection { } } - - public byte[] getSet(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1141,7 +1094,7 @@ public class LettuceConnection implements RedisConnection { pipeline(new LettuceResult(getAsyncConnection().mget(keys))); return null; } - if(isQueueing()) { + if (isQueueing()) { transaction(new LettuceTxResult(getConnection().mget(keys))); return null; } @@ -1151,7 +1104,6 @@ public class LettuceConnection implements RedisConnection { } } - public void mSet(Map tuples) { try { if (isPipelined()) { @@ -1168,14 +1120,13 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean mSetNX(Map tuples) { try { if (isPipelined()) { pipeline(new LettuceResult(getAsyncConnection().msetnx(tuples))); return null; } - if(isQueueing()) { + if (isQueueing()) { transaction(new LettuceTxResult(getConnection().msetnx(tuples))); return null; } @@ -1185,7 +1136,6 @@ public class LettuceConnection implements RedisConnection { } } - public void setEx(byte[] key, long time, byte[] value) { try { if (isPipelined()) { @@ -1202,7 +1152,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean setNX(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1219,7 +1168,6 @@ public class LettuceConnection implements RedisConnection { } } - public byte[] getRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1332,7 +1280,6 @@ public class LettuceConnection implements RedisConnection { } } - public void setBit(byte[] key, long offset, boolean value) { try { if (isPipelined()) { @@ -1349,7 +1296,6 @@ public class LettuceConnection implements RedisConnection { } } - public void setRange(byte[] key, byte[] value, long start) { try { if (isPipelined()) { @@ -1366,7 +1312,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long strLen(byte[] key) { try { if (isPipelined()) { @@ -1383,7 +1328,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long bitCount(byte[] key) { try { if (isPipelined()) { @@ -1400,7 +1344,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long bitCount(byte[] key, long begin, long end) { try { if (isPipelined()) { @@ -1417,7 +1360,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { try { if (isPipelined()) { @@ -1440,7 +1382,6 @@ public class LettuceConnection implements RedisConnection { // List commands // - public Long lPush(byte[] key, byte[]... values) { try { if (isPipelined()) { @@ -1528,13 +1469,11 @@ public class LettuceConnection implements RedisConnection { public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { try { if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().linsert(key, - LettuceConverters.toBoolean(where), pivot, value))); + pipeline(new LettuceResult(getAsyncConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value))); return null; } if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().linsert(key, - LettuceConverters.toBoolean(where), pivot, value))); + transaction(new LettuceTxResult(getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value))); return null; } return getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value); @@ -1591,7 +1530,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long lRem(byte[] key, long count, byte[] value) { try { if (isPipelined()) { @@ -1624,7 +1562,6 @@ public class LettuceConnection implements RedisConnection { } } - public void lTrim(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1641,7 +1578,6 @@ public class LettuceConnection implements RedisConnection { } } - public byte[] rPop(byte[] key) { try { if (isPipelined()) { @@ -1726,7 +1662,6 @@ public class LettuceConnection implements RedisConnection { // Set commands // - public Long sAdd(byte[] key, byte[]... values) { try { if (isPipelined()) { @@ -1743,7 +1678,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long sCard(byte[] key) { try { if (isPipelined()) { @@ -1776,7 +1710,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long sDiffStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1809,7 +1742,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long sInterStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1842,7 +1774,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set sMembers(byte[] key) { try { if (isPipelined()) { @@ -1859,7 +1790,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { if (isPipelined()) { @@ -1876,7 +1806,6 @@ public class LettuceConnection implements RedisConnection { } } - public byte[] sPop(byte[] key) { try { if (isPipelined()) { @@ -1910,16 +1839,18 @@ public class LettuceConnection implements RedisConnection { } public List sRandMember(byte[] key, long count) { - if(count < 0) { + if (count < 0) { throw new UnsupportedOperationException("sRandMember with a negative count is not supported"); } try { if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().srandmember(key, count), LettuceConverters.bytesSetToBytesList())); + pipeline(new LettuceResult(getAsyncConnection().srandmember(key, count), + LettuceConverters.bytesSetToBytesList())); return null; } if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().srandmember(key, count), LettuceConverters.bytesSetToBytesList())); + transaction(new LettuceTxResult(getConnection().srandmember(key, count), + LettuceConverters.bytesSetToBytesList())); return null; } return LettuceConverters.toBytesList(getConnection().srandmember(key, count)); @@ -1960,7 +1891,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long sUnionStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1981,7 +1911,6 @@ public class LettuceConnection implements RedisConnection { // ZSet commands // - public Boolean zAdd(byte[] key, double score, byte[] value) { try { if (isPipelined()) { @@ -1998,17 +1927,14 @@ public class LettuceConnection implements RedisConnection { } } - public Long zAdd(byte[] key, Set tuples) { try { if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().zadd(key, - LettuceConverters.toObjects(tuples).toArray()))); + pipeline(new LettuceResult(getAsyncConnection().zadd(key, LettuceConverters.toObjects(tuples).toArray()))); return null; } if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().zadd(key, - LettuceConverters.toObjects(tuples).toArray()))); + transaction(new LettuceTxResult(getConnection().zadd(key, LettuceConverters.toObjects(tuples).toArray()))); return null; } return getConnection().zadd(key, LettuceConverters.toObjects(tuples).toArray()); @@ -2083,7 +2009,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long zInterStore(byte[] destKey, byte[]... sets) { try { if (isPipelined()) { @@ -2118,7 +2043,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRangeWithScores(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -2137,7 +2061,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRangeByScore(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2156,7 +2079,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRangeByScoreWithScores(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2175,7 +2097,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRevRangeWithScores(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -2194,7 +2115,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isPipelined()) { @@ -2213,7 +2133,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { try { if (isPipelined()) { @@ -2232,7 +2151,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isPipelined()) { @@ -2251,7 +2169,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRevRangeByScore(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2270,7 +2187,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { try { if (isPipelined()) { @@ -2289,7 +2205,6 @@ public class LettuceConnection implements RedisConnection { } } - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -2308,7 +2223,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long zRank(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -2341,7 +2255,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long zRemRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -2392,7 +2305,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long zRevRank(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -2425,7 +2337,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { ZStoreArgs storeArgs = zStoreArgs(aggregate, weights); @@ -2444,7 +2355,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long zUnionStore(byte[] destKey, byte[]... sets) { try { if (isPipelined()) { @@ -2481,7 +2391,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { try { if (isPipelined()) { @@ -2498,7 +2407,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long hDel(byte[] key, byte[]... fields) { try { if (isPipelined()) { @@ -2515,7 +2423,6 @@ public class LettuceConnection implements RedisConnection { } } - public Boolean hExists(byte[] key, byte[] field) { try { if (isPipelined()) { @@ -2532,7 +2439,6 @@ public class LettuceConnection implements RedisConnection { } } - public byte[] hGet(byte[] key, byte[] field) { try { if (isPipelined()) { @@ -2565,7 +2471,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long hIncrBy(byte[] key, byte[] field, long delta) { try { if (isPipelined()) { @@ -2614,7 +2519,6 @@ public class LettuceConnection implements RedisConnection { } } - public Long hLen(byte[] key) { try { if (isPipelined()) { @@ -2647,7 +2551,6 @@ public class LettuceConnection implements RedisConnection { } } - public void hMSet(byte[] key, Map tuple) { try { if (isPipelined()) { @@ -2664,7 +2567,6 @@ public class LettuceConnection implements RedisConnection { } } - public List hVals(byte[] key) { try { if (isPipelined()) { @@ -2681,10 +2583,9 @@ public class LettuceConnection implements RedisConnection { } } - - // - // Scripting commands - // + // + // Scripting commands + // public void scriptFlush() { try { @@ -2703,7 +2604,7 @@ public class LettuceConnection implements RedisConnection { } public void scriptKill() { - if(isQueueing()) { + if (isQueueing()) { throw new UnsupportedOperationException("Script kill not permitted in a transaction"); } try { @@ -2759,13 +2660,13 @@ public class LettuceConnection implements RedisConnection { byte[][] args = extractScriptArgs(numKeys, keysAndArgs); if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), keys, args), - new LettuceEvalResultsConverter(returnType))); + pipeline(new LettuceResult(getAsyncConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), + keys, args), new LettuceEvalResultsConverter(returnType))); return null; } if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), keys, args), - new LettuceEvalResultsConverter(returnType))); + transaction(new LettuceTxResult(getConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), + keys, args), new LettuceEvalResultsConverter(returnType))); return null; } return new LettuceEvalResultsConverter(returnType).convert(getConnection().eval(script, @@ -2781,13 +2682,15 @@ public class LettuceConnection implements RedisConnection { byte[][] args = extractScriptArgs(numKeys, keysAndArgs); if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().evalsha(scriptSha1, LettuceConverters.toScriptOutputType(returnType), - keys, args), new LettuceEvalResultsConverter(returnType))); + pipeline(new LettuceResult(getAsyncConnection().evalsha(scriptSha1, + LettuceConverters.toScriptOutputType(returnType), keys, args), new LettuceEvalResultsConverter( + returnType))); return null; } if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().evalsha(scriptSha1, LettuceConverters.toScriptOutputType(returnType), - keys, args), new LettuceEvalResultsConverter(returnType))); + transaction(new LettuceTxResult(getConnection().evalsha(scriptSha1, + LettuceConverters.toScriptOutputType(returnType), keys, args), new LettuceEvalResultsConverter( + returnType))); return null; } return new LettuceEvalResultsConverter(returnType).convert(getConnection().evalsha(scriptSha1, @@ -2821,12 +2724,10 @@ public class LettuceConnection implements RedisConnection { return subscription; } - public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } - public void pSubscribe(MessageListener listener, byte[]... patterns) { checkSubscription(); @@ -2844,7 +2745,6 @@ public class LettuceConnection implements RedisConnection { } } - public void subscribe(MessageListener listener, byte[]... channels) { checkSubscription(); @@ -2861,10 +2761,9 @@ public class LettuceConnection implements RedisConnection { } /** - * 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 - * + * 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 + * * @param convertPipelineAndTxResults Whether or not to convert pipeline and tx results */ public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) { @@ -2885,9 +2784,9 @@ public class LettuceConnection implements RedisConnection { } private void pipeline(LettuceResult result) { - if(isQueueing()) { + if (isQueueing()) { transaction(result); - }else { + } else { ppline.add(result); } } @@ -2917,8 +2816,8 @@ public class LettuceConnection implements RedisConnection { } private RedisAsyncConnection getAsyncDedicatedConnection() { - if(asyncDedicatedConn == null) { - if(this.pool != null) { + if (asyncDedicatedConn == null) { + if (this.pool != null) { this.asyncDedicatedConn = pool.getResource(); } else { this.asyncDedicatedConn = client.connectAsync(CODEC); @@ -2928,7 +2827,7 @@ public class LettuceConnection implements RedisConnection { } private com.lambdaworks.redis.RedisConnection getDedicatedConnection() { - if(dedicatedConn == null) { + if (dedicatedConn == null) { this.dedicatedConn = new com.lambdaworks.redis.RedisConnection(getAsyncDedicatedConnection()); } return dedicatedConn; @@ -2936,49 +2835,49 @@ public class LettuceConnection implements RedisConnection { private Future asyncBitOp(BitOperation op, byte[] destination, byte[]... keys) { switch (op) { - case AND: - return getAsyncConnection().bitopAnd(destination, keys); - case OR: - return getAsyncConnection().bitopOr(destination, keys); - case XOR: - return getAsyncConnection().bitopXor(destination, keys); - case NOT: - if (keys.length != 1) { - throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); - } - return getAsyncConnection().bitopNot(destination, keys[0]); - default: - throw new UnsupportedOperationException("Bit operation " + op + " is not supported"); + case AND: + return getAsyncConnection().bitopAnd(destination, keys); + case OR: + return getAsyncConnection().bitopOr(destination, keys); + case XOR: + return getAsyncConnection().bitopXor(destination, keys); + case NOT: + if (keys.length != 1) { + throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); + } + return getAsyncConnection().bitopNot(destination, keys[0]); + default: + throw new UnsupportedOperationException("Bit operation " + op + " is not supported"); } } private Long syncBitOp(BitOperation op, byte[] destination, byte[]... keys) { switch (op) { - case AND: - return getConnection().bitopAnd(destination, keys); - case OR: - return getConnection().bitopOr(destination, keys); - case XOR: - return getConnection().bitopXor(destination, keys); - case NOT: - if (keys.length != 1) { - throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); - } - return getConnection().bitopNot(destination, keys[0]); - default: - throw new UnsupportedOperationException("Bit operation " + op + " is not supported"); + case AND: + return getConnection().bitopAnd(destination, keys); + case OR: + return getConnection().bitopOr(destination, keys); + case XOR: + return getConnection().bitopXor(destination, keys); + case NOT: + if (keys.length != 1) { + throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); + } + return getConnection().bitopNot(destination, keys[0]); + default: + throw new UnsupportedOperationException("Bit operation " + op + " is not supported"); } } private byte[][] extractScriptKeys(int numKeys, byte[]... keysAndArgs) { - if(numKeys > 0) { - return Arrays.copyOfRange(keysAndArgs, 0,numKeys); + if (numKeys > 0) { + return Arrays.copyOfRange(keysAndArgs, 0, numKeys); } return new byte[0][0]; } private byte[][] extractScriptArgs(int numKeys, byte[]... keysAndArgs) { - if(keysAndArgs.length > numKeys) { + if (keysAndArgs.length > numKeys) { return Arrays.copyOfRange(keysAndArgs, numKeys, keysAndArgs.length); } return new byte[0][0]; @@ -2988,15 +2887,15 @@ public class LettuceConnection implements RedisConnection { ZStoreArgs args = new ZStoreArgs(); if (aggregate != null) { switch (aggregate) { - case MIN: - args.min(); - break; - case MAX: - args.max(); - break; - default: - args.sum(); - break; + case MIN: + args.min(); + break; + case MAX: + args.max(); + break; + default: + args.sum(); + break; } } long[] lg = new long[weights.length]; @@ -3006,4 +2905,4 @@ public class LettuceConnection implements RedisConnection { args.weights(lg); return args; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java index e0e5be050..566044dbc 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java @@ -34,28 +34,21 @@ import com.lambdaworks.redis.RedisClient; import com.lambdaworks.redis.RedisException; /** - * Connection factory creating Lettuce-based connections. + * Connection factory creating Lettuce-based connections. *

- * This factory creates a new {@link LettuceConnection} on each call to - * {@link #getConnection()}. Multiple {@link LettuceConnection}s share a single - * thread-safe native connection by default. - * + * This factory creates a new {@link LettuceConnection} on each call to {@link #getConnection()}. Multiple + * {@link LettuceConnection}s share a single thread-safe native connection by default. *

- * The shared native connection is never closed by {@link LettuceConnection}, - * therefore it is not validated by default on {@link #getConnection()}. Use - * {@link #setValidateConnection(boolean)} to change this behavior if necessary. - * - * Inject a {@link Pool} to pool dedicated connections. If shareNativeConnection is - * true, the pool will be used to select a connection for blocking and tx operations only, - * which should not share a connection. If native connection sharing is disabled, - * the selected connection will be used for all operations. - * + * The shared native connection is never closed by {@link LettuceConnection}, therefore it is not validated by default + * on {@link #getConnection()}. Use {@link #setValidateConnection(boolean)} to change this behavior if necessary. Inject + * a {@link Pool} to pool dedicated connections. If shareNativeConnection is true, the pool will be used to select a + * connection for blocking and tx operations only, which should not share a connection. If native connection sharing is + * disabled, the selected connection will be used for all operations. + * * @author Costin Leau * @author Jennifer Hickey */ -public class LettuceConnectionFactory implements InitializingBean, DisposableBean, - RedisConnectionFactory { +public class LettuceConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory { private final Log log = LogFactory.getLog(getClass()); @@ -74,15 +67,12 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea private boolean convertPipelineAndTxResults = true; /** - * Constructs a new LettuceConnectionFactory instance with - * default settings. + * Constructs a new LettuceConnectionFactory instance with default settings. */ - public LettuceConnectionFactory() { - } + public LettuceConnectionFactory() {} /** - * Constructs a new LettuceConnectionFactory instance with - * default settings. + * Constructs a new LettuceConnectionFactory instance with default settings. */ public LettuceConnectionFactory(String host, int port) { this.hostName = host; @@ -118,12 +108,11 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea } /** - * Reset the underlying shared Connection, to be reinitialized on next - * access. + * Reset the underlying shared Connection, to be reinitialized on next access. */ public void resetConnection() { synchronized (this.connectionMonitor) { - if(this.connection != null) { + if (this.connection != null) { this.connection.close(); } this.connection = null; @@ -150,7 +139,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Returns the current host. - * + * * @return the host */ public String getHostName() { @@ -159,9 +148,8 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Sets the host. - * - * @param host - * the host to set + * + * @param host the host to set */ public void setHostName(String host) { this.hostName = host; @@ -169,7 +157,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Returns the current port. - * + * * @return the port */ public int getPort() { @@ -178,9 +166,8 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Sets the port. - * - * @param port - * the port to set + * + * @param port the port to set */ public void setPort(int port) { this.port = port; @@ -188,7 +175,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Returns the connection timeout (in milliseconds). - * + * * @return connection timeout */ public long getTimeout() { @@ -197,9 +184,8 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Sets the connection timeout (in milliseconds). - * - * @param timeout - * connection timeout + * + * @param timeout connection timeout */ public void setTimeout(long timeout) { this.timeout = timeout; @@ -207,7 +193,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Indicates if validation of the native Lettuce connection is enabled - * + * * @return connection validation enabled */ public boolean getValidateConnection() { @@ -215,30 +201,25 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea } /** - * Enables validation of the shared native Lettuce connection on calls to - * {@link #getConnection()}. A new connection will be created and used if - * validation fails. + * Enables validation of the shared native Lettuce connection on calls to {@link #getConnection()}. A new connection + * will be created and used if validation fails. *

- * Lettuce will automatically reconnect until close is called, which should - * never happen through {@link LettuceConnection} if a shared native - * connection is used, therefore the default is false. + * Lettuce will automatically reconnect until close is called, which should never happen through + * {@link LettuceConnection} if a shared native connection is used, therefore the default is false. *

- * Setting this to true will result in a round-trip call to the server on - * each new connection, so this setting should only be used if connection - * sharing is enabled and there is code that is actively closing the native - * Lettuce connection. - * - * @param validateConnection - * enable connection validation + * Setting this to true will result in a round-trip call to the server on each new connection, so this setting should + * only be used if connection sharing is enabled and there is code that is actively closing the native Lettuce + * connection. + * + * @param validateConnection enable connection validation */ public void setValidateConnection(boolean validateConnection) { this.validateConnection = validateConnection; } /** - * Indicates if multiple {@link LettuceConnection}s should share a single - * native connection. - * + * Indicates if multiple {@link LettuceConnection}s should share a single native connection. + * * @return native connection shared */ public boolean getShareNativeConnection() { @@ -246,12 +227,10 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea } /** - * Enables multiple {@link LettuceConnection}s to share a single native - * connection. If set to false, every operation on {@link LettuceConnection} - * will open and close a socket. - * - * @param shareNativeConnection - * enable connection sharing + * Enables multiple {@link LettuceConnection}s to share a single native connection. If set to false, every operation + * on {@link LettuceConnection} will open and close a socket. + * + * @param shareNativeConnection enable connection sharing */ public void setShareNativeConnection(boolean shareNativeConnection) { this.shareNativeConnection = shareNativeConnection; @@ -259,7 +238,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Returns the index of the database. - * + * * @return Returns the database index */ public int getDatabase() { @@ -267,11 +246,9 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea } /** - * Sets the index of the database used by this connection factory. Default - * is 0. - * - * @param index - * database index + * Sets the index of the database used by this connection factory. Default is 0. + * + * @param index database index */ public void setDatabase(int index) { Assert.isTrue(index >= 0, "invalid DB index (a positive index required)"); @@ -280,7 +257,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Returns the password used for authenticating with the Redis server. - * + * * @return password for authentication */ public String getPassword() { @@ -289,7 +266,7 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea /** * Sets the password used for authenticating with the Redis server. - * + * * @param password the password to set */ public void setPassword(String password) { @@ -297,10 +274,10 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea } /** - * Specifies if pipelined results should be converted to the expected data - * type. If false, results of {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()} - * will be of the type returned by the Lettuce driver - * + * Specifies if pipelined results should be converted to the expected data type. If false, results of + * {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()} will be of the type returned by the + * Lettuce driver + * * @return Whether or not to convert pipeline and tx results */ public boolean getConvertPipelineAndTxResults() { @@ -308,10 +285,10 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea } /** - * Specifies if pipelined and transaction results should be converted to the expected data - * type. If false, results of {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()} - * will be of the type returned by the Lettuce driver - * + * Specifies if pipelined and transaction results should be converted to the expected data type. If false, results of + * {@link LettuceConnection#closePipeline()} and {LettuceConnection#exec()} will be of the type returned by the + * Lettuce driver + * * @param convertPipelineAndTxResults Whether or not to convert pipeline and tx results */ public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) { @@ -337,23 +314,22 @@ public class LettuceConnectionFactory implements InitializingBean, DisposableBea protected RedisAsyncConnection createLettuceConnector() { try { RedisAsyncConnection connection = client.connectAsync(LettuceConnection.CODEC); - if(dbIndex > 0) { + if (dbIndex > 0) { connection.select(dbIndex); } return connection; } catch (RedisException e) { - throw new RedisConnectionFailureException("Unable to connect to Redis on " + - getHostName() + ":" + getPort(), e); + throw new RedisConnectionFailureException("Unable to connect to Redis on " + getHostName() + ":" + getPort(), e); } } private RedisClient createRedisClient() { - if(pool != null) { + if (pool != null) { return pool.getClient(); } - RedisClient client = password != null ? new AuthenticatingRedisClient(hostName, port, password) : - new RedisClient(hostName, port); + RedisClient client = password != null ? new AuthenticatingRedisClient(hostName, port, password) : new RedisClient( + hostName, port); client.setDefaultTimeout(timeout, TimeUnit.MILLISECONDS); return client; } -} \ No newline at end of file +} 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 fd8402280..46d01c1ab 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 @@ -40,9 +40,8 @@ import com.lambdaworks.redis.protocol.Charsets; /** * Lettuce type converters - * + * * @author Jennifer Hickey - * */ abstract public class LettuceConverters extends Converters { @@ -161,19 +160,18 @@ abstract public class LettuceConverters extends Converters { public static ScriptOutputType toScriptOutputType(ReturnType returnType) { switch (returnType) { - case BOOLEAN: - return ScriptOutputType.BOOLEAN; - case MULTI: - return ScriptOutputType.MULTI; - case VALUE: - return ScriptOutputType.VALUE; - case INTEGER: - return ScriptOutputType.INTEGER; - case STATUS: - return ScriptOutputType.STATUS; - default: - throw new IllegalArgumentException("Return type " + returnType - + " is not a supported script output type"); + case BOOLEAN: + return ScriptOutputType.BOOLEAN; + case MULTI: + return ScriptOutputType.MULTI; + case VALUE: + return ScriptOutputType.VALUE; + case INTEGER: + return ScriptOutputType.INTEGER; + case STATUS: + return ScriptOutputType.STATUS; + default: + throw new IllegalArgumentException("Return type " + returnType + " is not a supported script output type"); } } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceExceptionConverter.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceExceptionConverter.java index 30f6ab5b4..27d2271b3 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceExceptionConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceExceptionConverter.java @@ -29,9 +29,8 @@ import com.lambdaworks.redis.RedisException; /** * Converts Lettuce Exceptions to {@link DataAccessException}s - * + * * @author Jennifer Hickey - * */ public class LettuceExceptionConverter implements Converter { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceMessageListener.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceMessageListener.java index a0de169f0..71767fd4c 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceMessageListener.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceMessageListener.java @@ -44,15 +44,11 @@ class LettuceMessageListener implements RedisPubSubListener { listener.onMessage(new DefaultMessage(channel, message), pattern); } - public void subscribed(byte[] channel, long count) { - } + public void subscribed(byte[] channel, long count) {} - public void psubscribed(byte[] pattern, long count) { - } + public void psubscribed(byte[] pattern, long count) {} - public void unsubscribed(byte[] channel, long count) { - } + public void unsubscribed(byte[] channel, long count) {} - public void punsubscribed(byte[] pattern, long count) { - } + public void punsubscribed(byte[] pattern, long count) {} } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePool.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePool.java index 6f4006322..67f0456b7 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePool.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettucePool.java @@ -22,16 +22,13 @@ import com.lambdaworks.redis.RedisAsyncConnection; import com.lambdaworks.redis.RedisClient; /** - * * Pool of Lettuce {@link RedisAsyncConnection}s - * + * * @author Jennifer Hickey - * */ public interface LettucePool extends Pool> { /** - * * @return The {@link RedisClient} used to create pooled connections */ RedisClient getClient(); diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSubscription.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSubscription.java index 84180b2da..5407d1964 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSubscription.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSubscription.java @@ -40,17 +40,16 @@ class LettuceSubscription extends AbstractSubscription { } protected void doClose() { - if(!getChannels().isEmpty()) { + if (!getChannels().isEmpty()) { pubsub.unsubscribe(new byte[0]); } - if(!getPatterns().isEmpty()) { + if (!getPatterns().isEmpty()) { pubsub.punsubscribe(new byte[0]); } pubsub.removeListener(this.listener); pubsub.close(); } - protected void doPsubscribe(byte[]... patterns) { pubsub.psubscribe(patterns); } @@ -68,4 +67,4 @@ class LettuceSubscription extends AbstractSubscription { // lettuce doesn't automatically subscribe from all patterns pubsub.unsubscribe(channels); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceUtils.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceUtils.java index 31a8adab7..4e0ee11fd 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceUtils.java @@ -46,10 +46,9 @@ import com.lambdaworks.redis.codec.RedisCodec; import com.lambdaworks.redis.protocol.Charsets; /** - * Helper class featuring methods for Lettuce connection handling, providing - * support for exception translation. - * + * Helper class featuring methods for Lettuce connection handling, providing support for exception translation. * Deprecated in favor of {@link LettuceConverters} + * * @author Costin Leau */ @Deprecated @@ -68,7 +67,7 @@ abstract class LettuceUtils { } static Properties info(String reply) { - if(reply == null) { + if (reply == null) { return null; } Properties info = new Properties(); @@ -93,7 +92,7 @@ abstract class LettuceUtils { } static Set convertTuple(List> zrange) { - if(zrange == null) { + if (zrange == null) { return null; } Set tuples = new LinkedHashSet(zrange.size()); @@ -107,7 +106,7 @@ abstract class LettuceUtils { static SortArgs sort(SortParameters params) { SortArgs args = new SortArgs(); - if(params == null) { + if (params == null) { return args; } @@ -129,8 +128,7 @@ abstract class LettuceUtils { if (params.getOrder() != null) { if (params.getOrder() == Order.ASC) { args.asc(); - } - else { + } else { args.desc(); } } @@ -147,15 +145,15 @@ abstract class LettuceUtils { if (aggregate != null) { switch (aggregate) { - case MIN: - args.min(); - break; - case MAX: - args.max(); - break; - default: - args.sum(); - break; + case MIN: + args.min(); + break; + case MAX: + args.max(); + break; + default: + args.sum(); + break; } } @@ -168,7 +166,7 @@ abstract class LettuceUtils { } static List toList(KeyValue blpop) { - if(blpop == null) { + if (blpop == null) { return null; } List list = new ArrayList(2); @@ -179,34 +177,33 @@ abstract class LettuceUtils { static ScriptOutputType toScriptOutputType(ReturnType returnType) { switch (returnType) { - case BOOLEAN: - return ScriptOutputType.BOOLEAN; - case MULTI: - return ScriptOutputType.MULTI; - case VALUE: - return ScriptOutputType.VALUE; - case INTEGER: - return ScriptOutputType.INTEGER; - case STATUS: - return ScriptOutputType.STATUS; - default: - throw new IllegalArgumentException("Return type " + returnType - + " is not a supported script output type"); + case BOOLEAN: + return ScriptOutputType.BOOLEAN; + case MULTI: + return ScriptOutputType.MULTI; + case VALUE: + return ScriptOutputType.VALUE; + case INTEGER: + return ScriptOutputType.INTEGER; + case STATUS: + return ScriptOutputType.STATUS; + default: + throw new IllegalArgumentException("Return type " + returnType + " is not a supported script output type"); } } static byte[][] extractScriptKeys(int numKeys, byte[]... keysAndArgs) { - if(numKeys > 0) { - return Arrays.copyOfRange(keysAndArgs, 0,numKeys); + if (numKeys > 0) { + return Arrays.copyOfRange(keysAndArgs, 0, numKeys); } return new byte[0][0]; } static byte[][] extractScriptArgs(int numKeys, byte[]... keysAndArgs) { - if(keysAndArgs.length > numKeys) { + if (keysAndArgs.length > numKeys) { return Arrays.copyOfRange(keysAndArgs, numKeys, keysAndArgs.length); } return new byte[0][0]; } -} \ No newline at end of file +} 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 2fdc24304..a25bef6eb 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 @@ -54,7 +54,8 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; /** - * {@code RedisConnection} implementation on top of spullara Redis Protocol library. + * {@code RedisConnection} implementation on top of spullara Redis + * Protocol library. * * @author Costin Leau * @author Jennifer Hickey @@ -78,8 +79,7 @@ public class SrpConnection implements RedisConnection { private PipelineTracker callback; private PipelineTracker txTracker; private volatile SrpSubscription subscription; - private boolean convertPipelineAndTxResults=true; - + private boolean convertPipelineAndTxResults = true; @SuppressWarnings("rawtypes") private class PipelineTracker implements FutureCallback { @@ -104,8 +104,8 @@ public class SrpConnection implements RedisConnection { public List complete() { int txResults = 0; List> futures = new ArrayList>(); - for(FutureResult future: futureResults) { - if(future instanceof SrpTxResult) { + for (FutureResult future : futureResults) { + if (future instanceof SrpTxResult) { txResults++; } else { ListenableFuture f = (ListenableFuture) future.getResultHolder(); @@ -117,26 +117,26 @@ public class SrpConnection implements RedisConnection { } catch (Exception ex) { // ignore } - if(futureResults.size() != results.size() + txResults) { - throw new RedisPipelineException("Received a different number of results than expected. Expected: " + - futureResults.size(), results); + if (futureResults.size() != results.size() + txResults) { + throw new RedisPipelineException("Received a different number of results than expected. Expected: " + + futureResults.size(), results); } List convertedResults = new ArrayList(); int i = 0; - for(FutureResult future: futureResults) { - if(future instanceof SrpTxResult) { - PipelineTracker txTracker = ((SrpTxResult)future).getResultHolder(); - if(txTracker != null) { + for (FutureResult future : futureResults) { + if (future instanceof SrpTxResult) { + PipelineTracker txTracker = ((SrpTxResult) future).getResultHolder(); + if (txTracker != null) { convertedResults.add(getPipelinedResults(txTracker, true)); - }else { + } else { convertedResults.add(null); } - }else { + } else { Object result = results.get(i); - if(result instanceof Exception || !convertResults) { + if (result instanceof Exception || !convertResults) { convertedResults.add(result); - }else if(!(future.isStatus())) { + } else if (!(future.isStatus())) { convertedResults.add(future.convert(result)); } i++; @@ -147,8 +147,8 @@ public class SrpConnection implements RedisConnection { public void addCommand(FutureResult result) { futureResults.add(result); - if(!(result instanceof SrpTxResult)) { - Futures.addCallback(((SrpGenericResult)result).getResultHolder(), this); + if (!(result instanceof SrpTxResult)) { + Futures.addCallback(((SrpGenericResult) result).getResultHolder(), this); } } @@ -163,6 +163,7 @@ public class SrpConnection implements RedisConnection { public SrpGenericResult(ListenableFuture resultHolder, Converter converter) { super(resultHolder, converter); } + public SrpGenericResult(ListenableFuture resultHolder) { super(resultHolder); } @@ -175,7 +176,7 @@ public class SrpConnection implements RedisConnection { @SuppressWarnings("rawtypes") private class SrpResult extends SrpGenericResult { - public SrpResult(ListenableFuture> resultHolder, Converter converter) { + public SrpResult(ListenableFuture> resultHolder, Converter converter) { super(resultHolder, converter); } @@ -196,8 +197,9 @@ public class SrpConnection implements RedisConnection { public SrpTxResult(PipelineTracker txTracker) { super(txTracker); } + public List get() { - if(resultHolder == null) { + if (resultHolder == null) { return null; } return resultHolder.complete(); @@ -210,7 +212,7 @@ public class SrpConnection implements RedisConnection { this.queue = queue; } catch (IOException e) { throw new RedisConnectionFailureException("Could not connect", e); - } catch(RedisException e) { + } catch (RedisException e) { throw new RedisConnectionFailureException("Could not connect", e); } } @@ -219,7 +221,7 @@ public class SrpConnection implements RedisConnection { this(host, port, queue); try { this.client.auth(password); - } catch(RedisException e) { + } catch (RedisException e) { throw new RedisConnectionFailureException("Could not connect", e); } } @@ -248,7 +250,7 @@ public class SrpConnection implements RedisConnection { queue.remove(this); if (subscription != null) { - if(subscription.isAlive()) { + if (subscription.isAlive()) { subscription.doClose(); } subscription = null; @@ -269,7 +271,6 @@ public class SrpConnection implements RedisConnection { return client; } - public boolean isQueueing() { return isMulti; } @@ -278,7 +279,6 @@ public class SrpConnection implements RedisConnection { return pipelineRequested || (txTracker != null); } - public void openPipeline() { pipelineRequested = true; initPipeline(); @@ -326,8 +326,6 @@ public class SrpConnection implements RedisConnection { } } - - public void flushDb() { try { if (isPipelined()) { @@ -340,7 +338,6 @@ public class SrpConnection implements RedisConnection { } } - public void flushAll() { try { if (isPipelined()) { @@ -353,7 +350,6 @@ public class SrpConnection implements RedisConnection { } } - public void bgSave() { try { if (isPipelined()) { @@ -366,7 +362,6 @@ public class SrpConnection implements RedisConnection { } } - public void bgWriteAof() { try { if (isPipelined()) { @@ -379,7 +374,6 @@ public class SrpConnection implements RedisConnection { } } - public void save() { try { if (isPipelined()) { @@ -392,7 +386,6 @@ public class SrpConnection implements RedisConnection { } } - public List getConfig(String param) { try { if (isPipelined()) { @@ -405,7 +398,6 @@ public class SrpConnection implements RedisConnection { } } - public Properties info() { try { if (isPipelined()) { @@ -418,7 +410,6 @@ public class SrpConnection implements RedisConnection { } } - public Properties info(String section) { try { if (isPipelined()) { @@ -431,7 +422,6 @@ public class SrpConnection implements RedisConnection { } } - public Long lastSave() { try { if (isPipelined()) { @@ -444,7 +434,6 @@ public class SrpConnection implements RedisConnection { } } - public void setConfig(String param, String value) { try { if (isPipelined()) { @@ -457,8 +446,6 @@ public class SrpConnection implements RedisConnection { } } - - public void resetConfigStats() { try { if (isPipelined()) { @@ -471,7 +458,6 @@ public class SrpConnection implements RedisConnection { } } - public void shutdown() { byte[] save = "SAVE".getBytes(Charsets.UTF_8); try { @@ -485,7 +471,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] echo(byte[] message) { try { if (isPipelined()) { @@ -498,7 +483,6 @@ public class SrpConnection implements RedisConnection { } } - public String ping() { try { if (isPipelined()) { @@ -511,7 +495,6 @@ public class SrpConnection implements RedisConnection { } } - public Long del(byte[]... keys) { try { if (isPipelined()) { @@ -524,7 +507,6 @@ public class SrpConnection implements RedisConnection { } } - public void discard() { isMulti = false; try { @@ -536,21 +518,20 @@ public class SrpConnection implements RedisConnection { } } - public List exec() { isMulti = false; try { Future exec = client.exec(); // Need to wait on execution or subsequent non-pipelined calls may read exec results boolean resultsSet = exec.get(); - if(!resultsSet) { + if (!resultsSet) { // This is the case where a nil MultiBulk Reply was returned b/c watched variable modified - if(pipelineRequested) { + if (pipelineRequested) { pipeline(new SrpTxResult(null)); } return null; } - if(pipelineRequested) { + if (pipelineRequested) { pipeline(new SrpTxResult(txTracker)); return null; } @@ -562,7 +543,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean exists(byte[] key) { try { if (isPipelined()) { @@ -575,7 +555,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean expire(byte[] key, long seconds) { try { if (isPipelined()) { @@ -588,7 +567,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean expireAt(byte[] key, long unixTime) { try { if (isPipelined()) { @@ -637,7 +615,6 @@ public class SrpConnection implements RedisConnection { } } - public void multi() { if (isQueueing()) { return; @@ -651,7 +628,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean persist(byte[] key) { try { if (isPipelined()) { @@ -664,7 +640,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean move(byte[] key, int dbIndex) { try { if (isPipelined()) { @@ -677,7 +652,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] randomKey() { try { if (isPipelined()) { @@ -690,7 +664,6 @@ public class SrpConnection implements RedisConnection { } } - public void rename(byte[] oldName, byte[] newName) { try { if (isPipelined()) { @@ -703,7 +676,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean renameNX(byte[] oldName, byte[] newName) { try { if (isPipelined()) { @@ -716,7 +688,6 @@ public class SrpConnection implements RedisConnection { } } - public void select(int dbIndex) { try { if (isPipelined()) { @@ -729,7 +700,6 @@ public class SrpConnection implements RedisConnection { } } - public Long ttl(byte[] key) { try { if (isPipelined()) { @@ -790,7 +760,6 @@ public class SrpConnection implements RedisConnection { } } - public void unwatch() { try { if (isPipelined()) { @@ -803,7 +772,6 @@ public class SrpConnection implements RedisConnection { } } - public void watch(byte[]... keys) { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -812,8 +780,7 @@ public class SrpConnection implements RedisConnection { if (isPipelined()) { pipeline(new SrpStatusResult(pipeline.watch((Object[]) keys))); return; - } - else { + } else { client.watch((Object[]) keys); } } catch (Exception ex) { @@ -825,7 +792,6 @@ public class SrpConnection implements RedisConnection { // String commands // - public byte[] get(byte[] key) { try { if (isPipelined()) { @@ -839,7 +805,6 @@ public class SrpConnection implements RedisConnection { } } - public void set(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -852,8 +817,6 @@ public class SrpConnection implements RedisConnection { } } - - public byte[] getSet(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -866,7 +829,6 @@ public class SrpConnection implements RedisConnection { } } - public Long append(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -879,7 +841,6 @@ public class SrpConnection implements RedisConnection { } } - public List mGet(byte[]... keys) { try { if (isPipelined()) { @@ -892,7 +853,6 @@ public class SrpConnection implements RedisConnection { } } - public void mSet(Map tuples) { try { if (isPipelined()) { @@ -905,11 +865,11 @@ public class SrpConnection implements RedisConnection { } } - public Boolean mSetNX(Map tuples) { try { if (isPipelined()) { - pipeline(new SrpResult(pipeline.msetnx((Object[]) SrpConverters.toByteArrays(tuples)), SrpConverters.longToBoolean())); + pipeline(new SrpResult(pipeline.msetnx((Object[]) SrpConverters.toByteArrays(tuples)), + SrpConverters.longToBoolean())); return null; } return SrpConverters.toBoolean(client.msetnx((Object[]) SrpConverters.toByteArrays(tuples)).data()); @@ -918,7 +878,6 @@ public class SrpConnection implements RedisConnection { } } - public void setEx(byte[] key, long time, byte[] value) { try { if (isPipelined()) { @@ -931,7 +890,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean setNX(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -944,7 +902,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] getRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -957,7 +914,6 @@ public class SrpConnection implements RedisConnection { } } - public Long decr(byte[] key) { try { if (isPipelined()) { @@ -970,7 +926,6 @@ public class SrpConnection implements RedisConnection { } } - public Long decrBy(byte[] key, long value) { try { if (isPipelined()) { @@ -983,7 +938,6 @@ public class SrpConnection implements RedisConnection { } } - public Long incr(byte[] key) { try { if (isPipelined()) { @@ -996,7 +950,6 @@ public class SrpConnection implements RedisConnection { } } - public Long incrBy(byte[] key, long value) { try { if (isPipelined()) { @@ -1009,7 +962,6 @@ public class SrpConnection implements RedisConnection { } } - public Double incrBy(byte[] key, double value) { try { if (isPipelined()) { @@ -1022,7 +974,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean getBit(byte[] key, long offset) { try { if (isPipelined()) { @@ -1035,7 +986,6 @@ public class SrpConnection implements RedisConnection { } } - public void setBit(byte[] key, long offset, boolean value) { try { if (isPipelined()) { @@ -1048,7 +998,6 @@ public class SrpConnection implements RedisConnection { } } - public void setRange(byte[] key, byte[] value, long start) { try { if (isPipelined()) { @@ -1061,7 +1010,6 @@ public class SrpConnection implements RedisConnection { } } - public Long strLen(byte[] key) { try { if (isPipelined()) { @@ -1074,7 +1022,6 @@ public class SrpConnection implements RedisConnection { } } - public Long bitCount(byte[] key) { try { if (isPipelined()) { @@ -1087,7 +1034,6 @@ public class SrpConnection implements RedisConnection { } } - public Long bitCount(byte[] key, long begin, long end) { try { if (isPipelined()) { @@ -1100,9 +1046,8 @@ public class SrpConnection implements RedisConnection { } } - public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { - if(op == BitOperation.NOT && keys.length > 1) { + if (op == BitOperation.NOT && keys.length > 1) { throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); } try { @@ -1110,7 +1055,7 @@ public class SrpConnection implements RedisConnection { pipeline(new SrpResult(pipeline.bitop(SrpConverters.toBytes(op), destination, (Object[]) keys))); return null; } - return client.bitop(SrpConverters.toBytes(op), destination, (Object[])keys).data(); + return client.bitop(SrpConverters.toBytes(op), destination, (Object[]) keys).data(); } catch (Exception ex) { throw convertSrpAccessException(ex); } @@ -1126,13 +1071,12 @@ public class SrpConnection implements RedisConnection { pipeline(new SrpResult(pipeline.lpush(key, (Object[]) values))); return null; } - return client.lpush(key, (Object[]) values ).data(); + return client.lpush(key, (Object[]) values).data(); } catch (Exception ex) { throw convertSrpAccessException(ex); } } - public Long rPush(byte[] key, byte[]... values) { try { if (isPipelined()) { @@ -1145,7 +1089,6 @@ public class SrpConnection implements RedisConnection { } } - public List bLPop(int timeout, byte[]... keys) { Object[] args = popArgs(timeout, keys); @@ -1160,7 +1103,6 @@ public class SrpConnection implements RedisConnection { } } - public List bRPop(int timeout, byte[]... keys) { Object[] args = popArgs(timeout, keys); try { @@ -1174,7 +1116,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] lIndex(byte[] key, long index) { try { if (isPipelined()) { @@ -1187,7 +1128,6 @@ public class SrpConnection implements RedisConnection { } } - public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { try { if (isPipelined()) { @@ -1200,7 +1140,6 @@ public class SrpConnection implements RedisConnection { } } - public Long lLen(byte[] key) { try { if (isPipelined()) { @@ -1213,7 +1152,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] lPop(byte[] key) { try { if (isPipelined()) { @@ -1226,7 +1164,6 @@ public class SrpConnection implements RedisConnection { } } - public List lRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1239,7 +1176,6 @@ public class SrpConnection implements RedisConnection { } } - public Long lRem(byte[] key, long count, byte[] value) { try { if (isPipelined()) { @@ -1252,7 +1188,6 @@ public class SrpConnection implements RedisConnection { } } - public void lSet(byte[] key, long index, byte[] value) { try { if (isPipelined()) { @@ -1265,7 +1200,6 @@ public class SrpConnection implements RedisConnection { } } - public void lTrim(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1278,7 +1212,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] rPop(byte[] key) { try { if (isPipelined()) { @@ -1291,7 +1224,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { if (isPipelined()) { @@ -1304,7 +1236,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { try { if (isPipelined()) { @@ -1317,7 +1248,6 @@ public class SrpConnection implements RedisConnection { } } - public Long lPushX(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1330,7 +1260,6 @@ public class SrpConnection implements RedisConnection { } } - public Long rPushX(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1343,12 +1272,10 @@ public class SrpConnection implements RedisConnection { } } - // // Set commands // - public Long sAdd(byte[] key, byte[]... values) { try { if (isPipelined()) { @@ -1361,7 +1288,6 @@ public class SrpConnection implements RedisConnection { } } - public Long sCard(byte[] key) { try { if (isPipelined()) { @@ -1374,7 +1300,6 @@ public class SrpConnection implements RedisConnection { } } - public Set sDiff(byte[]... keys) { try { if (isPipelined()) { @@ -1387,7 +1312,6 @@ public class SrpConnection implements RedisConnection { } } - public Long sDiffStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1400,7 +1324,6 @@ public class SrpConnection implements RedisConnection { } } - public Set sInter(byte[]... keys) { try { if (isPipelined()) { @@ -1413,7 +1336,6 @@ public class SrpConnection implements RedisConnection { } } - public Long sInterStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1426,7 +1348,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean sIsMember(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1439,7 +1360,6 @@ public class SrpConnection implements RedisConnection { } } - public Set sMembers(byte[] key) { try { if (isPipelined()) { @@ -1452,7 +1372,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { if (isPipelined()) { @@ -1465,7 +1384,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] sPop(byte[] key) { try { if (isPipelined()) { @@ -1478,14 +1396,13 @@ public class SrpConnection implements RedisConnection { } } - public byte[] sRandMember(byte[] key) { try { if (isPipelined()) { pipeline(new SrpResult(pipeline.srandmember(key, null))); return null; } - return (byte[])client.srandmember(key, null).data(); + return (byte[]) client.srandmember(key, null).data(); } catch (Exception ex) { throw convertSrpAccessException(ex); } @@ -1497,7 +1414,7 @@ public class SrpConnection implements RedisConnection { pipeline(new SrpGenericResult(pipeline.srandmember(key, count), SrpConverters.repliesToBytesList())); return null; } - return SrpConverters.toBytesList(((MultiBulkReply)client.srandmember(key, count)).data()); + return SrpConverters.toBytesList(((MultiBulkReply) client.srandmember(key, count)).data()); } catch (Exception ex) { throw convertSrpAccessException(ex); } @@ -1515,7 +1432,6 @@ public class SrpConnection implements RedisConnection { } } - public Set sUnion(byte[]... keys) { try { if (isPipelined()) { @@ -1528,7 +1444,6 @@ public class SrpConnection implements RedisConnection { } } - public Long sUnionStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { @@ -1545,7 +1460,6 @@ public class SrpConnection implements RedisConnection { // ZSet commands // - public Boolean zAdd(byte[] key, double score, byte[] value) { try { if (isPipelined()) { @@ -1585,7 +1499,6 @@ public class SrpConnection implements RedisConnection { } } - public Long zCount(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -1598,7 +1511,6 @@ public class SrpConnection implements RedisConnection { } } - public Double zIncrBy(byte[] key, double increment, byte[] value) { try { if (isPipelined()) { @@ -1611,12 +1523,10 @@ public class SrpConnection implements RedisConnection { } } - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } - public Long zInterStore(byte[] destKey, byte[]... sets) { try { if (isPipelined()) { @@ -1641,7 +1551,6 @@ public class SrpConnection implements RedisConnection { } } - public Set zRangeWithScores(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1654,11 +1563,11 @@ public class SrpConnection implements RedisConnection { } } - public Set zRangeByScore(byte[] key, double min, double max) { try { if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrangebyscore(key, min, max, null, EMPTY_PARAMS_ARRAY), SrpConverters.repliesToBytesSet())); + pipeline(new SrpResult(pipeline.zrangebyscore(key, min, max, null, EMPTY_PARAMS_ARRAY), + SrpConverters.repliesToBytesSet())); return null; } return SrpConverters.toBytesSet(client.zrangebyscore(key, min, max, null, EMPTY_PARAMS_ARRAY).data()); @@ -1667,11 +1576,11 @@ public class SrpConnection implements RedisConnection { } } - public Set zRangeByScoreWithScores(byte[] key, double min, double max) { try { if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrangebyscore(key, min, max, WITHSCORES, EMPTY_PARAMS_ARRAY), SrpConverters.repliesToTupleSet())); + pipeline(new SrpResult(pipeline.zrangebyscore(key, min, max, WITHSCORES, EMPTY_PARAMS_ARRAY), + SrpConverters.repliesToTupleSet())); return null; } return SrpConverters.toTupleSet(client.zrangebyscore(key, min, max, WITHSCORES, EMPTY_PARAMS_ARRAY).data()); @@ -1680,7 +1589,6 @@ public class SrpConnection implements RedisConnection { } } - public Set zRevRangeWithScores(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1693,7 +1601,6 @@ public class SrpConnection implements RedisConnection { } } - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { try { Object[] limit = limitParams(offset, count); @@ -1707,12 +1614,12 @@ public class SrpConnection implements RedisConnection { } } - public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { try { Object[] limit = limitParams(offset, count); if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrangebyscore(key, min, max, WITHSCORES, limit), SrpConverters.repliesToTupleSet())); + pipeline(new SrpResult(pipeline.zrangebyscore(key, min, max, WITHSCORES, limit), + SrpConverters.repliesToTupleSet())); return null; } return SrpConverters.toTupleSet(client.zrangebyscore(key, min, max, WITHSCORES, limit).data()); @@ -1721,7 +1628,6 @@ public class SrpConnection implements RedisConnection { } } - public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { try { Object[] limit = limitParams(offset, count); @@ -1735,11 +1641,11 @@ public class SrpConnection implements RedisConnection { } } - public Set zRevRangeByScore(byte[] key, double min, double max) { try { if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrevrangebyscore(key, max, min, null, EMPTY_PARAMS_ARRAY), SrpConverters.repliesToBytesSet())); + pipeline(new SrpResult(pipeline.zrevrangebyscore(key, max, min, null, EMPTY_PARAMS_ARRAY), + SrpConverters.repliesToBytesSet())); return null; } return SrpConverters.toBytesSet(client.zrevrangebyscore(key, max, min, null, EMPTY_PARAMS_ARRAY).data()); @@ -1748,12 +1654,12 @@ public class SrpConnection implements RedisConnection { } } - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { try { Object[] limit = limitParams(offset, count); if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrevrangebyscore(key, max, min, WITHSCORES, limit), SrpConverters.repliesToTupleSet())); + pipeline(new SrpResult(pipeline.zrevrangebyscore(key, max, min, WITHSCORES, limit), + SrpConverters.repliesToTupleSet())); return null; } return SrpConverters.toTupleSet(client.zrevrangebyscore(key, max, min, WITHSCORES, limit).data()); @@ -1762,11 +1668,11 @@ public class SrpConnection implements RedisConnection { } } - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { try { if (isPipelined()) { - pipeline(new SrpResult(pipeline.zrevrangebyscore(key, max, min, WITHSCORES, EMPTY_PARAMS_ARRAY), SrpConverters.repliesToTupleSet())); + pipeline(new SrpResult(pipeline.zrevrangebyscore(key, max, min, WITHSCORES, EMPTY_PARAMS_ARRAY), + SrpConverters.repliesToTupleSet())); return null; } return SrpConverters.toTupleSet(client.zrevrangebyscore(key, max, min, WITHSCORES, EMPTY_PARAMS_ARRAY).data()); @@ -1775,7 +1681,6 @@ public class SrpConnection implements RedisConnection { } } - public Long zRank(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1788,7 +1693,6 @@ public class SrpConnection implements RedisConnection { } } - public Long zRem(byte[] key, byte[]... values) { try { if (isPipelined()) { @@ -1801,7 +1705,6 @@ public class SrpConnection implements RedisConnection { } } - public Long zRemRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1814,7 +1717,6 @@ public class SrpConnection implements RedisConnection { } } - public Long zRemRangeByScore(byte[] key, double min, double max) { try { if (isPipelined()) { @@ -1827,7 +1729,6 @@ public class SrpConnection implements RedisConnection { } } - public Set zRevRange(byte[] key, long start, long end) { try { if (isPipelined()) { @@ -1840,7 +1741,6 @@ public class SrpConnection implements RedisConnection { } } - public Long zRevRank(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1853,7 +1753,6 @@ public class SrpConnection implements RedisConnection { } } - public Double zScore(byte[] key, byte[] value) { try { if (isPipelined()) { @@ -1866,12 +1765,10 @@ public class SrpConnection implements RedisConnection { } } - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } - public Long zUnionStore(byte[] destKey, byte[]... sets) { try { if (isPipelined()) { @@ -1888,7 +1785,6 @@ public class SrpConnection implements RedisConnection { // Hash commands // - public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { if (isPipelined()) { @@ -1901,7 +1797,6 @@ public class SrpConnection implements RedisConnection { } } - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { try { if (isPipelined()) { @@ -1914,20 +1809,18 @@ public class SrpConnection implements RedisConnection { } } - public Long hDel(byte[] key, byte[]... fields) { try { if (isPipelined()) { - pipeline(new SrpResult(pipeline.hdel(key, (Object[])fields))); + pipeline(new SrpResult(pipeline.hdel(key, (Object[]) fields))); return null; } - return client.hdel(key, (Object[])fields).data(); + return client.hdel(key, (Object[]) fields).data(); } catch (Exception ex) { throw convertSrpAccessException(ex); } } - public Boolean hExists(byte[] key, byte[] field) { try { if (isPipelined()) { @@ -1940,7 +1833,6 @@ public class SrpConnection implements RedisConnection { } } - public byte[] hGet(byte[] key, byte[] field) { try { if (isPipelined()) { @@ -1953,7 +1845,6 @@ public class SrpConnection implements RedisConnection { } } - public Map hGetAll(byte[] key) { try { if (isPipelined()) { @@ -1966,7 +1857,6 @@ public class SrpConnection implements RedisConnection { } } - public Long hIncrBy(byte[] key, byte[] field, long delta) { try { if (isPipelined()) { @@ -2003,7 +1893,6 @@ public class SrpConnection implements RedisConnection { } } - public Long hLen(byte[] key) { try { if (isPipelined()) { @@ -2016,7 +1905,6 @@ public class SrpConnection implements RedisConnection { } } - public List hMGet(byte[] key, byte[]... fields) { try { if (isPipelined()) { @@ -2029,7 +1917,6 @@ public class SrpConnection implements RedisConnection { } } - public void hMSet(byte[] key, Map tuple) { try { if (isPipelined()) { @@ -2042,7 +1929,6 @@ public class SrpConnection implements RedisConnection { } } - public List hVals(byte[] key) { try { if (isPipelined()) { @@ -2055,10 +1941,9 @@ public class SrpConnection implements RedisConnection { } } - // - // Scripting commands - // - + // + // Scripting commands + // public void scriptFlush() { try { @@ -2073,7 +1958,7 @@ public class SrpConnection implements RedisConnection { } public void scriptKill() { - if(isQueueing()) { + if (isQueueing()) { throw new UnsupportedOperationException("Script kill not permitted in a transaction"); } try { @@ -2093,7 +1978,7 @@ public class SrpConnection implements RedisConnection { pipeline(new SrpGenericResult(pipeline.script_load(script), SrpConverters.bytesToString())); return null; } - return SrpConverters.toString((byte[])client.script_load(script).data()); + return SrpConverters.toString((byte[]) client.script_load(script).data()); } catch (Exception ex) { throw convertSrpAccessException(ex); } @@ -2102,11 +1987,11 @@ public class SrpConnection implements RedisConnection { public List scriptExists(String... scriptSha1) { try { if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.script_exists((Object[])scriptSha1), + pipeline(new SrpGenericResult(pipeline.script_exists((Object[]) scriptSha1), SrpConverters.repliesToBooleanList())); return null; } - return SrpConverters.toBooleanList(((MultiBulkReply)client.script_exists_((Object[])scriptSha1)).data()); + return SrpConverters.toBooleanList(((MultiBulkReply) client.script_exists_((Object[]) scriptSha1)).data()); } catch (Exception ex) { throw convertSrpAccessException(ex); } @@ -2116,12 +2001,12 @@ public class SrpConnection implements RedisConnection { public T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { try { if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.eval(script, numKeys, (Object[])keysAndArgs), + pipeline(new SrpGenericResult(pipeline.eval(script, numKeys, (Object[]) keysAndArgs), new SrpScriptReturnConverter(returnType))); return null; } - return (T) new SrpScriptReturnConverter(returnType).convert(client.eval(script, numKeys, - (Object[])keysAndArgs).data()); + return (T) new SrpScriptReturnConverter(returnType).convert(client.eval(script, numKeys, (Object[]) keysAndArgs) + .data()); } catch (Exception ex) { throw convertSrpAccessException(ex); } @@ -2131,18 +2016,17 @@ public class SrpConnection implements RedisConnection { public T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) { try { if (isPipelined()) { - pipeline(new SrpGenericResult(pipeline.evalsha(scriptSha1, numKeys, (Object[])keysAndArgs), + pipeline(new SrpGenericResult(pipeline.evalsha(scriptSha1, numKeys, (Object[]) keysAndArgs), new SrpScriptReturnConverter(returnType))); return null; } - return (T) new SrpScriptReturnConverter(returnType).convert(client.evalsha(scriptSha1, - numKeys, (Object[])keysAndArgs).data()); + return (T) new SrpScriptReturnConverter(returnType).convert(client.evalsha(scriptSha1, numKeys, + (Object[]) keysAndArgs).data()); } catch (Exception ex) { throw convertSrpAccessException(ex); } } - // // Pub/Sub functionality // @@ -2162,17 +2046,14 @@ public class SrpConnection implements RedisConnection { } } - public Subscription getSubscription() { return subscription; } - public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } - public void pSubscribe(MessageListener listener, byte[]... patterns) { checkSubscription(); @@ -2190,7 +2071,6 @@ public class SrpConnection implements RedisConnection { } } - public void subscribe(MessageListener listener, byte[]... channels) { checkSubscription(); @@ -2207,10 +2087,9 @@ public class SrpConnection implements RedisConnection { } /** - * 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 Lettuce driver - * + * 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 Lettuce driver + * * @param convertPipelineAndTxResults Whether or not to convert pipeline results */ public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) { @@ -2226,9 +2105,9 @@ public class SrpConnection implements RedisConnection { // processing method that adds a listener to the future in order to track down the results and close the pipeline private void pipeline(FutureResult future) { - if(isQueueing()) { + if (isQueueing()) { txTracker.addCommand(future); - }else { + } else { callback.addCommand(future); } } @@ -2241,7 +2120,7 @@ public class SrpConnection implements RedisConnection { } private void initTxTracker() { - if(txTracker == null) { + if (txTracker == null) { txTracker = new PipelineTracker(convertPipelineAndTxResults); } initPipeline(); @@ -2284,9 +2163,9 @@ public class SrpConnection implements RedisConnection { } } if (cause != null) { - if(throwPipelineException) { + if (throwPipelineException) { throw new RedisPipelineException(cause, execute); - }else { + } else { throw convertSrpAccessException(cause); } } @@ -2304,14 +2183,13 @@ public class SrpConnection implements RedisConnection { args[i] = keys[i]; } } - args[length-1] = String.valueOf(timeout).getBytes(); + args[length - 1] = String.valueOf(timeout).getBytes(); return args; } private Object[] limitParams(long offset, long count) { - return new Object[] { "LIMIT".getBytes(Charsets.UTF_8), - String.valueOf(offset).getBytes(Charsets.UTF_8), - String.valueOf(count).getBytes(Charsets.UTF_8)}; + return new Object[] { "LIMIT".getBytes(Charsets.UTF_8), String.valueOf(offset).getBytes(Charsets.UTF_8), + String.valueOf(count).getBytes(Charsets.UTF_8) }; } private byte[] limit(long offset, long count) { @@ -2324,7 +2202,7 @@ public class SrpConnection implements RedisConnection { private Object[] sortParams(SortParameters params, byte[] sortKey) { List arrays = new ArrayList(); - if(params != null) { + if (params != null) { if (params.getByPattern() != null) { arrays.add(BY); arrays.add(params.getByPattern()); @@ -2353,4 +2231,4 @@ public class SrpConnection implements RedisConnection { } return arrays.toArray(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnectionFactory.java index 70cf533a2..efdb17426 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnectionFactory.java @@ -37,26 +37,21 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R private BlockingQueue trackedConnections = new ArrayBlockingQueue(50); private boolean convertPipelineAndTxResults = true; private String password; - /** - * Constructs a new SRedisConnectionFactory instance - * with default settings. + * Constructs a new SRedisConnectionFactory instance with default settings. */ - public SrpConnectionFactory() { - } + public SrpConnectionFactory() {} /** - * Constructs a new SRedisConnectionFactory instance - * with default settings. + * Constructs a new SRedisConnectionFactory instance with default settings. */ public SrpConnectionFactory(String host, int port) { this.hostName = host; this.port = port; } - public void afterPropertiesSet() { - } + public void afterPropertiesSet() {} public void destroy() { SrpConnection con; @@ -73,8 +68,8 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R } public RedisConnection getConnection() { - SrpConnection connection = password != null ? new SrpConnection(hostName, port, password, trackedConnections) : - new SrpConnection(hostName, port, trackedConnections); + SrpConnection connection = password != null ? new SrpConnection(hostName, port, password, trackedConnections) + : new SrpConnection(hostName, port, trackedConnections); connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults); return connection; } @@ -85,7 +80,7 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R /** * Returns the current host. - * + * * @return the host */ public String getHostName() { @@ -94,7 +89,7 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R /** * Sets the host. - * + * * @param host the host to set */ public void setHostName(String host) { @@ -103,7 +98,7 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R /** * Returns the current port. - * + * * @return the port */ public int getPort() { @@ -112,7 +107,7 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R /** * Sets the port. - * + * * @param port the port to set */ public void setPort(int port) { @@ -121,7 +116,7 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R /** * Returns the password used for authenticating with the Redis server. - * + * * @return password for authentication */ public String getPassword() { @@ -130,7 +125,7 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R /** * Sets the password used for authenticating with the Redis server. - * + * * @param password the password to set */ public void setPassword(String password) { @@ -138,10 +133,10 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R } /** - * Specifies if pipelined results should be converted to the expected data - * type. If false, results of {@link SrpConnection#closePipeline()} and {@link SrpConnection#exec()} - * will be of the type returned by the SRP driver - * + * Specifies if pipelined results should be converted to the expected data type. If false, results of + * {@link SrpConnection#closePipeline()} and {@link SrpConnection#exec()} will be of the type returned by the SRP + * driver + * * @return Whether or not to convert pipeline and tx results */ public boolean getConvertPipelineAndTxResults() { @@ -149,13 +144,13 @@ public class SrpConnectionFactory implements InitializingBean, DisposableBean, R } /** - * Specifies if pipelined results should be converted to the expected data - * type. If false, results of {@link SrpConnection#closePipeline()} and {@link SrpConnection#exec()} - * will be of the type returned by the SRP driver - * + * Specifies if pipelined results should be converted to the expected data type. If false, results of + * {@link SrpConnection#closePipeline()} and {@link SrpConnection#exec()} will be of the type returned by the SRP + * driver + * * @param convertPipelineAndTxResults Whether or not to convert pipeline and tx results */ public void setConvertPipelineAndTxResults(boolean convertPipelineAndTxResults) { this.convertPipelineAndTxResults = convertPipelineAndTxResults; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConverters.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConverters.java index fac18b05a..453ac1048 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConverters.java @@ -44,9 +44,8 @@ import com.google.common.base.Charsets; /** * SRP type converters - * + * * @author Jennifer Hickey - * */ @SuppressWarnings("rawtypes") abstract public class SrpConverters extends Converters { @@ -77,8 +76,7 @@ abstract public class SrpConverters extends Converters { } else if (data instanceof byte[]) list.add((byte[]) data); else - throw new IllegalArgumentException( - "array contains more then just nulls and bytes -> " + data); + throw new IllegalArgumentException("array contains more then just nulls and bytes -> " + data); } return list; } @@ -95,13 +93,12 @@ abstract public class SrpConverters extends Converters { }; BYTES_TO_DOUBLE = new Converter() { public Double convert(byte[] bytes) { - return (bytes == null || bytes.length == 0 ? null : Double.valueOf(new String( - bytes, Charsets.UTF_8))); + return (bytes == null || bytes.length == 0 ? null : Double.valueOf(new String(bytes, Charsets.UTF_8))); } }; REPLIES_TO_TUPLE_SET = new Converter>() { public Set convert(Reply[] byteArrays) { - if(byteArrays == null) { + if (byteArrays == null) { return null; } Set tuples = new LinkedHashSet(byteArrays.length / 2 + 1); @@ -116,7 +113,7 @@ abstract public class SrpConverters extends Converters { }; REPLIES_TO_BYTES_MAP = new Converter>() { public Map convert(Reply[] byteArrays) { - if(byteArrays == null) { + if (byteArrays == null) { return null; } Map map = new LinkedHashMap(byteArrays.length / 2); @@ -133,7 +130,7 @@ abstract public class SrpConverters extends Converters { }; REPLIES_TO_BOOLEAN_LIST = new Converter>() { public List convert(Reply[] source) { - if(source == null) { + if (source == null) { return null; } List results = new ArrayList(); @@ -145,7 +142,7 @@ abstract public class SrpConverters extends Converters { }; REPLIES_TO_STRING_LIST = new Converter>() { public List convert(Reply[] source) { - if(source == null) { + if (source == null) { return null; } List results = new ArrayList(); diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java index 761859f7d..687b2d1af 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpMessageListener.java @@ -44,15 +44,11 @@ class SrpMessageListener implements ReplyListener { listener.onMessage(new DefaultMessage(channel, message), pattern); } - public void psubscribed(byte[] arg0, int arg1) { - } + public void psubscribed(byte[] arg0, int arg1) {} - public void punsubscribed(byte[] arg0, int arg1) { - } + public void punsubscribed(byte[] arg0, int arg1) {} - public void subscribed(byte[] arg0, int arg1) { - } + public void subscribed(byte[] arg0, int arg1) {} - public void unsubscribed(byte[] arg0, int arg1) { - } + public void unsubscribed(byte[] arg0, int arg1) {} } diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpScriptReturnConverter.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpScriptReturnConverter.java index 7275be3ad..ca629f861 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpScriptReturnConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpScriptReturnConverter.java @@ -24,11 +24,9 @@ import org.springframework.data.redis.connection.ReturnType; import redis.reply.Reply; /** - * Converts the value returned by SRP script eval to the expected - * {@link ReturnType} - * + * Converts the value returned by SRP script eval to the expected {@link ReturnType} + * * @author Jennifer Hickey - * */ public class SrpScriptReturnConverter implements Converter { diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java index dfdbf4ed2..d804ff052 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpSubscription.java @@ -40,16 +40,15 @@ class SrpSubscription extends AbstractSubscription { } protected void doClose() { - if(!getChannels().isEmpty()) { + if (!getChannels().isEmpty()) { client.unsubscribe((Object[]) null); } - if(!getPatterns().isEmpty()) { + if (!getPatterns().isEmpty()) { client.punsubscribe((Object[]) null); } client.removeListener(this.listener); } - protected void doPsubscribe(byte[]... patterns) { client.psubscribe((Object[]) patterns); } @@ -57,8 +56,7 @@ class SrpSubscription extends AbstractSubscription { protected void doPUnsubscribe(boolean all, byte[]... patterns) { if (all) { client.punsubscribe((Object[]) null); - } - else { + } else { client.punsubscribe((Object[]) patterns); } } @@ -70,9 +68,8 @@ class SrpSubscription extends AbstractSubscription { protected void doUnsubscribe(boolean all, byte[]... channels) { if (all) { client.unsubscribe((Object[]) null); - } - else { + } else { client.unsubscribe((Object[]) channels); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpUtils.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpUtils.java index 1693ab692..4eb609727 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpUtils.java @@ -45,9 +45,8 @@ import java.util.Set; /** * Helper class featuring methods for SRedis connection handling, providing support for exception translation. - * * Deprecated. Use {@link SrpConverters} instead. - * + * * @author Costin Leau * @author Jennifer Hickey */ @@ -65,7 +64,6 @@ abstract class SrpUtils { private static final byte[] ALPHA = "ALPHA".getBytes(Charsets.UTF_8); private static final byte[] STORE = "STORE".getBytes(Charsets.UTF_8); - static DataAccessException convertSRedisAccessException(RuntimeException ex) { if (ex instanceof RedisException) { return new RedisSystemException("redis exception", ex); @@ -89,7 +87,7 @@ abstract class SrpUtils { @SuppressWarnings("rawtypes") static List toBytesList(Reply[] replies) { - if(replies == null) { + if (replies == null) { return null; } List list = new ArrayList(replies.length); @@ -97,8 +95,7 @@ abstract class SrpUtils { Object data = reply.data(); if (data == null) { list.add(null); - } - else if (data instanceof byte[]) + } else if (data instanceof byte[]) list.add((byte[]) data); else throw new IllegalArgumentException("array contains more then just nulls and bytes -> " + data); @@ -109,8 +106,8 @@ abstract class SrpUtils { static List asStatusList(Reply[] replies) { List statuses = new ArrayList(); - for(Reply reply: replies) { - statuses.add(((StatusReply)reply).data()); + for (Reply reply : replies) { + statuses.add(((StatusReply) reply).data()); } return statuses; } @@ -179,7 +176,7 @@ abstract class SrpUtils { args[i] = keys[i]; } } - args[length-1] = String.valueOf(timeout).getBytes(); + args[length - 1] = String.valueOf(timeout).getBytes(); return args; } @@ -204,9 +201,8 @@ abstract class SrpUtils { } static Object[] limitParams(long offset, long count) { - return new Object[] { "LIMIT".getBytes(Charsets.UTF_8), - String.valueOf(offset).getBytes(Charsets.UTF_8), - String.valueOf(count).getBytes(Charsets.UTF_8)}; + return new Object[] { "LIMIT".getBytes(Charsets.UTF_8), String.valueOf(offset).getBytes(Charsets.UTF_8), + String.valueOf(count).getBytes(Charsets.UTF_8) }; } static byte[] sort(SortParameters params) { @@ -217,17 +213,17 @@ abstract class SrpUtils { List arrays = new ArrayList(); Object[] sortParams = sortParams(params, sortKey); - for(Object param: sortParams) { - arrays.add((byte[])param); + for (Object param : sortParams) { + arrays.add((byte[]) param); arrays.add(SPACE); } - arrays.remove(arrays.size()-1); + arrays.remove(arrays.size() - 1); // concatenate array int size = 0; for (Object bs : arrays) { - size += ((byte[])bs).length; + size += ((byte[]) bs).length; } byte[] result = new byte[size]; @@ -247,7 +243,7 @@ abstract class SrpUtils { static Object[] sortParams(SortParameters params, byte[] sortKey) { List arrays = new ArrayList(); - if(params != null) { + if (params != null) { if (params.getByPattern() != null) { arrays.add(BY); arrays.add(params.getByPattern()); @@ -294,20 +290,20 @@ abstract class SrpUtils { } static List asBooleanList(Reply reply) { - if(!(reply instanceof MultiBulkReply)) { + if (!(reply instanceof MultiBulkReply)) { throw new IllegalArgumentException(); } List results = new ArrayList(); - for(Reply r: ((MultiBulkReply)reply).data()) { - results.add(SrpUtils.asBoolean((IntegerReply)r)); + for (Reply r : ((MultiBulkReply) reply).data()) { + results.add(SrpUtils.asBoolean((IntegerReply) r)); } return results; } static List asIntegerList(Reply[] replies) { List results = new ArrayList(); - for(Reply reply: replies) { - results.add(((IntegerReply)reply).data()); + for (Reply reply : replies) { + results.add(((IntegerReply) reply).data()); } return results; } @@ -315,23 +311,23 @@ abstract class SrpUtils { static List asList(MultiBulkReply genericReply) { Reply[] replies = genericReply.data(); List results = new ArrayList(); - for(Reply reply: replies) { + for (Reply reply : replies) { results.add(reply.data()); } return results; } static Object convertScriptReturn(ReturnType returnType, Reply reply) { - if(reply instanceof MultiBulkReply) { - return SrpUtils.asList((MultiBulkReply)reply); + if (reply instanceof MultiBulkReply) { + return SrpUtils.asList((MultiBulkReply) reply); } - if(returnType == ReturnType.BOOLEAN) { + if (returnType == ReturnType.BOOLEAN) { // Lua false comes back as a null bulk reply - if(reply.data() == null) { + if (reply.data() == null) { return Boolean.FALSE; } - return ((Long)reply.data() == 1); + return ((Long) reply.data() == 1); } return reply.data(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/util/AbstractSubscription.java b/src/main/java/org/springframework/data/redis/connection/util/AbstractSubscription.java index 1df7d8594..45169661c 100644 --- a/src/main/java/org/springframework/data/redis/connection/util/AbstractSubscription.java +++ b/src/main/java/org/springframework/data/redis/connection/util/AbstractSubscription.java @@ -26,8 +26,8 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** - * Base implementation for a subscription handling the channel/pattern registration so subclasses only have to deal - * with the actual registration/unregistration. + * Base implementation for a subscription handling the channel/pattern registration so subclasses only have to deal with + * the actual registration/unregistration. * * @author Costin Leau */ @@ -43,10 +43,10 @@ public abstract class AbstractSubscription implements Subscription { } /** - * Constructs a new AbstractSubscription instance. Allows channels and patterns to be added - * to the subscription w/o triggering a subscription action (as some clients (Jedis) require an initial call - * before entering into listening mode). - * + * Constructs a new AbstractSubscription instance. Allows channels and patterns to be added to the + * subscription w/o triggering a subscription action (as some clients (Jedis) require an initial call before entering + * into listening mode). + * * @param listener * @param channels * @param patterns @@ -98,26 +98,22 @@ public abstract class AbstractSubscription implements Subscription { */ protected abstract void doClose(); - public MessageListener getListener() { return listener; } - public Collection getChannels() { synchronized (channels) { return clone(channels); } } - public Collection getPatterns() { synchronized (patterns) { return clone(patterns); } } - public void pSubscribe(byte[]... patterns) { checkPulse(); @@ -130,13 +126,10 @@ public abstract class AbstractSubscription implements Subscription { doPsubscribe(patterns); } - public void pUnsubscribe() { pUnsubscribe((byte[][]) null); } - - public void subscribe(byte[]... channels) { checkPulse(); @@ -149,12 +142,10 @@ public abstract class AbstractSubscription implements Subscription { doSubscribe(channels); } - public void unsubscribe() { unsubscribe((byte[][]) null); } - public void pUnsubscribe(byte[]... patts) { if (!isAlive()) { return; @@ -168,13 +159,11 @@ public abstract class AbstractSubscription implements Subscription { doPUnsubscribe(true, patts); this.patterns.clear(); } - } - else { + } else { // nothing to unsubscribe from return; } - } - else { + } else { doPUnsubscribe(false, patts); synchronized (this.patterns) { remove(this.patterns, patts); @@ -184,7 +173,6 @@ public abstract class AbstractSubscription implements Subscription { closeIfUnsubscribed(); } - public void unsubscribe(byte[]... chans) { if (!isAlive()) { return; @@ -198,13 +186,11 @@ public abstract class AbstractSubscription implements Subscription { doUnsubscribe(true, chans); this.channels.clear(); } - } - else { + } else { // nothing to unsubscribe from return; } - } - else { + } else { doUnsubscribe(false, chans); synchronized (this.channels) { remove(this.channels, chans); @@ -214,7 +200,6 @@ public abstract class AbstractSubscription implements Subscription { closeIfUnsubscribed(); } - public boolean isAlive() { return alive.get(); } @@ -232,7 +217,6 @@ public abstract class AbstractSubscription implements Subscription { } } - private static Collection clone(Collection col) { Collection list = new ArrayList(col.size()); for (ByteArrayWrapper wrapper : col) { @@ -241,7 +225,6 @@ public abstract class AbstractSubscription implements Subscription { return list; } - private static void add(Collection col, byte[]... bytes) { if (!ObjectUtils.isEmpty(bytes)) { for (byte[] bs : bytes) { @@ -257,4 +240,4 @@ public abstract class AbstractSubscription implements Subscription { } } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/util/Base64.java b/src/main/java/org/springframework/data/redis/connection/util/Base64.java index c001e2d91..c37f8b69d 100644 --- a/src/main/java/org/springframework/data/redis/connection/util/Base64.java +++ b/src/main/java/org/springframework/data/redis/connection/util/Base64.java @@ -2,73 +2,55 @@ package org.springframework.data.redis.connection.util; import java.util.Arrays; -/** - * A very fast and memory efficient class to encode and decode to and from BASE64 in full accordance - * with RFC 2045.

- * On Windows XP sp1 with 1.4.2_04 and later ;), this encoder and decoder is about 10 times faster - * on small arrays (10 - 1000 bytes) and 2-3 times as fast on larger arrays (10000 - 1000000 bytes) - * compared to sun.misc.Encoder()/Decoder().

- * - * On byte arrays the encoder is about 20% faster than Jakarta Commons Base64 Codec for encode and - * about 50% faster for decoding large arrays. This implementation is about twice as fast on very small - * arrays (< 30 bytes). If source/destination is a String this - * version is about three times as fast due to the fact that the Commons Codec result has to be recoded - * to a String from byte[], which is very expensive.

- * - * This encode/decode algorithm doesn't create any temporary arrays as many other codecs do, it only - * allocates the resulting array. This produces less garbage and it is possible to handle arrays twice - * as large as algorithms that create a temporary array. (E.g. Jakarta Commons Codec). It is unknown - * whether Sun's sun.misc.Encoder()/Decoder() produce temporary arrays but since performance - * is quite low it probably does.

- * - * The encoder produces the same output as the Sun one except that the Sun's encoder appends - * a trailing line separator if the last character isn't a pad. Unclear why but it only adds to the - * length and is probably a side effect. Both are in conformance with RFC 2045 though.
- * Commons codec seem to always att a trailing line separator.

- * - * Note! - * The encode/decode method pairs (types) come in three versions with the exact same algorithm and - * thus a lot of code redundancy. This is to not create any temporary arrays for transcoding to/from different - * format types. The methods not used can simply be commented out.

- * - * There is also a "fast" version of all decode methods that works the same way as the normal ones, but - * har a few demands on the decoded input. Normally though, these fast verions should be used if the source if - * the input is known and it hasn't bee tampered with.

- * - * If you find the code useful or you find a bug, please send me a note at base64 @ miginfocom . com. - * - * Licence (BSD): - * ============== - * - * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (base64 @ miginfocom . com) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this list - * of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or other - * materials provided with the distribution. - * Neither the name of the MiG InfoCom AB nor the names of its contributors may be - * used to endorse or promote products derived from this software without specific - * prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * +/** + * A very fast and memory efficient class to encode and decode to and from BASE64 in full accordance with RFC 2045.
+ *
+ * On Windows XP sp1 with 1.4.2_04 and later ;), this encoder and decoder is about 10 times faster on small arrays (10 - + * 1000 bytes) and 2-3 times as fast on larger arrays (10000 - 1000000 bytes) compared to + * sun.misc.Encoder()/Decoder().
+ *
+ * On byte arrays the encoder is about 20% faster than Jakarta Commons Base64 Codec for encode and about 50% faster for + * decoding large arrays. This implementation is about twice as fast on very small arrays (< 30 bytes). If + * source/destination is a String this version is about three times as fast due to the fact that the + * Commons Codec result has to be recoded to a String from byte[], which is very expensive.
+ *
+ * This encode/decode algorithm doesn't create any temporary arrays as many other codecs do, it only allocates the + * resulting array. This produces less garbage and it is possible to handle arrays twice as large as algorithms that + * create a temporary array. (E.g. Jakarta Commons Codec). It is unknown whether Sun's + * sun.misc.Encoder()/Decoder() produce temporary arrays but since performance is quite low it probably + * does.
+ *
+ * The encoder produces the same output as the Sun one except that the Sun's encoder appends a trailing line separator + * if the last character isn't a pad. Unclear why but it only adds to the length and is probably a side effect. Both are + * in conformance with RFC 2045 though.
+ * Commons codec seem to always att a trailing line separator.
+ *
+ * Note! The encode/decode method pairs (types) come in three versions with the exact same algorithm and + * thus a lot of code redundancy. This is to not create any temporary arrays for transcoding to/from different format + * types. The methods not used can simply be commented out.
+ *
+ * There is also a "fast" version of all decode methods that works the same way as the normal ones, but har a few + * demands on the decoded input. Normally though, these fast verions should be used if the source if the input is known + * and it hasn't bee tampered with.
+ *
+ * If you find the code useful or you find a bug, please send me a note at base64 @ miginfocom . com. Licence (BSD): + * ============== Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (base64 @ miginfocom . com) All rights reserved. + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the + * distribution. Neither the name of the MiG InfoCom AB nor the names of its contributors may be used to endorse or + * promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY + * THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * * @version 2.2 - * @author Mikael Grev - * Date: 2004-aug-02 - * Time: 11:31:11 + * @author Mikael Grev Date: 2004-aug-02 Time: 11:31:11 */ class Base64 { @@ -82,14 +64,16 @@ class Base64 { } // **************************************************************************************** - // * char[] version + // * char[] version // **************************************************************************************** - /** Encodes a raw byte array into a BASE64 char[] representation i accordance with RFC 2045. + /** + * Encodes a raw byte array into a BASE64 char[] representation i accordance with RFC 2045. + * * @param sArr The bytes to convert. If null or length 0 an empty array will be returned. * @param lineSep Optional "\r\n" after 76 characters, unless end of file.
- * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a - * little faster. + * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a little + * faster. * @return A BASE64 encoded array. Never null. */ public final static char[] encodeToChar(byte[] sArr, boolean lineSep) { @@ -137,11 +121,13 @@ class Base64 { return dArr; } - /** Decodes a BASE64 encoded char array. All illegal characters will be ignored and can handle both arrays with - * and without line separators. + /** + * Decodes a BASE64 encoded char array. All illegal characters will be ignored and can handle both arrays with and + * without line separators. + * * @param sArr The source array. null or length 0 will return an empty array. * @return The decoded array of bytes. May be of length 0. Will be null if the legal characters - * (including '=') isn't divideable by 4. (I.e. definitely corrupted). + * (including '=') isn't divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(char[] sArr) { // Check special case @@ -191,12 +177,14 @@ class Base64 { return dArr; } - /** Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as - * fast as {@link #decode(char[])}. The preconditions are:
+ /** + * Decodes a BASE64 encoded char array that is known to be resonably well formatted. The method is about twice as fast + * as {@link #decode(char[])}. The preconditions are:
* + The array must have a line length of 76 chars OR no line separators at all (one line).
- * + Line separator must be "\r\n", as specified in RFC 2045 - * + The array must not contain illegal characters within the encoded string
+ * + Line separator must be "\r\n", as specified in RFC 2045 + The array must not contain illegal characters within + * the encoded string
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.
+ * * @param sArr The source array. Length 0 will return an empty array. null will throw an exception. * @return The decoded array of bytes. May be of length 0. */ @@ -256,14 +244,16 @@ class Base64 { } // **************************************************************************************** - // * byte[] version + // * byte[] version // **************************************************************************************** - /** Encodes a raw byte array into a BASE64 byte[] representation i accordance with RFC 2045. + /** + * Encodes a raw byte array into a BASE64 byte[] representation i accordance with RFC 2045. + * * @param sArr The bytes to convert. If null or length 0 an empty array will be returned. * @param lineSep Optional "\r\n" after 76 characters, unless end of file.
- * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a - * little faster. + * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a little + * faster. * @return A BASE64 encoded array. Never null. */ public final static byte[] encodeToByte(byte[] sArr, boolean lineSep) { @@ -311,11 +301,13 @@ class Base64 { return dArr; } - /** Decodes a BASE64 encoded byte array. All illegal characters will be ignored and can handle both arrays with - * and without line separators. + /** + * Decodes a BASE64 encoded byte array. All illegal characters will be ignored and can handle both arrays with and + * without line separators. + * * @param sArr The source array. Length 0 will return an empty array. null will throw an exception. * @return The decoded array of bytes. May be of length 0. Will be null if the legal characters - * (including '=') isn't divideable by 4. (I.e. definitely corrupted). + * (including '=') isn't divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(byte[] sArr) { // Check special case @@ -365,13 +357,14 @@ class Base64 { return dArr; } - - /** Decodes a BASE64 encoded byte array that is known to be resonably well formatted. The method is about twice as - * fast as {@link #decode(byte[])}. The preconditions are:
+ /** + * Decodes a BASE64 encoded byte array that is known to be resonably well formatted. The method is about twice as fast + * as {@link #decode(byte[])}. The preconditions are:
* + The array must have a line length of 76 chars OR no line separators at all (one line).
- * + Line separator must be "\r\n", as specified in RFC 2045 - * + The array must not contain illegal characters within the encoded string
+ * + Line separator must be "\r\n", as specified in RFC 2045 + The array must not contain illegal characters within + * the encoded string
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.
+ * * @param sArr The source array. Length 0 will return an empty array. null will throw an exception. * @return The decoded array of bytes. May be of length 0. */ @@ -434,11 +427,13 @@ class Base64 { // * String version // **************************************************************************************** - /** Encodes a raw byte array into a BASE64 String representation i accordance with RFC 2045. + /** + * Encodes a raw byte array into a BASE64 String representation i accordance with RFC 2045. + * * @param sArr The bytes to convert. If null or length 0 an empty array will be returned. * @param lineSep Optional "\r\n" after 76 characters, unless end of file.
- * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a - * little faster. + * No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a little + * faster. * @return A BASE64 encoded array. Never null. */ public final static String encodeToString(byte[] sArr, boolean lineSep) { @@ -446,13 +441,15 @@ class Base64 { return new String(encodeToChar(sArr, lineSep)); } - /** Decodes a BASE64 encoded String. All illegal characters will be ignored and can handle both strings with - * and without line separators.
- * Note! It can be up to about 2x the speed to call decode(str.toCharArray()) instead. That - * will create a temporary array though. This version will use str.charAt(i) to iterate the string. + /** + * Decodes a BASE64 encoded String. All illegal characters will be ignored and can handle both strings + * with and without line separators.
+ * Note! It can be up to about 2x the speed to call decode(str.toCharArray()) instead. That will + * create a temporary array though. This version will use str.charAt(i) to iterate the string. + * * @param str The source string. null or length 0 will return an empty array. * @return The decoded array of bytes. May be of length 0. Will be null if the legal characters - * (including '=') isn't divideable by 4. (I.e. definitely corrupted). + * (including '=') isn't divideable by 4. (I.e. definitely corrupted). */ public final static byte[] decode(String str) { // Check special case @@ -503,12 +500,14 @@ class Base64 { return dArr; } - /** Decodes a BASE64 encoded string that is known to be resonably well formatted. The method is about twice as - * fast as {@link #decode(String)}. The preconditions are:
+ /** + * Decodes a BASE64 encoded string that is known to be resonably well formatted. The method is about twice as fast as + * {@link #decode(String)}. The preconditions are:
* + The array must have a line length of 76 chars OR no line separators at all (one line).
- * + Line separator must be "\r\n", as specified in RFC 2045 - * + The array must not contain illegal characters within the encoded string
+ * + Line separator must be "\r\n", as specified in RFC 2045 + The array must not contain illegal characters within + * the encoded string
* + The array CAN have illegal characters at the beginning and end, those will be dealt with appropriately.
+ * * @param s The source string. Length 0 will return an empty array. null will throw an exception. * @return The decoded array of bytes. May be of length 0. */ @@ -540,8 +539,7 @@ class Base64 { int d = 0; for (int cc = 0, eLen = (len / 3) * 3; d < eLen;) { // Assemble three bytes into an int from four "valid" characters. - int i = IA[s.charAt(sIx++)] << 18 | IA[s.charAt(sIx++)] << 12 | IA[s.charAt(sIx++)] << 6 - | IA[s.charAt(sIx++)]; + int i = IA[s.charAt(sIx++)] << 18 | IA[s.charAt(sIx++)] << 12 | IA[s.charAt(sIx++)] << 6 | IA[s.charAt(sIx++)]; // Add the bytes dArr[d++] = (byte) (i >> 16); @@ -567,4 +565,4 @@ class Base64 { return dArr; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/connection/util/ByteArrayWrapper.java b/src/main/java/org/springframework/data/redis/connection/util/ByteArrayWrapper.java index 3a1d4c985..30695fd7b 100644 --- a/src/main/java/org/springframework/data/redis/connection/util/ByteArrayWrapper.java +++ b/src/main/java/org/springframework/data/redis/connection/util/ByteArrayWrapper.java @@ -19,7 +19,7 @@ import java.util.Arrays; /** * Simple wrapper class used for wrapping arrays so they can be used as keys inside maps. - * + * * @author Costin Leau */ public class ByteArrayWrapper { @@ -32,7 +32,6 @@ public class ByteArrayWrapper { this.hashCode = Arrays.hashCode(array); } - public boolean equals(Object obj) { if (obj instanceof ByteArrayWrapper) { return Arrays.equals(array, ((ByteArrayWrapper) obj).array); @@ -41,14 +40,13 @@ public class ByteArrayWrapper { return false; } - public int hashCode() { return hashCode; } /** * Returns the array. - * + * * @return Returns the array */ public byte[] getArray() { diff --git a/src/main/java/org/springframework/data/redis/connection/util/DecodeUtils.java b/src/main/java/org/springframework/data/redis/connection/util/DecodeUtils.java index aa6acda42..db2914473 100644 --- a/src/main/java/org/springframework/data/redis/connection/util/DecodeUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/util/DecodeUtils.java @@ -79,4 +79,4 @@ public abstract class DecodeUtils { } return set; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/AbstractOperations.java b/src/main/java/org/springframework/data/redis/core/AbstractOperations.java index 62fc03bd5..df4f93e3c 100644 --- a/src/main/java/org/springframework/data/redis/core/AbstractOperations.java +++ b/src/main/java/org/springframework/data/redis/core/AbstractOperations.java @@ -46,7 +46,6 @@ abstract class AbstractOperations { this.key = key; } - public final V doInRedis(RedisConnection connection) { byte[] result = inRedis(rawKey(key), connection); return deserializeValue(result); @@ -81,7 +80,6 @@ abstract class AbstractOperations { return template.getStringSerializer(); } - T execute(RedisCallback callback, boolean b) { return template.execute(callback, b); } @@ -93,8 +91,8 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") byte[] rawKey(Object key) { Assert.notNull(key, "non null key required"); - if(keySerializer() == null && key instanceof byte[]) { - return (byte[])key; + if (keySerializer() == null && key instanceof byte[]) { + return (byte[]) key; } return keySerializer().serialize(key); } @@ -106,8 +104,8 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") byte[] rawValue(Object value) { - if(valueSerializer() == null && value instanceof byte[]) { - return (byte[])value; + if (valueSerializer() == null && value instanceof byte[]) { + return (byte[]) value; } return valueSerializer().serialize(value); } @@ -124,8 +122,8 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") byte[] rawHashKey(HK hashKey) { Assert.notNull(hashKey, "non null hash key required"); - if(hashKeySerializer() == null && hashKey instanceof byte[]) { - return (byte[])hashKey; + if (hashKeySerializer() == null && hashKey instanceof byte[]) { + return (byte[]) hashKey; } return hashKeySerializer().serialize(hashKey); } @@ -141,8 +139,8 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") byte[] rawHashValue(HV value) { - if(hashValueSerializer() == null & value instanceof byte[]) { - return (byte[])value; + if (hashValueSerializer() == null & value instanceof byte[]) { + return (byte[]) value; } return hashValueSerializer().serialize(value); } @@ -150,7 +148,6 @@ abstract class AbstractOperations { byte[][] rawKeys(K key, K otherKey) { final byte[][] rawKeys = new byte[2][]; - rawKeys[0] = rawKey(key); rawKeys[1] = rawKey(key); return rawKeys; @@ -178,21 +175,21 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") Set deserializeValues(Set rawValues) { - if(valueSerializer() == null) { - return (Set)rawValues; + if (valueSerializer() == null) { + return (Set) rawValues; } return SerializationUtils.deserialize(rawValues, valueSerializer()); } @SuppressWarnings({ "unchecked", "rawtypes" }) Set> deserializeTupleValues(Set rawValues) { - if(rawValues == null) { + if (rawValues == null) { return null; } Set> set = new LinkedHashSet>(rawValues.size()); for (Tuple rawValue : rawValues) { Object value = rawValue.getValue(); - if(valueSerializer() != null) { + if (valueSerializer() != null) { value = valueSerializer().deserialize(rawValue.getValue()); } set.add(new DefaultTypedTuple(value, rawValue.getScore())); @@ -202,15 +199,15 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") Set rawTupleValues(Set> values) { - if(values == null) { + if (values == null) { return null; } Set rawTuples = new LinkedHashSet(values.size()); - for(TypedTuple value: values) { + for (TypedTuple value : values) { byte[] rawValue; - if(valueSerializer() == null && value.getValue() instanceof byte[]) { + if (valueSerializer() == null && value.getValue() instanceof byte[]) { rawValue = (byte[]) value.getValue(); - }else { + } else { rawValue = valueSerializer().serialize(value.getValue()); } rawTuples.add(new DefaultTuple(rawValue, value.getScore())); @@ -220,24 +217,24 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") List deserializeValues(List rawValues) { - if(valueSerializer() == null) { - return (List)rawValues; + if (valueSerializer() == null) { + return (List) rawValues; } return SerializationUtils.deserialize(rawValues, valueSerializer()); } @SuppressWarnings("unchecked") Set deserializeHashKeys(Set rawKeys) { - if(hashKeySerializer() == null) { - return (Set)rawKeys; + if (hashKeySerializer() == null) { + return (Set) rawKeys; } return SerializationUtils.deserialize(rawKeys, hashKeySerializer()); } @SuppressWarnings("unchecked") List deserializeHashValues(List rawValues) { - if(hashValueSerializer() == null) { - return (List)rawValues; + if (hashValueSerializer() == null) { + return (List) rawValues; } return SerializationUtils.deserialize(rawValues, hashValueSerializer()); } @@ -260,7 +257,7 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") K deserializeKey(byte[] value) { - if(keySerializer() == null) { + if (keySerializer() == null) { return (K) value; } return (K) keySerializer().deserialize(value); @@ -268,8 +265,8 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") V deserializeValue(byte[] value) { - if(valueSerializer() == null) { - return (V)value; + if (valueSerializer() == null) { + return (V) value; } return (V) valueSerializer().deserialize(value); } @@ -278,19 +275,19 @@ abstract class AbstractOperations { return (String) stringSerializer().deserialize(value); } - @SuppressWarnings( { "unchecked" }) + @SuppressWarnings({ "unchecked" }) HK deserializeHashKey(byte[] value) { - if(hashKeySerializer() == null) { - return (HK)value; + if (hashKeySerializer() == null) { + return (HK) value; } return (HK) hashKeySerializer().deserialize(value); } @SuppressWarnings("unchecked") HV deserializeHashValue(byte[] value) { - if(hashValueSerializer() == null) { - return (HV)value; + if (hashValueSerializer() == null) { + return (HV) value; } return (HV) hashValueSerializer().deserialize(value); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/BoundKeyOperations.java b/src/main/java/org/springframework/data/redis/core/BoundKeyOperations.java index defec7c59..15dfef6b6 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundKeyOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundKeyOperations.java @@ -21,13 +21,12 @@ import java.util.concurrent.TimeUnit; import org.springframework.data.redis.connection.DataType; /** - * Operations over a Redis key. - * - * Useful for executing common key-'bound' operations to all implementations. - * - *

As the rest of the APIs, if the underlying connection is pipelined or queued/in multi mode, - * all methods will return null. + * Operations over a Redis key. Useful for executing common key-'bound' operations to all implementations. + *

+ * As the rest of the APIs, if the underlying connection is pipelined or queued/in multi mode, all methods will return + * null. *

+ * * @author Costin Leau */ public interface BoundKeyOperations { @@ -41,13 +40,13 @@ public interface BoundKeyOperations { /** * Returns the associated Redis type. - * + * * @return key type */ DataType getType(); /** - * Returns the expiration of this key. + * Returns the expiration of this key. * * @return expiration value (in seconds) */ @@ -72,6 +71,7 @@ public interface BoundKeyOperations { /** * Removes the expiration (if any) of the key. + * * @return true if expiration was removed, false otherwise */ Boolean persist(); @@ -82,4 +82,4 @@ public interface BoundKeyOperations { * @param newKey new key */ void rename(K newKey); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/BoundValueOperations.java b/src/main/java/org/springframework/data/redis/core/BoundValueOperations.java index 00707faf0..9d83159ca 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundValueOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundValueOperations.java @@ -18,7 +18,7 @@ package org.springframework.data.redis.core; import java.util.concurrent.TimeUnit; /** - * Value (or String in Redis terminology) operations bound to a certain key. + * Value (or String in Redis terminology) operations bound to a certain key. * * @author Costin Leau */ diff --git a/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java b/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java index b7a4cff0d..24fbe2a2c 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundZSetOperations.java @@ -21,7 +21,6 @@ import java.util.Set; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; - /** * ZSet (or SortedSet) operations bound to a certain key. * diff --git a/src/main/java/org/springframework/data/redis/core/BulkMapper.java b/src/main/java/org/springframework/data/redis/core/BulkMapper.java index 9b19269fd..acf04b6ee 100644 --- a/src/main/java/org/springframework/data/redis/core/BulkMapper.java +++ b/src/main/java/org/springframework/data/redis/core/BulkMapper.java @@ -18,8 +18,8 @@ package org.springframework.data.redis.core; import java.util.List; /** - * Mapper translating Redis bulk value responses (typically returned by a sort query) to actual objects. Implementations of this interface do not have to worry - * about exception or connection handling. + * Mapper translating Redis bulk value responses (typically returned by a sort query) to actual objects. Implementations + * of this interface do not have to worry about exception or connection handling. *

* Typically used by {@link RedisTemplate} sort methods. * diff --git a/src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java b/src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java index af0fd3faf..bd23949bd 100644 --- a/src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java +++ b/src/main/java/org/springframework/data/redis/core/CloseSuppressingInvocationHandler.java @@ -22,10 +22,11 @@ import java.lang.reflect.Method; import org.springframework.data.redis.connection.RedisConnection; /** -* Invocation handler that suppresses close calls on {@link RedisConnection}. -* @see RedisConnection#close() -* @author Costin Leau -*/ + * Invocation handler that suppresses close calls on {@link RedisConnection}. + * + * @see RedisConnection#close() + * @author Costin Leau + */ class CloseSuppressingInvocationHandler implements InvocationHandler { private static final String CLOSE = "close"; @@ -43,12 +44,10 @@ class CloseSuppressingInvocationHandler implements InvocationHandler { if (method.getName().equals(EQUALS)) { // Only consider equal when proxies are identical. return (proxy == args[0]); - } - else if (method.getName().equals(HASH_CODE)) { + } else if (method.getName().equals(HASH_CODE)) { // Use hashCode of PersistenceManager proxy. return System.identityHashCode(proxy); - } - else if (method.getName().equals(CLOSE)) { + } else if (method.getName().equals(CLOSE)) { // Handle close method: suppress, not valid. return null; } @@ -61,4 +60,4 @@ class CloseSuppressingInvocationHandler implements InvocationHandler { throw ex.getTargetException(); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java index 8c7793770..382b46569 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java @@ -27,13 +27,14 @@ import org.springframework.data.redis.connection.DataType; * * @author Costin Leau */ -class DefaultBoundHashOperations extends DefaultBoundKeyOperations implements BoundHashOperations { +class DefaultBoundHashOperations extends DefaultBoundKeyOperations implements + BoundHashOperations { private final HashOperations ops; /** * Constructs a new DefaultBoundHashOperations instance. - * + * * @param key * @param template */ @@ -42,32 +43,26 @@ class DefaultBoundHashOperations extends DefaultBoundKeyOperations this.ops = operations.opsForHash(); } - public void delete(Object... keys) { ops.delete(getKey(), keys); } - public HV get(Object key) { return ops.get(getKey(), key); } - public List multiGet(Collection hashKeys) { return ops.multiGet(getKey(), hashKeys); } - public RedisOperations getOperations() { return ops.getOperations(); } - public Boolean hasKey(Object key) { return ops.hasKey(getKey(), key); } - public Long increment(HK key, long delta) { return ops.increment(getKey(), key, delta); } @@ -80,38 +75,31 @@ class DefaultBoundHashOperations extends DefaultBoundKeyOperations return ops.keys(getKey()); } - public Long size() { return ops.size(getKey()); } - public void putAll(Map m) { ops.putAll(getKey(), m); } - public void put(HK key, HV value) { ops.put(getKey(), key, value); } - public Boolean putIfAbsent(HK key, HV value) { return ops.putIfAbsent(getKey(), key, value); } - public List values() { return ops.values(getKey()); } - public Map entries() { return ops.entries(getKey()); } - public DataType getType() { return DataType.HASH; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundKeyOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundKeyOperations.java index d568712e0..816feebe4 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundKeyOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundKeyOperations.java @@ -18,10 +18,8 @@ package org.springframework.data.redis.core; import java.util.Date; import java.util.concurrent.TimeUnit; - /** - * Default {@link BoundKeyOperations} implementation. - * Meant for internal usage. + * Default {@link BoundKeyOperations} implementation. Meant for internal usage. * * @author Costin Leau */ @@ -35,7 +33,6 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { this.ops = operations; } - public K getKey() { return key; } @@ -44,31 +41,26 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { this.key = key; } - public Boolean expire(long timeout, TimeUnit unit) { return ops.expire(key, timeout, unit); } - public Boolean expireAt(Date date) { return ops.expireAt(key, date); } - public Long getExpire() { return ops.getExpire(key); } - public Boolean persist() { return ops.persist(key); } - public void rename(K newKey) { if (ops.hasKey(key)) { ops.rename(key, newKey); } key = newKey; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundListOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundListOperations.java index 5ddfcd8f5..413b7a936 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundListOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundListOperations.java @@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit; import org.springframework.data.redis.connection.DataType; - /** * Default implementation for {@link BoundListOperations}. * @@ -32,7 +31,7 @@ class DefaultBoundListOperations extends DefaultBoundKeyOperations impl /** * Constructs a new DefaultBoundListOperations instance. - * + * * @param key * @param operations */ @@ -41,28 +40,22 @@ class DefaultBoundListOperations extends DefaultBoundKeyOperations impl this.ops = operations.opsForList(); } - - public RedisOperations getOperations() { return ops.getOperations(); } - public V index(long index) { return ops.index(getKey(), index); } - public V leftPop() { return ops.leftPop(getKey()); } - public V leftPop(long timeout, TimeUnit unit) { return ops.leftPop(getKey(), timeout, unit); } - public Long leftPush(V value) { return ops.leftPush(getKey(), value); } @@ -70,47 +63,39 @@ class DefaultBoundListOperations extends DefaultBoundKeyOperations impl public Long leftPushAll(V... values) { return ops.leftPushAll(getKey(), values); } - + public Long leftPushIfPresent(V value) { return ops.leftPushIfPresent(getKey(), value); } - public Long leftPush(V pivot, V value) { return ops.leftPush(getKey(), pivot, value); } - public Long size() { return ops.size(getKey()); } - public List range(long start, long end) { return ops.range(getKey(), start, end); } - public Long remove(long i, Object value) { return ops.remove(getKey(), i, value); } - public V rightPop() { return ops.rightPop(getKey()); } - public V rightPop(long timeout, TimeUnit unit) { return ops.rightPop(getKey(), timeout, unit); } - public Long rightPushIfPresent(V value) { return ops.rightPushIfPresent(getKey(), value); } - public Long rightPush(V value) { return ops.rightPush(getKey(), value); } @@ -123,18 +108,15 @@ class DefaultBoundListOperations extends DefaultBoundKeyOperations impl return ops.rightPush(getKey(), pivot, value); } - public void trim(long start, long end) { ops.trim(getKey(), start, end); } - public void set(long index, V value) { ops.set(getKey(), index, value); } - public DataType getType() { return DataType.LIST; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundSetOperations.java index 6d522f521..c289d8e3b 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundSetOperations.java @@ -31,10 +31,9 @@ class DefaultBoundSetOperations extends DefaultBoundKeyOperations imple private final SetOperations ops; - /** * Constructs a new DefaultBoundSetOperations instance. - * + * * @param key * @param operations */ @@ -43,125 +42,99 @@ class DefaultBoundSetOperations extends DefaultBoundKeyOperations imple this.ops = operations.opsForSet(); } - public Long add(V... values) { return ops.add(getKey(), values); } - public Set diff(K key) { return ops.difference(getKey(), key); } - public Set diff(Collection keys) { return ops.difference(getKey(), keys); } - - public void diffAndStore(K key, K destKey) { ops.differenceAndStore(getKey(), key, destKey); } - public void diffAndStore(Collection keys, K destKey) { ops.differenceAndStore(getKey(), keys, destKey); } - public RedisOperations getOperations() { return ops.getOperations(); } - public Set intersect(K key) { return ops.intersect(getKey(), key); } - public Set intersect(Collection keys) { return ops.intersect(getKey(), keys); } - public void intersectAndStore(K key, K destKey) { ops.intersectAndStore(getKey(), key, destKey); } - public void intersectAndStore(Collection keys, K destKey) { ops.intersectAndStore(getKey(), keys, destKey); } - public Boolean isMember(Object o) { return ops.isMember(getKey(), o); } - public Set members() { return ops.members(getKey()); } - public Boolean move(K destKey, V value) { return ops.move(getKey(), value, destKey); } - public V randomMember() { return ops.randomMember(getKey()); } - public Set distinctRandomMembers(long count) { return ops.distinctRandomMembers(getKey(), count); } - public List randomMembers(long count) { return ops.randomMembers(getKey(), count); } - public Long remove(Object... values) { return ops.remove(getKey(), values); } - public V pop() { return ops.pop(getKey()); } - public Long size() { return ops.size(getKey()); } - - public Set union(K key) { return ops.union(getKey(), key); } - public Set union(Collection keys) { return ops.union(getKey(), keys); } - public void unionAndStore(K key, K destKey) { ops.unionAndStore(getKey(), key, destKey); } - public void unionAndStore(Collection keys, K destKey) { ops.unionAndStore(getKey(), keys, destKey); } - public DataType getType() { return DataType.SET; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundValueOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundValueOperations.java index 49d8eb4da..8a845c11a 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundValueOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundValueOperations.java @@ -28,7 +28,7 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp /** * Constructs a new DefaultBoundValueOperations instance. - * + * * @param key * @param operations */ @@ -37,17 +37,14 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp this.ops = operations.opsForValue(); } - public V get() { return ops.get(getKey()); } - public V getAndSet(V value) { return ops.getAndSet(getKey(), value); } - public Long increment(long delta) { return ops.increment(getKey(), delta); } @@ -60,43 +57,35 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp return ops.append(getKey(), value); } - public String get(long start, long end) { return ops.get(getKey(), start, end); } - public void set(V value, long timeout, TimeUnit unit) { ops.set(getKey(), value, timeout, unit); } - public void set(V value) { ops.set(getKey(), value); } - public Boolean setIfAbsent(V value) { return ops.setIfAbsent(getKey(), value); } - public void set(V value, long offset) { ops.set(getKey(), value, offset); } - public Long size() { return ops.size(getKey()); } - public RedisOperations getOperations() { return ops.getOperations(); } - public DataType getType() { return DataType.STRING; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java index 001545122..417db58c6 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java @@ -33,7 +33,7 @@ class DefaultBoundZSetOperations extends DefaultBoundKeyOperations impl /** * Constructs a new DefaultBoundZSetOperations instance. - * + * * @param key * @param oeprations */ @@ -42,7 +42,6 @@ class DefaultBoundZSetOperations extends DefaultBoundKeyOperations impl this.ops = operations.opsForZSet(); } - public Boolean add(V value, double score) { return ops.add(getKey(), value, score); } @@ -55,113 +54,91 @@ class DefaultBoundZSetOperations extends DefaultBoundKeyOperations impl return ops.incrementScore(getKey(), value, delta); } - public RedisOperations getOperations() { return ops.getOperations(); } - public void intersectAndStore(K otherKey, K destKey) { ops.intersectAndStore(getKey(), otherKey, destKey); } - public void intersectAndStore(Collection otherKeys, K destKey) { ops.intersectAndStore(getKey(), otherKeys, destKey); } - public Set range(long start, long end) { return ops.range(getKey(), start, end); } - public Set rangeByScore(double min, double max) { return ops.rangeByScore(getKey(), min, max); } - public Set> rangeByScoreWithScores(double min, double max) { return ops.rangeByScoreWithScores(getKey(), min, max); } - public Set> rangeWithScores(long start, long end) { return ops.rangeWithScores(getKey(), start, end); } - public Set reverseRangeByScore(double min, double max) { return ops.reverseRangeByScore(getKey(), min, max); } - public Set> reverseRangeByScoreWithScores(double min, double max) { return ops.reverseRangeByScoreWithScores(getKey(), min, max); } - public Set> reverseRangeWithScores(long start, long end) { return ops.reverseRangeWithScores(getKey(), start, end); } - public Long rank(Object o) { return ops.rank(getKey(), o); } - public Long reverseRank(Object o) { return ops.reverseRank(getKey(), o); } - public Double score(Object o) { return ops.score(getKey(), o); } - public Long remove(Object... values) { return ops.remove(getKey(), values); } - public void removeRange(long start, long end) { ops.removeRange(getKey(), start, end); } - public void removeRangeByScore(double min, double max) { ops.removeRangeByScore(getKey(), min, max); } - public Set reverseRange(long start, long end) { return ops.reverseRange(getKey(), start, end); } - public Long count(double min, double max) { return ops.count(getKey(), min, max); } - public Long size() { return ops.size(getKey()); } - public void unionAndStore(K otherKey, K destKey) { ops.unionAndStore(getKey(), otherKey, destKey); } - public void unionAndStore(Collection otherKeys, K destKey) { ops.unionAndStore(getKey(), otherKeys, destKey); } - public DataType getType() { return DataType.ZSET; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java index 46a85c4b9..bb54463f4 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java @@ -26,7 +26,7 @@ import org.springframework.data.redis.connection.RedisConnection; /** * Default implementation of {@link HashOperations}. - * + * * @author Costin Leau */ class DefaultHashOperations extends AbstractOperations implements HashOperations { @@ -37,13 +37,12 @@ class DefaultHashOperations extends AbstractOperations imp } @SuppressWarnings("unchecked") - public HV get(K key, Object hashKey) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); byte[] rawHashValue = execute(new RedisCallback() { - + public byte[] doInRedis(RedisConnection connection) { return connection.hGet(rawKey, rawHashKey); } @@ -52,26 +51,24 @@ class DefaultHashOperations extends AbstractOperations imp return (HV) deserializeHashValue(rawHashValue); } - public Boolean hasKey(K key, Object hashKey) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); return execute(new RedisCallback() { - + public Boolean doInRedis(RedisConnection connection) { return connection.hExists(rawKey, rawHashKey); } }, true); } - public Long increment(K key, HK hashKey, final long delta) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.hIncrBy(rawKey, rawHashKey, delta); } @@ -94,7 +91,7 @@ class DefaultHashOperations extends AbstractOperations imp final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { - + public Set doInRedis(RedisConnection connection) { return connection.hKeys(rawKey); } @@ -103,19 +100,17 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashKeys(rawValues); } - public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.hLen(rawKey); } }, true); } - public void putAll(K key, Map m) { if (m.isEmpty()) { return; @@ -130,7 +125,7 @@ class DefaultHashOperations extends AbstractOperations imp } execute(new RedisCallback() { - + public Object doInRedis(RedisConnection connection) { connection.hMSet(rawKey, hashes); return null; @@ -138,8 +133,6 @@ class DefaultHashOperations extends AbstractOperations imp }, true); } - - public List multiGet(K key, Collection fields) { if (fields.isEmpty()) { return Collections.emptyList(); @@ -155,7 +148,7 @@ class DefaultHashOperations extends AbstractOperations imp } List rawValues = execute(new RedisCallback>() { - + public List doInRedis(RedisConnection connection) { return connection.hMGet(rawKey, rawHashKeys); } @@ -164,14 +157,13 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashValues(rawValues); } - public void put(K key, HK hashKey, HV value) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); final byte[] rawHashValue = rawHashValue(value); execute(new RedisCallback() { - + public Object doInRedis(RedisConnection connection) { connection.hSet(rawKey, rawHashKey, rawHashValue); return null; @@ -179,27 +171,24 @@ class DefaultHashOperations extends AbstractOperations imp }, true); } - public Boolean putIfAbsent(K key, HK hashKey, HV value) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); final byte[] rawHashValue = rawHashValue(value); return execute(new RedisCallback() { - + public Boolean doInRedis(RedisConnection connection) { return connection.hSetNX(rawKey, rawHashKey, rawHashValue); } }, true); } - - public List values(K key) { final byte[] rawKey = rawKey(key); List rawValues = execute(new RedisCallback>() { - + public List doInRedis(RedisConnection connection) { return connection.hVals(rawKey); } @@ -208,13 +197,12 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashValues(rawValues); } - public void delete(K key, Object... hashKeys) { final byte[] rawKey = rawKey(key); final byte[][] rawHashKeys = rawHashKeys(hashKeys); execute(new RedisCallback() { - + public Object doInRedis(RedisConnection connection) { connection.hDel(rawKey, rawHashKeys); return null; @@ -222,12 +210,11 @@ class DefaultHashOperations extends AbstractOperations imp }, true); } - public Map entries(K key) { final byte[] rawKey = rawKey(key); Map entries = execute(new RedisCallback>() { - + public Map doInRedis(RedisConnection connection) { return connection.hGetAll(rawKey); } @@ -235,4 +222,4 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashMap(entries); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultListOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultListOperations.java index a2e963dd9..81e2fd015 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultListOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultListOperations.java @@ -33,30 +33,28 @@ class DefaultListOperations extends AbstractOperations implements Li super(template); } - public V index(K key, final long index) { return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { return connection.lIndex(rawKey, index); } }, true); } - public V leftPop(K key) { return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { return connection.lPop(rawKey); } }, true); } - + public V leftPop(K key, long timeout, TimeUnit unit) { final int tm = (int) TimeoutUtils.toSeconds(timeout, unit); return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { List lPop = connection.bLPop(tm, rawKey); return (CollectionUtils.isEmpty(lPop) ? null : lPop.get(1)); @@ -64,12 +62,11 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - public Long leftPush(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.lPush(rawKey, rawValue); } @@ -90,38 +87,35 @@ class DefaultListOperations extends AbstractOperations implements Li final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.lPushX(rawKey, rawValue); } }, true); } - public Long leftPush(K key, V pivot, V value) { final byte[] rawKey = rawKey(key); final byte[] rawPivot = rawValue(pivot); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.lInsert(rawKey, Position.BEFORE, rawPivot, rawValue); } }, true); } - public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.lLen(rawKey); } }, true); } - public List range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback>() { @@ -131,34 +125,31 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - public Long remove(K key, final long count, Object value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.lRem(rawKey, count, rawValue); } }, true); } - public V rightPop(K key) { return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { return connection.rPop(rawKey); } }, true); } - public V rightPop(K key, long timeout, TimeUnit unit) { final int tm = (int) TimeoutUtils.toSeconds(timeout, unit); return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { List bRPop = connection.bRPop(tm, rawKey); return (CollectionUtils.isEmpty(bRPop) ? null : bRPop.get(1)); @@ -166,12 +157,11 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - public Long rightPush(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.rPush(rawKey, rawValue); } @@ -192,57 +182,53 @@ class DefaultListOperations extends AbstractOperations implements Li final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.rPushX(rawKey, rawValue); } }, true); } - public Long rightPush(K key, V pivot, V value) { final byte[] rawKey = rawKey(key); final byte[] rawPivot = rawValue(pivot); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.lInsert(rawKey, Position.AFTER, rawPivot, rawValue); } }, true); } - public V rightPopAndLeftPush(K sourceKey, K destinationKey) { final byte[] rawDestKey = rawKey(destinationKey); return execute(new ValueDeserializingRedisCallback(sourceKey) { - + protected byte[] inRedis(byte[] rawSourceKey, RedisConnection connection) { return connection.rPopLPush(rawSourceKey, rawDestKey); } }, true); } - public V rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit) { - final int tm = (int)TimeoutUtils.toSeconds(timeout, unit); + final int tm = (int) TimeoutUtils.toSeconds(timeout, unit); final byte[] rawDestKey = rawKey(destinationKey); return execute(new ValueDeserializingRedisCallback(sourceKey) { - + protected byte[] inRedis(byte[] rawSourceKey, RedisConnection connection) { return connection.bRPopLPush(tm, rawSourceKey, rawDestKey); } }, true); } - public void set(K key, final long index, V value) { final byte[] rawValue = rawValue(value); execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { connection.lSet(rawKey, index, rawValue); return null; @@ -250,14 +236,13 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - public void trim(K key, final long start, final long end) { execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { connection.lTrim(rawKey, start, end); return null; } }, true); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java index 26d3fc74e..03f9355da 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java @@ -25,7 +25,7 @@ import org.springframework.data.redis.connection.RedisConnection; /** * Default implementation of {@link SetOperations}. - * + * * @author Costin Leau */ class DefaultSetOperations extends AbstractOperations implements SetOperations { @@ -34,19 +34,17 @@ class DefaultSetOperations extends AbstractOperations implements Set super(template); } - public Long add(K key, V... values) { final byte[] rawKey = rawKey(key); final byte[][] rawValues = rawValues(values); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.sAdd(rawKey, rawValues); } }, true); } - public Set difference(K key, K otherKey) { return difference(key, Collections.singleton(otherKey)); } @@ -54,7 +52,7 @@ class DefaultSetOperations extends AbstractOperations implements Set public Set difference(final K key, final Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { - + public Set doInRedis(RedisConnection connection) { return connection.sDiff(rawKeys); } @@ -63,24 +61,21 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - public Long differenceAndStore(K key, K otherKey, K destKey) { return differenceAndStore(key, Collections.singleton(otherKey), destKey); } - public Long differenceAndStore(final K key, final Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.sDiffStore(rawDestKey, rawKeys); } }, true); } - public Set intersect(K key, K otherKey) { return intersect(key, Collections.singleton(otherKey)); } @@ -88,7 +83,7 @@ class DefaultSetOperations extends AbstractOperations implements Set public Set intersect(K key, Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { - + public Set doInRedis(RedisConnection connection) { return connection.sInter(rawKeys); } @@ -97,17 +92,15 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - public Long intersectAndStore(K key, K otherKey, K destKey) { return intersectAndStore(key, Collections.singleton(otherKey), destKey); } - public Long intersectAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { connection.sInterStore(rawDestKey, rawKeys); return null; @@ -115,12 +108,11 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } - public Boolean isMember(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { - + public Boolean doInRedis(RedisConnection connection) { return connection.sIsMember(rawKey, rawValue); } @@ -130,7 +122,7 @@ class DefaultSetOperations extends AbstractOperations implements Set public Set members(K key) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { - + public Set doInRedis(RedisConnection connection) { return connection.sMembers(rawKey); } @@ -139,36 +131,33 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - public Boolean move(K key, V value, K destKey) { final byte[] rawKey = rawKey(key); final byte[] rawDestKey = rawKey(destKey); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Boolean doInRedis(RedisConnection connection) { return connection.sMove(rawKey, rawDestKey, rawValue); } }, true); } - public V randomMember(K key) { return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { return connection.sRandMember(rawKey); } }, true); } - public Set distinctRandomMembers(K key, final long count) { - if(count < 0) { - throw new IllegalArgumentException("Negative count not supported. " + - "Use randomMembers to allow duplicate elements."); + if (count < 0) { + throw new IllegalArgumentException("Negative count not supported. " + + "Use randomMembers to allow duplicate elements."); } final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { @@ -179,57 +168,52 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - public List randomMembers(K key, final long count) { - if(count < 0) { - throw new IllegalArgumentException("Use a positive number for count. " + - "This method is already allowing duplicate elements."); + if (count < 0) { + throw new IllegalArgumentException("Use a positive number for count. " + + "This method is already allowing duplicate elements."); } final byte[] rawKey = rawKey(key); List rawValues = execute(new RedisCallback>() { public List doInRedis(RedisConnection connection) { - return connection.sRandMember(rawKey, - count); + return connection.sRandMember(rawKey, -count); } }, true); return deserializeValues(rawValues); } - public Long remove(K key, Object... values) { final byte[] rawKey = rawKey(key); final byte[][] rawValues = rawValues(values); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.sRem(rawKey, rawValues); } }, true); } - public V pop(K key) { return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { return connection.sPop(rawKey); } }, true); } - public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.sCard(rawKey); } }, true); } - public Set union(K key, K otherKey) { return union(key, Collections.singleton(otherKey)); } @@ -237,7 +221,7 @@ class DefaultSetOperations extends AbstractOperations implements Set public Set union(K key, Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { - + public Set doInRedis(RedisConnection connection) { return connection.sUnion(rawKeys); } @@ -246,20 +230,18 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - public Long unionAndStore(K key, K otherKey, K destKey) { return unionAndStore(key, Collections.singleton(otherKey), destKey); } - public Long unionAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.sUnionStore(rawDestKey, rawKeys); } }, true); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultTypedTuple.java b/src/main/java/org/springframework/data/redis/core/DefaultTypedTuple.java index 88659a2fa..ce1690eca 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultTypedTuple.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultTypedTuple.java @@ -31,7 +31,7 @@ public class DefaultTypedTuple implements TypedTuple { /** * Constructs a new DefaultTypedTuple instance. - * + * * @param value * @param score */ @@ -40,17 +40,14 @@ public class DefaultTypedTuple implements TypedTuple { this.value = value; } - public Double getScore() { return score; } - public V getValue() { return value; } - public int hashCode() { final int prime = 31; int result = 1; @@ -59,7 +56,6 @@ public class DefaultTypedTuple implements TypedTuple { return result; } - public boolean equals(Object obj) { if (this == obj) return true; @@ -71,27 +67,24 @@ public class DefaultTypedTuple implements TypedTuple { if (score == null) { if (other.score != null) return false; - } - else if (!score.equals(other.score)) + } else if (!score.equals(other.score)) return false; if (value == null) { if (other.value != null) return false; - } - else if(value instanceof byte[]) { - if(!(other.value instanceof byte[])) { + } else if (value instanceof byte[]) { + if (!(other.value instanceof byte[])) { return false; } - return Arrays.equals((byte[])value, (byte[])other.value); + return Arrays.equals((byte[]) value, (byte[]) other.value); } else if (!value.equals(other.value)) return false; return true; } - public int compareTo(Double o) { Double d = (score == null ? Double.valueOf(0) : score); Double a = (o == null ? Double.valueOf(0) : o); return d.compareTo(a); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java index 99d239d49..1e148b426 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java @@ -37,39 +37,36 @@ class DefaultValueOperations extends AbstractOperations implements V super(template); } - public V get(final Object key) { return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { return connection.get(rawKey); } }, true); } - public V getAndSet(K key, V newValue) { final byte[] rawValue = rawValue(newValue); return execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { return connection.getSet(rawKey, rawValue); } }, true); } - public Long increment(K key, final long delta) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.incrBy(rawKey, delta); } }, true); } - + public Double increment(K key, final double delta) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { @@ -84,19 +81,18 @@ class DefaultValueOperations extends AbstractOperations implements V final byte[] rawString = rawString(value); return execute(new RedisCallback() { - + public Integer doInRedis(RedisConnection connection) { return connection.append(rawKey, rawString).intValue(); } }, true); } - public String get(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); byte[] rawReturn = execute(new RedisCallback() { - + public byte[] doInRedis(RedisConnection connection) { return connection.getRange(rawKey, start, end); } @@ -118,7 +114,7 @@ class DefaultValueOperations extends AbstractOperations implements V } List rawValues = execute(new RedisCallback>() { - + public List doInRedis(RedisConnection connection) { return connection.mGet(rawKeys); } @@ -127,7 +123,6 @@ class DefaultValueOperations extends AbstractOperations implements V return deserializeValues(rawValues); } - public void multiSet(Map m) { if (m.isEmpty()) { return; @@ -140,7 +135,7 @@ class DefaultValueOperations extends AbstractOperations implements V } execute(new RedisCallback() { - + public Object doInRedis(RedisConnection connection) { connection.mSet(rawKeys); return null; @@ -148,7 +143,6 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - public Boolean multiSetIfAbsent(Map m) { if (m.isEmpty()) { return true; @@ -161,18 +155,17 @@ class DefaultValueOperations extends AbstractOperations implements V } return execute(new RedisCallback() { - + public Boolean doInRedis(RedisConnection connection) { return connection.mSetNX(rawKeys); } }, true); } - public void set(K key, V value) { final byte[] rawValue = rawValue(value); execute(new ValueDeserializingRedisCallback(key) { - + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { connection.set(rawKey, rawValue); return null; @@ -180,14 +173,13 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - public void set(K key, V value, long timeout, TimeUnit unit) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); final long rawTimeout = TimeoutUtils.toSeconds(timeout, unit); execute(new RedisCallback() { - + public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.setEx(rawKey, rawTimeout, rawValue); return null; @@ -195,27 +187,24 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - public Boolean setIfAbsent(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - + public Boolean doInRedis(RedisConnection connection) throws DataAccessException { return connection.setNX(rawKey, rawValue); } }, true); } - - public void set(K key, final V value, final long offset) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); execute(new RedisCallback() { - + public Object doInRedis(RedisConnection connection) { connection.setRange(rawKey, rawValue, offset); return null; @@ -223,15 +212,14 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - + public Long doInRedis(RedisConnection connection) { return connection.strLen(rawKey); } }, true); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java index 980077002..65518df65 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java @@ -33,7 +33,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS super(template); } - public Boolean add(final K key, final V value, final double score) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); @@ -70,12 +69,10 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Long intersectAndStore(K key, K otherKey, K destKey) { return intersectAndStore(key, Collections.singleton(otherKey), destKey); } - public Long intersectAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); @@ -87,7 +84,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Set range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); @@ -101,7 +97,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } - public Set reverseRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); @@ -115,7 +110,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } - public Set> rangeWithScores(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); @@ -129,7 +123,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeTupleValues(rawValues); } - public Set> reverseRangeWithScores(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); @@ -143,7 +136,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeTupleValues(rawValues); } - public Set rangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); @@ -170,7 +162,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } - public Set reverseRangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); @@ -210,7 +201,8 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeTupleValues(rawValues); } - public Set> rangeByScoreWithScores(K key, final double min, final double max, final long offset, final long count) { + public Set> rangeByScoreWithScores(K key, final double min, final double max, final long offset, + final long count) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { @@ -223,7 +215,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeTupleValues(rawValues); } - public Set> reverseRangeByScoreWithScores(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); @@ -238,7 +229,8 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeTupleValues(rawValues); } - public Set> reverseRangeByScoreWithScores(K key, final double min, final double max, final long offset, final long count) { + public Set> reverseRangeByScoreWithScores(K key, final double min, final double max, final long offset, + final long count) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { @@ -252,7 +244,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeTupleValues(rawValues); } - public Long rank(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); @@ -266,7 +257,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Long reverseRank(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); @@ -280,7 +270,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Long remove(K key, Object... values) { final byte[] rawKey = rawKey(key); final byte[][] rawValues = rawValues(values); @@ -293,7 +282,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Long removeRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { @@ -304,7 +292,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Long removeRangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { @@ -315,7 +302,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Double score(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); @@ -328,7 +314,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Long count(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); @@ -340,7 +325,6 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Long size(K key) { final byte[] rawKey = rawKey(key); @@ -352,12 +336,10 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - public Long unionAndStore(K key, K otherKey, K destKey) { return unionAndStore(key, Collections.singleton(otherKey), destKey); } - public Long unionAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); @@ -368,4 +350,4 @@ class DefaultZSetOperations extends AbstractOperations implements ZS } }, true); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/HashOperationsEditor.java b/src/main/java/org/springframework/data/redis/core/HashOperationsEditor.java index e967dd65e..746a9559a 100644 --- a/src/main/java/org/springframework/data/redis/core/HashOperationsEditor.java +++ b/src/main/java/org/springframework/data/redis/core/HashOperationsEditor.java @@ -18,21 +18,17 @@ package org.springframework.data.redis.core; import java.beans.PropertyEditorSupport; /** - * PropertyEditor allowing for easy injection of {@link HashOperations} from - * {@link RedisOperations}. + * PropertyEditor allowing for easy injection of {@link HashOperations} from {@link RedisOperations}. * * @author Costin Leau */ class HashOperationsEditor extends PropertyEditorSupport { - public void setValue(Object value) { if (value instanceof RedisOperations) { super.setValue(((RedisOperations) value).opsForHash()); - } - else { - throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " - + RedisOperations.class); + } else { + throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class); } } } diff --git a/src/main/java/org/springframework/data/redis/core/ListOperationsEditor.java b/src/main/java/org/springframework/data/redis/core/ListOperationsEditor.java index 8abbd6475..b1a980d25 100644 --- a/src/main/java/org/springframework/data/redis/core/ListOperationsEditor.java +++ b/src/main/java/org/springframework/data/redis/core/ListOperationsEditor.java @@ -18,20 +18,17 @@ package org.springframework.data.redis.core; import java.beans.PropertyEditorSupport; /** - * PropertyEditor allowing for easy injection of {@link ListOperations} from - * {@link RedisOperations}. + * PropertyEditor allowing for easy injection of {@link ListOperations} from {@link RedisOperations}. * * @author Costin Leau */ class ListOperationsEditor extends PropertyEditorSupport { - + public void setValue(Object value) { if (value instanceof RedisOperations) { super.setValue(((RedisOperations) value).opsForList()); - } - else { - throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " - + RedisOperations.class); + } else { + throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class); } } } diff --git a/src/main/java/org/springframework/data/redis/core/RedisAccessor.java b/src/main/java/org/springframework/data/redis/core/RedisAccessor.java index e0e8c8468..84d6fc7f8 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisAccessor.java +++ b/src/main/java/org/springframework/data/redis/core/RedisAccessor.java @@ -22,8 +22,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.util.Assert; /** - * Base class for {@link RedisTemplate} defining common properties. - * Not intended to be used directly. + * Base class for {@link RedisTemplate} defining common properties. Not intended to be used directly. * * @author Costin Leau */ @@ -40,7 +39,7 @@ public class RedisAccessor implements InitializingBean { /** * Returns the connectionFactory. - * + * * @return Returns the connectionFactory */ public RedisConnectionFactory getConnectionFactory() { @@ -55,4 +54,4 @@ public class RedisAccessor implements InitializingBean { public void setConnectionFactory(RedisConnectionFactory connectionFactory) { this.connectionFactory = connectionFactory; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/RedisCallback.java b/src/main/java/org/springframework/data/redis/core/RedisCallback.java index 9062bc177..b889651c0 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisCallback.java +++ b/src/main/java/org/springframework/data/redis/core/RedisCallback.java @@ -19,16 +19,16 @@ import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.RedisConnection; /** - * Callback interface for Redis 'low level' code. - * To be used with {@link RedisTemplate} execution methods, often as anonymous classes within a method implementation. - * Usually, used for chaining several operations together ({@code get/set/trim etc...}. + * Callback interface for Redis 'low level' code. To be used with {@link RedisTemplate} execution methods, often as + * anonymous classes within a method implementation. Usually, used for chaining several operations together ( + * {@code get/set/trim etc...}. * * @author Costin Leau */ public interface RedisCallback { /** - * Gets called by {@link RedisTemplate} with an active Redis connection. Does not need to care about activating or + * Gets called by {@link RedisTemplate} with an active Redis connection. Does not need to care about activating or * closing the connection or handling exceptions. * * @param connection active Redis connection diff --git a/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java b/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java index 7ad7b9de7..08ae0bc02 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java +++ b/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java @@ -24,7 +24,8 @@ import org.springframework.transaction.support.TransactionSynchronizationManager import org.springframework.util.Assert; /** - * Helper class featuring {@link RedisConnection} handling, allowing for reuse of instances within 'transactions'/scopes. + * Helper class featuring {@link RedisConnection} handling, allowing for reuse of instances within + * 'transactions'/scopes. * * @author Costin Leau */ @@ -33,7 +34,7 @@ public abstract class RedisConnectionUtils { private static final Log log = LogFactory.getLog(RedisConnectionUtils.class); /** - * Binds a new Redis connection (from the given factory) to the current thread, if none is already bound. + * Binds a new Redis connection (from the given factory) to the current thread, if none is already bound. * * @param factory connection factory * @return a new Redis connection @@ -43,8 +44,9 @@ public abstract class RedisConnectionUtils { } /** - * Gets a Redis connection from the given factory. Is aware of and will return any existing corresponding connections bound to the current thread, - * for example when using a transaction manager. Will always create a new connection otherwise. + * Gets a Redis connection from the given factory. Is aware of and will return any existing corresponding connections + * bound to the current thread, for example when using a transaction manager. Will always create a new connection + * otherwise. * * @param factory connection factory for creating the connection * @return an active Redis connection @@ -54,11 +56,13 @@ public abstract class RedisConnectionUtils { } /** - * Gets a Redis connection. Is aware of and will return any existing corresponding connections bound to the current thread, - * for example when using a transaction manager. Will create a new Connection otherwise, if {@code allowCreate} is true. + * Gets a Redis connection. Is aware of and will return any existing corresponding connections bound to the current + * thread, for example when using a transaction manager. Will create a new Connection otherwise, if + * {@code allowCreate} is true. * * @param factory connection factory for creating the connection - * @param allowCreate whether a new (unbound) connection should be created when no connection can be found for the current thread + * @param allowCreate whether a new (unbound) connection should be created when no connection can be found for the + * current thread * @param bind binds the connection to the thread, in case one was created * @return an active Redis connection */ @@ -66,7 +70,7 @@ public abstract class RedisConnectionUtils { Assert.notNull(factory, "No RedisConnectionFactory specified"); RedisConnectionHolder connHolder = (RedisConnectionHolder) TransactionSynchronizationManager.getResource(factory); - //TODO: investigate tx synchronization + // TODO: investigate tx synchronization if (connHolder != null) return connHolder.getConnection(); @@ -89,7 +93,8 @@ public abstract class RedisConnectionUtils { } /** - * Closes the given connection, created via the given factory if not managed externally (i.e. not bound to the thread). + * Closes the given connection, created via the given factory if not managed externally (i.e. not bound to the + * thread). * * @param conn the Redis connection to close * @param factory the Redis factory that the connection was created with @@ -113,7 +118,8 @@ public abstract class RedisConnectionUtils { * @param factory Redis factory */ public static void unbindConnection(RedisConnectionFactory factory) { - RedisConnectionHolder connHolder = (RedisConnectionHolder) TransactionSynchronizationManager.unbindResourceIfPossible(factory); + RedisConnectionHolder connHolder = (RedisConnectionHolder) TransactionSynchronizationManager + .unbindResourceIfPossible(factory); if (connHolder != null) { RedisConnection connection = connHolder.getConnection(); connection.close(); @@ -121,7 +127,8 @@ public abstract class RedisConnectionUtils { } /** - * Return whether the given Redis connection is transactional, that is, bound to the current thread by Spring's transaction facilities. + * Return whether the given Redis connection is transactional, that is, bound to the current thread by Spring's + * transaction facilities. * * @param conn Redis connection to check * @param connFactory Redis connection factory that the connection was created with @@ -131,7 +138,8 @@ public abstract class RedisConnectionUtils { if (connFactory == null) { return false; } - RedisConnectionHolder connHolder = (RedisConnectionHolder) TransactionSynchronizationManager.getResource(connFactory); + RedisConnectionHolder connHolder = (RedisConnectionHolder) TransactionSynchronizationManager + .getResource(connFactory); return (connHolder != null && conn == connHolder.getConnection()); } @@ -144,7 +152,6 @@ public abstract class RedisConnectionUtils { this.conn = conn; } - public boolean isVoid() { return isVoid; } @@ -153,14 +160,12 @@ public abstract class RedisConnectionUtils { return conn; } - public void reset() { // no-op } - public void unbound() { this.isVoid = true; } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/RedisOperations.java b/src/main/java/org/springframework/data/redis/core/RedisOperations.java index 851e246ae..aeaa7ea78 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/RedisOperations.java @@ -26,25 +26,22 @@ import org.springframework.data.redis.core.query.SortQuery; import org.springframework.data.redis.core.script.RedisScript; import org.springframework.data.redis.serializer.RedisSerializer; - /** - * Interface that specified a basic set of Redis operations, implemented by {@link RedisTemplate}. - * Not often used but a useful option for extensibility and testability (as it can be easily mocked or stubbed). + * Interface that specified a basic set of Redis operations, implemented by {@link RedisTemplate}. Not often used but a + * useful option for extensibility and testability (as it can be easily mocked or stubbed). * * @author Costin Leau */ public interface RedisOperations { /** - * Executes the given action within a Redis connection. - * - * Application exceptions thrown by the action object get propagated to the caller (can only be unchecked) whenever possible. - * Redis exceptions are transformed into appropriate DAO ones. - * Allows for returning a result object, that is a domain object or a collection of domain objects. - * Performs automatic serialization/deserialization for the given objects to and from binary data suitable for the Redis storage. - * - * Note: Callback code is not supposed to handle transactions itself! Use an appropriate transaction manager. - * Generally, callback code must not touch any Connection lifecycle methods, like close, to let the template do its work. + * Executes the given action within a Redis connection. Application exceptions thrown by the action object get + * propagated to the caller (can only be unchecked) whenever possible. Redis exceptions are transformed into + * appropriate DAO ones. Allows for returning a result object, that is a domain object or a collection of domain + * objects. Performs automatic serialization/deserialization for the given objects to and from binary data suitable + * for the Redis storage. Note: Callback code is not supposed to handle transactions itself! Use an appropriate + * transaction manager. Generally, callback code must not touch any Connection lifecycle methods, like close, to let + * the template do its work. * * @param return type * @param action callback object that specifies the Redis action @@ -52,13 +49,10 @@ public interface RedisOperations { */ T execute(RedisCallback action); - /** - * Executes a Redis session. + * Executes a Redis session. Allows multiple operations to be executed in the same session enabling 'transactional' + * capabilities through {@link #multi()} and {@link #watch(Collection)} operations. * - * Allows multiple operations to be executed in the same session enabling 'transactional' capabilities through {@link #multi()} - * and {@link #watch(Collection)} operations. - * * @param return type * @param session session callback * @return result object returned by the action or null @@ -66,30 +60,30 @@ public interface RedisOperations { T execute(SessionCallback session); /** - * Executes the given action object on a pipelined connection, returning the results. Note that the callback cannot - * return a non-null value as it gets overwritten by the pipeline. - * - * This method will use the default serializers to deserialize results - * - * @param action callback object to execute - * @return list of objects returned by the pipeline - */ + * Executes the given action object on a pipelined connection, returning the results. Note that the callback + * cannot return a non-null value as it gets overwritten by the pipeline. This method will use the default + * serializers to deserialize results + * + * @param action callback object to execute + * @return list of objects returned by the pipeline + */ List executePipelined(RedisCallback action); /** * Executes the given action object on a pipelined connection, returning the results using a dedicated serializer. * Note that the callback cannot return a non-null value as it gets overwritten by the pipeline. - * + * * @param action callback object to execute - * @param resultSerializer The Serializer to use for individual values or Collections of values. If any - * returned values are hashes, this serializer will be used to deserialize both the key and value + * @param resultSerializer The Serializer to use for individual values or Collections of values. If any returned + * values are hashes, this serializer will be used to deserialize both the key and value * @return list of objects returned by the pipeline */ List executePipelined(final RedisCallback action, final RedisSerializer resultSerializer); /** - * Executes the given Redis session on a pipelined connection. Allows transactions to be pipelined. - * Note that the callback cannot return a non-null value as it gets overwritten by the pipeline. + * Executes the given Redis session on a pipelined connection. Allows transactions to be pipelined. Note that the + * callback cannot return a non-null value as it gets overwritten by the pipeline. + * * @param session Session callback * @return list of objects returned by the pipeline */ @@ -97,8 +91,9 @@ public interface RedisOperations { /** * Executes the given Redis session on a pipelined connection, returning the results using a dedicated serializer. - * Allows transactions to be pipelined. - * Note that the callback cannot return a non-null value as it gets overwritten by the pipeline. + * Allows transactions to be pipelined. Note that the callback cannot return a non-null value as it gets + * overwritten by the pipeline. + * * @param session Session callback * @param resultSerializer * @return list of objects returned by the pipeline @@ -107,34 +102,26 @@ public interface RedisOperations { /** * Executes the given {@link RedisScript} - * - * @param script - * The script to execute - * @param keys - * Any keys that need to be passed to the script - * @param args - * Any args that need to be passed to the script - * @return The return value of the script or null if {@link RedisScript#getResultType()} is - * null, likely indicating a throw-away status reply (i.e. "OK") + * + * @param script The script to execute + * @param keys Any keys that need to be passed to the script + * @param args Any args that need to be passed to the script + * @return The return value of the script or null if {@link RedisScript#getResultType()} is null, likely indicating a + * throw-away status reply (i.e. "OK") */ T execute(RedisScript script, List keys, Object... args); /** - * Executes the given {@link RedisScript}, using the provided {@link RedisSerializer}s to - * serialize the script arguments and result. - * - * @param script - * The script to execute - * @param argsSerializer - * The {@link RedisSerializer} to use for serializing args - * @param resultSerializer - * The {@link RedisSerializer} to use for serializing the script return value - * @param keys - * Any keys that need to be passed to the script - * @param args - * Any args that need to be passed to the script - * @return The return value of the script or null if {@link RedisScript#getResultType()} is - * null, likely indicating a throw-away status reply (i.e. "OK") + * Executes the given {@link RedisScript}, using the provided {@link RedisSerializer}s to serialize the script + * arguments and result. + * + * @param script The script to execute + * @param argsSerializer The {@link RedisSerializer} to use for serializing args + * @param resultSerializer The {@link RedisSerializer} to use for serializing the script return value + * @param keys Any keys that need to be passed to the script + * @param args Any args that need to be passed to the script + * @return The return value of the script or null if {@link RedisScript#getResultType()} is null, likely indicating a + * throw-away status reply (i.e. "OK") */ T execute(RedisScript script, RedisSerializer argsSerializer, RedisSerializer resultSerializer, List keys, Object... args); @@ -177,8 +164,8 @@ public interface RedisOperations { void unwatch(); - /**' - * + /** + * ' */ void multi(); @@ -187,14 +174,12 @@ public interface RedisOperations { List exec(); /** - * Execute a transaction, using the provided {@link RedisSerializer} to deserialize - * any results that are byte[]s or Collections of byte[]s. If a result is a Map, the - * provided {@link RedisSerializer} will be used for both the keys and values. Other result - * types (Long, Boolean, etc) are left as-is in the converted results. Tuple results are + * Execute a transaction, using the provided {@link RedisSerializer} to deserialize any results that are byte[]s or + * Collections of byte[]s. If a result is a Map, the provided {@link RedisSerializer} will be used for both the keys + * and values. Other result types (Long, Boolean, etc) are left as-is in the converted results. Tuple results are * automatically converted to TypedTuples. - * - * @param valueSerializer The {@link RedisSerializer} to use for deserializing the results - * of transaction exec + * + * @param valueSerializer The {@link RedisSerializer} to use for deserializing the results of transaction exec * @return The deserialized results of transaction exec */ List exec(RedisSerializer valueSerializer); @@ -202,7 +187,6 @@ public interface RedisOperations { // pubsub functionality on the template void convertAndSend(String destination, Object message); - // operation types /** * Returns the operations performed on simple values (or Strings in Redis terminology). @@ -212,8 +196,7 @@ public interface RedisOperations { ValueOperations opsForValue(); /** - * Returns the operations performed on simple values (or Strings in Redis terminology) - * bound to the given key. + * Returns the operations performed on simple values (or Strings in Redis terminology) bound to the given key. * * @param key Redis key * @return value operations bound to the given key @@ -222,7 +205,7 @@ public interface RedisOperations { /** * Returns the operations performed on list values. - * + * * @return list operations */ ListOperations opsForList(); @@ -258,8 +241,7 @@ public interface RedisOperations { ZSetOperations opsForZSet(); /** - * Returns the operations performed on zset values (also known as sorted sets) - * bound to the given key. + * Returns the operations performed on zset values (also known as sorted sets) bound to the given key. * * @param key Redis key * @return zset operations bound to the given key. @@ -285,7 +267,6 @@ public interface RedisOperations { */ BoundHashOperations boundHashOps(K key); - List sort(SortQuery query); List sort(SortQuery query, RedisSerializer resultSerializer); @@ -303,4 +284,4 @@ public interface RedisOperations { RedisSerializer getHashKeySerializer(); RedisSerializer getHashValueSerializer(); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java index 9c05a16d8..e6dd59fe4 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -50,21 +50,21 @@ import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; /** - * Helper class that simplifies Redis data access code. + * Helper class that simplifies Redis data access code. *

- * Performs automatic serialization/deserialization between the given objects and the underlying binary data in the Redis store. - * By default, it uses Java serialization for its objects (through {@link JdkSerializationRedisSerializer}). For String intensive - * operations consider the dedicated {@link StringRedisTemplate}. + * Performs automatic serialization/deserialization between the given objects and the underlying binary data in the + * Redis store. By default, it uses Java serialization for its objects (through {@link JdkSerializationRedisSerializer} + * ). For String intensive operations consider the dedicated {@link StringRedisTemplate}. *

- * The central method is execute, supporting Redis access code implementing the {@link RedisCallback} interface. - * It provides {@link RedisConnection} handling such that neither the {@link RedisCallback} implementation nor - * the calling code needs to explicitly care about retrieving/closing Redis connections, or handling Connection - * lifecycle exceptions. For typical single step actions, there are various convenience methods. + * The central method is execute, supporting Redis access code implementing the {@link RedisCallback} interface. It + * provides {@link RedisConnection} handling such that neither the {@link RedisCallback} implementation nor the calling + * code needs to explicitly care about retrieving/closing Redis connections, or handling Connection lifecycle + * exceptions. For typical single step actions, there are various convenience methods. *

* Once configured, this class is thread-safe. - * - *

Note that while the template is generified, it is up to the serializers/deserializers to properly convert the given Objects - * to and from binary data. + *

+ * Note that while the template is generified, it is up to the serializers/deserializers to properly convert the given + * Objects to and from binary data. *

* This is the central class in Redis support. * @@ -96,17 +96,14 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation /** * Constructs a new RedisTemplate instance. - * */ - public RedisTemplate() { - } - + public RedisTemplate() {} public void afterPropertiesSet() { super.afterPropertiesSet(); boolean defaultUsed = false; - if(enableDefaultSerializer) { + if (enableDefaultSerializer) { if (keySerializer == null) { keySerializer = defaultSerializer; defaultUsed = true; @@ -129,24 +126,23 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation Assert.notNull(defaultSerializer, "default serializer null and not all serializers initialized"); } - if(scriptExecutor == null) { + if (scriptExecutor == null) { this.scriptExecutor = new DefaultScriptExecutor(this); } initialized = true; } - public T execute(RedisCallback action) { return execute(action, isExposeConnection()); } /** * Executes the given action object within a connection, which can be exposed or not. - * + * * @param return type * @param action callback object that specifies the Redis action - * @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code + * @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code * @return object returned by the action */ public T execute(RedisCallback action, boolean exposeConnection) { @@ -154,13 +150,13 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Executes the given action object within a connection that can be exposed or not. Additionally, the connection - * can be pipelined. Note the results of the pipeline are discarded (making it suitable for write-only scenarios). + * Executes the given action object within a connection that can be exposed or not. Additionally, the connection can + * be pipelined. Note the results of the pipeline are discarded (making it suitable for write-only scenarios). * * @param return type * @param action callback object to execute * @param exposeConnection whether to enforce exposure of the native Redis Connection to callback code - * @param pipeline whether to pipeline or not the connection for the execution + * @param pipeline whether to pipeline or not the connection for the execution * @return object returned by the action */ public T execute(RedisCallback action, boolean exposeConnection, boolean pipeline) { @@ -196,8 +192,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } } - - public T execute(SessionCallback session) { Assert.isTrue(initialized, "template not initialized; call afterPropertiesSet() before using it"); Assert.notNull(session, "Callback object must not be null"); @@ -232,12 +226,11 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation Object result = executeSession(session); if (result != null) { throw new InvalidDataAccessApiUsageException( - "Callback cannot return a non-null value as it gets overwritten by the pipeline"); + "Callback cannot return a non-null value as it gets overwritten by the pipeline"); } List closePipeline = connection.closePipeline(); pipelinedClosed = true; - return deserializeMixedResults(closePipeline, resultSerializer, - hashKeySerializer, hashValueSerializer); + return deserializeMixedResults(closePipeline, resultSerializer, hashKeySerializer, hashValueSerializer); } finally { if (!pipelinedClosed) { connection.closePipeline(); @@ -263,12 +256,11 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation Object result = action.doInRedis(connection); if (result != null) { throw new InvalidDataAccessApiUsageException( - "Callback cannot return a non-null value as it gets overwritten by the pipeline"); + "Callback cannot return a non-null value as it gets overwritten by the pipeline"); } List closePipeline = connection.closePipeline(); pipelinedClosed = true; - return deserializeMixedResults(closePipeline, resultSerializer, - resultSerializer, resultSerializer); + return deserializeMixedResults(closePipeline, resultSerializer, resultSerializer, resultSerializer); } finally { if (!pipelinedClosed) { connection.closePipeline(); @@ -298,7 +290,8 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Processes the connection (before any settings are executed on it). Default implementation returns the connection as is. + * Processes the connection (before any settings are executed on it). Default implementation returns the connection as + * is. * * @param connection redis connection */ @@ -311,8 +304,9 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Returns whether to expose the native Redis connection to RedisCallback code, or rather a connection proxy (the default). - * + * Returns whether to expose the native Redis connection to RedisCallback code, or rather a connection proxy (the + * default). + * * @return whether to expose the native Redis connection or not */ public boolean isExposeConnection() { @@ -320,10 +314,9 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Sets whether to expose the Redis connection to {@link RedisCallback} code. + * Sets whether to expose the Redis connection to {@link RedisCallback} code. Default is "false": a proxy will be + * returned, suppressing quit and disconnect calls. * - * Default is "false": a proxy will be returned, suppressing quit and disconnect calls. - * * @param exposeConnection */ public void setExposeConnection(boolean exposeConnection) { @@ -331,18 +324,16 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * - * @return Whether or not the default serializer should be used. If not, any serializers not explicilty set - * will remain null and values will not be serialized or deserialized. + * @return Whether or not the default serializer should be used. If not, any serializers not explicilty set will + * remain null and values will not be serialized or deserialized. */ public boolean isEnableDefaultSerializer() { return enableDefaultSerializer; } /** - * - * @param enableDefaultSerializer Whether or not the default serializer should be used. If not, - * any serializers not explicilty set will remain null and values will not be serialized or deserialized. + * @param enableDefaultSerializer Whether or not the default serializer should be used. If not, any serializers not + * explicilty set will remain null and values will not be serialized or deserialized. */ public void setEnableDefaultSerializer(boolean enableDefaultSerializer) { this.enableDefaultSerializer = enableDefaultSerializer; @@ -358,8 +349,9 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Sets the default serializer to use for this template. All serializers (expect the {@link #setStringSerializer(RedisSerializer)}) are - * initialized to this value unless explicitly set. Defaults to {@link JdkSerializationRedisSerializer}. + * Sets the default serializer to use for this template. All serializers (expect the + * {@link #setStringSerializer(RedisSerializer)}) are initialized to this value unless explicitly set. Defaults to + * {@link JdkSerializationRedisSerializer}. * * @param serializer default serializer to use */ @@ -405,7 +397,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation /** * Returns the hashKeySerializer. - * + * * @return Returns the hashKeySerializer */ public RedisSerializer getHashKeySerializer() { @@ -413,7 +405,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Sets the hash key (or field) serializer to be used by this template. Defaults to {@link #getDefaultSerializer()}. + * Sets the hash key (or field) serializer to be used by this template. Defaults to {@link #getDefaultSerializer()}. * * @param hashKeySerializer The hashKeySerializer to set. */ @@ -423,7 +415,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation /** * Returns the hashValueSerializer. - * + * * @return Returns the hashValueSerializer */ public RedisSerializer getHashValueSerializer() { @@ -431,7 +423,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Sets the hash value serializer to be used by this template. Defaults to {@link #getDefaultSerializer()}. + * Sets the hash value serializer to be used by this template. Defaults to {@link #getDefaultSerializer()}. * * @param hashValueSerializer The hashValueSerializer to set. */ @@ -441,7 +433,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation /** * Returns the stringSerializer. - * + * * @return Returns the stringSerializer */ public RedisSerializer getStringSerializer() { @@ -449,8 +441,8 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Sets the string value serializer to be used by this template (when the arguments or return types - * are always strings). Defaults to {@link StringRedisSerializer}. + * Sets the string value serializer to be used by this template (when the arguments or return types are always + * strings). Defaults to {@link StringRedisSerializer}. * * @see ValueOperations#get(Object, long, long) * @param stringSerializer The stringValueSerializer to set. @@ -460,7 +452,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * * @param scriptExecutor The {@link ScriptExecutor} to use for executing Redis scripts */ public void setScriptExecutor(ScriptExecutor scriptExecutor) { @@ -470,7 +461,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @SuppressWarnings("unchecked") private byte[] rawKey(Object key) { Assert.notNull(key, "non null key required"); - if(keySerializer == null && key instanceof byte[]) { + if (keySerializer == null && key instanceof byte[]) { return (byte[]) key; } return keySerializer.serialize(key); @@ -482,7 +473,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @SuppressWarnings("unchecked") private byte[] rawValue(Object value) { - if(valueSerializer == null && value instanceof byte[]) { + if (valueSerializer == null && value instanceof byte[]) { return (byte[]) value; } return valueSerializer.serialize(value); @@ -507,21 +498,21 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @SuppressWarnings({ "unchecked", "rawtypes" }) private List deserializeMixedResults(List rawValues, RedisSerializer valueSerializer, RedisSerializer hashKeySerializer, RedisSerializer hashValueSerializer) { - if(rawValues == null) { + if (rawValues == null) { return null; } List values = new ArrayList(); - for(Object rawValue: rawValues) { - if(rawValue instanceof byte[] && valueSerializer != null) { - values.add(valueSerializer.deserialize((byte[])rawValue)); - } else if(rawValue instanceof List) { + for (Object rawValue : rawValues) { + if (rawValue instanceof byte[] && valueSerializer != null) { + values.add(valueSerializer.deserialize((byte[]) rawValue)); + } else if (rawValue instanceof List) { // Lists are the only potential Collections of mixed values.... - values.add(deserializeMixedResults((List)rawValue, valueSerializer, hashKeySerializer, hashValueSerializer)); - } else if(rawValue instanceof Set && !(((Set)rawValue).isEmpty())) { - values.add(deserializeSet((Set)rawValue, valueSerializer)); - } else if(rawValue instanceof Map && !(((Map)rawValue).isEmpty()) && - ((Map)rawValue).values().iterator().next() instanceof byte[]) { - values.add(SerializationUtils.deserialize((Map)rawValue, hashKeySerializer, hashValueSerializer)); + values.add(deserializeMixedResults((List) rawValue, valueSerializer, hashKeySerializer, hashValueSerializer)); + } else if (rawValue instanceof Set && !(((Set) rawValue).isEmpty())) { + values.add(deserializeSet((Set) rawValue, valueSerializer)); + } else if (rawValue instanceof Map && !(((Map) rawValue).isEmpty()) + && ((Map) rawValue).values().iterator().next() instanceof byte[]) { + values.add(SerializationUtils.deserialize((Map) rawValue, hashKeySerializer, hashValueSerializer)); } else { values.add(rawValue); } @@ -531,13 +522,13 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @SuppressWarnings({ "rawtypes", "unchecked" }) private Set deserializeSet(Set rawSet, RedisSerializer valueSerializer) { - if(rawSet.isEmpty()) { + if (rawSet.isEmpty()) { return rawSet; } Object setValue = rawSet.iterator().next(); - if(setValue instanceof byte[] && valueSerializer != null) { - return (SerializationUtils.deserialize((Set)rawSet, valueSerializer)); - }else if(setValue instanceof Tuple) { + if (setValue instanceof byte[] && valueSerializer != null) { + return (SerializationUtils.deserialize((Set) rawSet, valueSerializer)); + } else if (setValue instanceof Tuple) { return convertTupleValues(rawSet, valueSerializer); } else { return rawSet; @@ -549,7 +540,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation Set> set = new LinkedHashSet>(rawValues.size()); for (Tuple rawValue : rawValues) { Object value = rawValue.getValue(); - if(valueSerializer != null) { + if (valueSerializer != null) { value = valueSerializer.deserialize(rawValue.getValue()); } set.add(new DefaultTypedTuple(value, rawValue.getScore())); @@ -562,29 +553,24 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // /** - * Execute a transaction, using the default {@link RedisSerializer}s to deserialize - * any results that are byte[]s or Collections or Maps of byte[]s or Tuples. Other result - * types (Long, Boolean, etc) are left as-is in the converted results. - * - * If conversion of tx results has been disabled in the {@link RedisConnectionFactory}, - * the results of exec will be returned without deserialization. This check is mostly for - * backwards compatibility with 1.0. - * + * Execute a transaction, using the default {@link RedisSerializer}s to deserialize any results that are byte[]s or + * Collections or Maps of byte[]s or Tuples. Other result types (Long, Boolean, etc) are left as-is in the converted + * results. If conversion of tx results has been disabled in the {@link RedisConnectionFactory}, the results of exec + * will be returned without deserialization. This check is mostly for backwards compatibility with 1.0. + * * @return The (possibly deserialized) results of transaction exec */ public List exec() { List results = execRaw(); - if(getConnectionFactory().getConvertPipelineAndTxResults()) { - return deserializeMixedResults(results, valueSerializer, - hashKeySerializer, hashValueSerializer); + if (getConnectionFactory().getConvertPipelineAndTxResults()) { + return deserializeMixedResults(results, valueSerializer, hashKeySerializer, hashValueSerializer); } else { return results; } } public List exec(RedisSerializer valueSerializer) { - return deserializeMixedResults(execRaw(), valueSerializer, valueSerializer, - valueSerializer); + return deserializeMixedResults(execRaw(), valueSerializer, valueSerializer, valueSerializer); } protected List execRaw() { @@ -595,7 +581,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }); } - public void delete(K key) { final byte[] rawKey = rawKey(key); @@ -608,7 +593,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public void delete(Collection keys) { if (CollectionUtils.isEmpty(keys)) { return; @@ -625,7 +609,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public Boolean hasKey(K key) { final byte[] rawKey = rawKey(key); @@ -637,7 +620,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public Boolean expire(K key, final long timeout, final TimeUnit unit) { final byte[] rawKey = rawKey(key); final long rawTimeout = TimeoutUtils.toMillis(timeout, unit); @@ -647,7 +629,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation public Boolean doInRedis(RedisConnection connection) { try { return connection.pExpire(rawKey, rawTimeout); - } catch(Exception e) { + } catch (Exception e) { // Driver may not support pExpire or we may be running on Redis 2.4 return connection.expire(rawKey, TimeoutUtils.toSeconds(timeout, unit)); } @@ -655,7 +637,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public Boolean expireAt(K key, final Date date) { final byte[] rawKey = rawKey(key); @@ -664,14 +645,13 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation public Boolean doInRedis(RedisConnection connection) { try { return connection.pExpireAt(rawKey, date.getTime()); - } catch(Exception e) { + } catch (Exception e) { return connection.expireAt(rawKey, date.getTime() / 1000); } } }, true); } - public void convertAndSend(String channel, Object message) { Assert.hasText(channel, "a non-empty channel is required"); @@ -687,12 +667,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - // // Value operations // - public Long getExpire(K key) { final byte[] rawKey = rawKey(key); @@ -712,7 +690,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation public Long doInRedis(RedisConnection connection) { try { return timeUnit.convert(connection.pTtl(rawKey), TimeUnit.MILLISECONDS); - } catch(Exception e) { + } catch (Exception e) { // Driver may not support pTtl or we may be running on Redis 2.4 return timeUnit.convert(connection.ttl(rawKey), TimeUnit.SECONDS); } @@ -731,11 +709,9 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } }, true); - return keySerializer != null ? SerializationUtils.deserialize(rawKeys, keySerializer) : - rawKeys; + return keySerializer != null ? SerializationUtils.deserialize(rawKeys, keySerializer) : rawKeys; } - public Boolean persist(K key) { final byte[] rawKey = rawKey(key); @@ -747,7 +723,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public Boolean move(K key, final int dbIndex) { final byte[] rawKey = rawKey(key); @@ -759,7 +734,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public K randomKey() { byte[] rawKey = execute(new RedisCallback() { @@ -771,7 +745,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return deserializeKey(rawKey); } - public void rename(K oldKey, K newKey) { final byte[] rawOldKey = rawKey(oldKey); final byte[] rawNewKey = rawKey(newKey); @@ -785,7 +758,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public Boolean renameIfAbsent(K oldKey, K newKey) { final byte[] rawOldKey = rawKey(oldKey); final byte[] rawNewKey = rawKey(newKey); @@ -798,7 +770,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public DataType type(K key) { final byte[] rawKey = rawKey(key); @@ -811,11 +782,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Executes the Redis dump command and returns the results. Redis uses a - * non-standard serialization mechanism and includes checksum information, - * thus the raw bytes are returned as opposed to deserializing with - * valueSerializer. Use the return value of dump as the value argument to restore - * + * Executes the Redis dump command and returns the results. Redis uses a non-standard serialization mechanism and + * includes checksum information, thus the raw bytes are returned as opposed to deserializing with valueSerializer. + * Use the return value of dump as the value argument to restore + * * @param key The key to dump * @return results The results of the dump operation */ @@ -830,18 +800,14 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Executes the Redis restore command. The value passed in should be the exact - * serialized data returned from {@link #dump(Object)}, since Redis uses a - * non-standard serialization mechanism. - * - * + * Executes the Redis restore command. The value passed in should be the exact serialized data returned from + * {@link #dump(Object)}, since Redis uses a non-standard serialization mechanism. + * * @param key The key to restore * @param value The value to restore, as returned by {@link #dump(Object)} * @param timeToLive An expiration for the restored key, or 0 for no expiration * @param unit The time unit for timeToLive - * @throws RedisSystemException if the key you are attempting to restore already - * exists. - * + * @throws RedisSystemException if the key you are attempting to restore already exists. */ public void restore(K key, final byte[] value, long timeToLive, TimeUnit unit) { final byte[] rawKey = rawKey(key); @@ -865,11 +831,9 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public void discard() { execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.discard(); return null; @@ -877,7 +841,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public void watch(K key) { final byte[] rawKey = rawKey(key); @@ -890,7 +853,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public void watch(Collection keys) { final byte[][] rawKeys = rawKeys(keys); @@ -903,7 +865,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public void unwatch() { execute(new RedisCallback() { @@ -921,7 +882,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return sort(query, valueSerializer); } - public List sort(SortQuery query, RedisSerializer resultSerializer) { final byte[] rawKey = rawKey(query.getKey()); final SortParameters params = QueryUtils.convertQuery(query, stringSerializer); @@ -941,7 +901,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return sort(query, bulkMapper, valueSerializer); } - public List sort(SortQuery query, BulkMapper bulkMapper, RedisSerializer resultSerializer) { List values = sort(query, resultSerializer); @@ -966,7 +925,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return result; } - public Long sort(SortQuery query, K storeKey) { final byte[] rawStoreKey = rawKey(storeKey); final byte[] rawKey = rawKey(query.getKey()); @@ -980,12 +938,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - public BoundValueOperations boundValueOps(K key) { return new DefaultBoundValueOperations(key, this); } - public ValueOperations opsForValue() { if (valueOps == null) { valueOps = new DefaultValueOperations(this); @@ -993,7 +949,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return valueOps; } - public ListOperations opsForList() { if (listOps == null) { listOps = new DefaultListOperations(this); @@ -1001,17 +956,14 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return listOps; } - public BoundListOperations boundListOps(K key) { return new DefaultBoundListOperations(key, this); } - public BoundSetOperations boundSetOps(K key) { return new DefaultBoundSetOperations(key, this); } - public SetOperations opsForSet() { if (setOps == null) { setOps = new DefaultSetOperations(this); @@ -1019,12 +971,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return setOps; } - public BoundZSetOperations boundZSetOps(K key) { return new DefaultBoundZSetOperations(key, this); } - public ZSetOperations opsForZSet() { if (zSetOps == null) { zSetOps = new DefaultZSetOperations(this); @@ -1032,13 +982,11 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return zSetOps; } - public BoundHashOperations boundHashOps(K key) { return new DefaultBoundHashOperations(key, this); } - public HashOperations opsForHash() { return new DefaultHashOperations(this); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/SessionCallback.java b/src/main/java/org/springframework/data/redis/core/SessionCallback.java index 39807ceb3..490aa40e1 100644 --- a/src/main/java/org/springframework/data/redis/core/SessionCallback.java +++ b/src/main/java/org/springframework/data/redis/core/SessionCallback.java @@ -18,8 +18,8 @@ package org.springframework.data.redis.core; import org.springframework.dao.DataAccessException; /** - * Callback executing all operations against a surrogate 'session' (basically against the same underlying Redis connection). - * Allows 'transactions' to take place through the use of multi/discard/exec/watch/unwatch commands. + * Callback executing all operations against a surrogate 'session' (basically against the same underlying Redis + * connection). Allows 'transactions' to take place through the use of multi/discard/exec/watch/unwatch commands. * * @author Costin Leau */ diff --git a/src/main/java/org/springframework/data/redis/core/SetOperationsEditor.java b/src/main/java/org/springframework/data/redis/core/SetOperationsEditor.java index 19ab09718..7ec3e30f4 100644 --- a/src/main/java/org/springframework/data/redis/core/SetOperationsEditor.java +++ b/src/main/java/org/springframework/data/redis/core/SetOperationsEditor.java @@ -18,21 +18,17 @@ package org.springframework.data.redis.core; import java.beans.PropertyEditorSupport; /** - * PropertyEditor allowing for easy injection of {@link SetOperations} from - * {@link RedisOperations}. + * PropertyEditor allowing for easy injection of {@link SetOperations} from {@link RedisOperations}. * * @author Costin Leau */ class SetOperationsEditor extends PropertyEditorSupport { - public void setValue(Object value) { if (value instanceof RedisOperations) { super.setValue(((RedisOperations) value).opsForSet()); - } - else { - throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " - + RedisOperations.class); + } else { + throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class); } } } diff --git a/src/main/java/org/springframework/data/redis/core/StringRedisTemplate.java b/src/main/java/org/springframework/data/redis/core/StringRedisTemplate.java index 0c06f5fdb..36e08f373 100644 --- a/src/main/java/org/springframework/data/redis/core/StringRedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/StringRedisTemplate.java @@ -23,21 +23,20 @@ import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; /** - * String-focused extension of RedisTemplate. Since most operations against Redis are String based, - * this class provides a dedicated class that minimizes configuration of its more generic - * {@link RedisTemplate template} especially in terms of serializers. - * - *

Note that this template exposes the {@link RedisConnection} used by the {@link RedisCallback} - * as a {@link StringRedisConnection}. + * String-focused extension of RedisTemplate. Since most operations against Redis are String based, this class provides + * a dedicated class that minimizes configuration of its more generic {@link RedisTemplate template} especially in terms + * of serializers. + *

+ * Note that this template exposes the {@link RedisConnection} used by the {@link RedisCallback} as a + * {@link StringRedisConnection}. * * @author Costin Leau */ public class StringRedisTemplate extends RedisTemplate { /** - * Constructs a new StringRedisTemplate instance. - * {@link #setConnectionFactory(RedisConnectionFactory)} and {@link #afterPropertiesSet()} still need to be called. - * + * Constructs a new StringRedisTemplate instance. {@link #setConnectionFactory(RedisConnectionFactory)} + * and {@link #afterPropertiesSet()} still need to be called. */ public StringRedisTemplate() { RedisSerializer stringSerializer = new StringRedisSerializer(); @@ -48,8 +47,8 @@ public class StringRedisTemplate extends RedisTemplate { } /** - * Constructs a new StringRedisTemplate instance ready to be used. - * + * Constructs a new StringRedisTemplate instance ready to be used. + * * @param connectionFactory connection factory for creating new connections */ public StringRedisTemplate(RedisConnectionFactory connectionFactory) { @@ -61,4 +60,4 @@ public class StringRedisTemplate extends RedisTemplate { protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) { return new DefaultStringRedisConnection(connection); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/TimeoutUtils.java b/src/main/java/org/springframework/data/redis/core/TimeoutUtils.java index 08eb7b7f0..e1c5841b8 100644 --- a/src/main/java/org/springframework/data/redis/core/TimeoutUtils.java +++ b/src/main/java/org/springframework/data/redis/core/TimeoutUtils.java @@ -27,14 +27,11 @@ abstract public class TimeoutUtils { /** * Converts the given timeout to seconds. *

- * Since a 0 timeout blocks some Redis ops indefinitely, this method will - * return 1 if the original value is greater than 0 but is truncated to 0 on - * conversion. + * Since a 0 timeout blocks some Redis ops indefinitely, this method will return 1 if the original value is greater + * than 0 but is truncated to 0 on conversion. * - * @param timeout - * The timeout to convert - * @param unit - * The timeout's unit + * @param timeout The timeout to convert + * @param unit The timeout's unit * @return The converted timeout */ public static long toSeconds(long timeout, TimeUnit unit) { @@ -45,14 +42,11 @@ abstract public class TimeoutUtils { /** * Converts the given timeout to milliseconds. *

- * Since a 0 timeout blocks some Redis ops indefinitely, this method will - * return 1 if the original value is greater than 0 but is truncated to 0 on - * conversion. - * - * @param timeout - * The timeout to convert - * @param unit - * The timeout's unit + * Since a 0 timeout blocks some Redis ops indefinitely, this method will return 1 if the original value is greater + * than 0 but is truncated to 0 on conversion. + * + * @param timeout The timeout to convert + * @param unit The timeout's unit * @return The converted timeout */ public static long toMillis(long timeout, TimeUnit unit) { @@ -67,4 +61,4 @@ abstract public class TimeoutUtils { } return convertedTimeout; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/ValueOperationsEditor.java b/src/main/java/org/springframework/data/redis/core/ValueOperationsEditor.java index 1752547e5..76f37c8f4 100644 --- a/src/main/java/org/springframework/data/redis/core/ValueOperationsEditor.java +++ b/src/main/java/org/springframework/data/redis/core/ValueOperationsEditor.java @@ -18,21 +18,17 @@ package org.springframework.data.redis.core; import java.beans.PropertyEditorSupport; /** - * PropertyEditor allowing for easy injection of {@link ValueOperations} from - * {@link RedisOperations}. + * PropertyEditor allowing for easy injection of {@link ValueOperations} from {@link RedisOperations}. * * @author Costin Leau */ class ValueOperationsEditor extends PropertyEditorSupport { - public void setValue(Object value) { if (value instanceof RedisOperations) { super.setValue(((RedisOperations) value).opsForValue()); - } - else { - throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " - + RedisOperations.class); + } else { + throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class); } } } diff --git a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java index a00dee7b9..e8871d0dd 100644 --- a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java @@ -27,7 +27,7 @@ import java.util.Set; public interface ZSetOperations { /** - * Typed ZSet tuple. + * Typed ZSet tuple. */ public interface TypedTuple extends Comparable { V getValue(); @@ -90,4 +90,4 @@ public interface ZSetOperations { Long size(K key); RedisOperations getOperations(); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/ZSetOperationsEditor.java b/src/main/java/org/springframework/data/redis/core/ZSetOperationsEditor.java index d7325d580..ef625559c 100644 --- a/src/main/java/org/springframework/data/redis/core/ZSetOperationsEditor.java +++ b/src/main/java/org/springframework/data/redis/core/ZSetOperationsEditor.java @@ -18,21 +18,17 @@ package org.springframework.data.redis.core; import java.beans.PropertyEditorSupport; /** - * PropertyEditor allowing for easy injection of {@link ZSetOperations} from - * {@link RedisOperations}. + * PropertyEditor allowing for easy injection of {@link ZSetOperations} from {@link RedisOperations}. * * @author Costin Leau */ class ZSetOperationsEditor extends PropertyEditorSupport { - public void setValue(Object value) { if (value instanceof RedisOperations) { super.setValue(((RedisOperations) value).opsForZSet()); - } - else { - throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " - + RedisOperations.class); + } else { + throw new java.lang.IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class); } } } diff --git a/src/main/java/org/springframework/data/redis/core/query/DefaultSortCriterion.java b/src/main/java/org/springframework/data/redis/core/query/DefaultSortCriterion.java index b5a56e36b..8116e63a7 100644 --- a/src/main/java/org/springframework/data/redis/core/query/DefaultSortCriterion.java +++ b/src/main/java/org/springframework/data/redis/core/query/DefaultSortCriterion.java @@ -40,36 +40,30 @@ class DefaultSortCriterion implements SortCriterion { this.key = key; } - public SortCriterion alphabetical(boolean alpha) { this.alpha = Boolean.valueOf(alpha); return this; } - public SortQuery build() { return new DefaultSortQuery(key, by, limit, order, alpha, getKeys); } - public SortCriterion limit(long offset, long count) { this.limit = new Range(offset, count); return this; } - public SortCriterion limit(Range range) { this.limit = range; return this; } - public SortCriterion order(Order order) { this.order = order; return this; } - public SortCriterion get(String getPattern) { this.getKeys.add(getPattern); return this; @@ -79,4 +73,4 @@ class DefaultSortCriterion implements SortCriterion { this.by = keyPattern; return this; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/query/DefaultSortQuery.java b/src/main/java/org/springframework/data/redis/core/query/DefaultSortQuery.java index 7d7d71fc0..ad77f1530 100644 --- a/src/main/java/org/springframework/data/redis/core/query/DefaultSortQuery.java +++ b/src/main/java/org/springframework/data/redis/core/query/DefaultSortQuery.java @@ -43,41 +43,33 @@ class DefaultSortQuery implements SortQuery { this.gets = gets; } - public String getBy() { return by; } - public Range getLimit() { return limit; } - public Order getOrder() { return order; } - public Boolean isAlphabetic() { return alpha; } - public K getKey() { return key; } - public List getGetPattern() { return gets; } - public String toString() { - return "DefaultSortQuery [alpha=" + alpha + ", by=" + by + ", gets=" + gets + ", key=" + key + ", limit=" - + limit + ", order=" + order + "]"; + return "DefaultSortQuery [alpha=" + alpha + ", by=" + by + ", gets=" + gets + ", key=" + key + ", limit=" + limit + + ", order=" + order + "]"; } - -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/query/QueryUtils.java b/src/main/java/org/springframework/data/redis/core/query/QueryUtils.java index 2e6bb761b..d412bd6fb 100644 --- a/src/main/java/org/springframework/data/redis/core/query/QueryUtils.java +++ b/src/main/java/org/springframework/data/redis/core/query/QueryUtils.java @@ -41,8 +41,7 @@ public abstract class QueryUtils { if (strings == null) { raw = Collections.emptyList(); - } - else { + } else { raw = new ArrayList(strings.size()); for (String key : strings) { raw.add(stringSerializer.serialize(key)); diff --git a/src/main/java/org/springframework/data/redis/core/query/SortQuery.java b/src/main/java/org/springframework/data/redis/core/query/SortQuery.java index f4bd3345a..3a4aa88fd 100644 --- a/src/main/java/org/springframework/data/redis/core/query/SortQuery.java +++ b/src/main/java/org/springframework/data/redis/core/query/SortQuery.java @@ -24,8 +24,8 @@ import org.springframework.data.redis.connection.SortParameters.Range; import org.springframework.data.redis.core.RedisTemplate; /** - * High-level abstraction over a Redis SORT (generified equivalent of {@link SortParameters}). To be used with {@link RedisTemplate} - * (just as {@link SortParameters} is used by {@link RedisConnection}). + * High-level abstraction over a Redis SORT (generified equivalent of {@link SortParameters}). To be used with + * {@link RedisTemplate} (just as {@link SortParameters} is used by {@link RedisConnection}). * * @author Costin Leau */ @@ -39,17 +39,15 @@ public interface SortQuery { Order getOrder(); /** - * Indicates if the sorting is numeric (default) or alphabetical (lexicographical). - * Can be null if nothing is specified. + * Indicates if the sorting is numeric (default) or alphabetical (lexicographical). Can be null if nothing is + * specified. * * @return the type of sorting */ Boolean isAlphabetic(); - /** - * Returns the sorting limit (range or pagination). - * Can be null if nothing is specified. + * Returns the sorting limit (range or pagination). Can be null if nothing is specified. * * @return sorting limit/range */ @@ -71,8 +69,8 @@ public interface SortQuery { /** * Returns the external key(s) whose values are returned by the sort. - * + * * @return the (list of) keys used for GET */ List getGetPattern(); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/core/query/SortQueryBuilder.java b/src/main/java/org/springframework/data/redis/core/query/SortQueryBuilder.java index 3acaf8774..eac83a829 100644 --- a/src/main/java/org/springframework/data/redis/core/query/SortQueryBuilder.java +++ b/src/main/java/org/springframework/data/redis/core/query/SortQueryBuilder.java @@ -15,10 +15,9 @@ */ package org.springframework.data.redis.core.query; - /** * Simple builder class for constructing {@link SortQuery}. - * + * * @author Costin Leau */ public class SortQueryBuilder extends DefaultSortCriterion { diff --git a/src/main/java/org/springframework/data/redis/core/script/DefaultRedisScript.java b/src/main/java/org/springframework/data/redis/core/script/DefaultRedisScript.java index 7bf7806b3..534dde911 100644 --- a/src/main/java/org/springframework/data/redis/core/script/DefaultRedisScript.java +++ b/src/main/java/org/springframework/data/redis/core/script/DefaultRedisScript.java @@ -25,16 +25,13 @@ import org.springframework.scripting.support.StaticScriptSource; import org.springframework.util.Assert; /** - * Default implementation of {@link RedisScript}. Delegates to an underlying {@link ScriptSource} to - * retrieve script text and detect if script has been modified (and thus should have SHA1 - * re-calculated). This class is best used as a Singleton to avoid re-calculation of SHA1 on every - * script execution. - * + * Default implementation of {@link RedisScript}. Delegates to an underlying {@link ScriptSource} to retrieve script + * text and detect if script has been modified (and thus should have SHA1 re-calculated). This class is best used as a + * Singleton to avoid re-calculation of SHA1 on every script execution. + * * @author Jennifer Hickey - * - * @param - * The script result type. Should be one of Long, Boolean, List, or deserialized value - * type. Can be null if the script returns a throw-away status (i.e "OK") + * @param The script result type. Should be one of Long, Boolean, List, or deserialized value type. Can be null if + * the script returns a throw-away status (i.e "OK") */ public class DefaultRedisScript implements RedisScript, InitializingBean { @@ -47,8 +44,7 @@ public class DefaultRedisScript implements RedisScript, InitializingBean { private final Object shaModifiedMonitor = new Object(); public void afterPropertiesSet() throws Exception { - Assert.notNull(this.scriptSource, "Either script, script location," - + " or script source is required"); + Assert.notNull(this.scriptSource, "Either script, script location," + " or script source is required"); } public String getSha1() { @@ -73,37 +69,29 @@ public class DefaultRedisScript implements RedisScript, InitializingBean { } /** - * - * @param resultType - * The script result type. Should be one of Long, Boolean, List, or deserialized - * value type. Can be null if the script returns a throw-away status (i.e "OK") + * @param resultType The script result type. Should be one of Long, Boolean, List, or deserialized value type. Can be + * null if the script returns a throw-away status (i.e "OK") */ public void setResultType(Class resultType) { this.resultType = resultType; } /** - * - * @param script - * The script text + * @param script The script text */ public void setScriptText(String scriptText) { this.scriptSource = new StaticScriptSource(scriptText); } /** - * - * @param scriptLocation - * The location of the script + * @param scriptLocation The location of the script */ public void setLocation(Resource scriptLocation) { this.scriptSource = new ResourceScriptSource(scriptLocation); } /** - * - * @param scriptSource - * A @{link {@link ScriptSource} pointing to the script + * @param scriptSource A @{link {@link ScriptSource} pointing to the script */ public void setScriptSource(ScriptSource scriptSource) { this.scriptSource = scriptSource; diff --git a/src/main/java/org/springframework/data/redis/core/script/DefaultScriptExecutor.java b/src/main/java/org/springframework/data/redis/core/script/DefaultScriptExecutor.java index 19f37e9f4..953062c33 100644 --- a/src/main/java/org/springframework/data/redis/core/script/DefaultScriptExecutor.java +++ b/src/main/java/org/springframework/data/redis/core/script/DefaultScriptExecutor.java @@ -26,21 +26,18 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; /** - * Default implementation of {@link ScriptExecutor}. Optimizes performance by attempting to execute - * script first using evalsha, then falling back to eval if Redis has not yet cached the script. - * Evalsha is not attempted if the script is executed in a pipeline or transaction. - * + * Default implementation of {@link ScriptExecutor}. Optimizes performance by attempting to execute script first using + * evalsha, then falling back to eval if Redis has not yet cached the script. Evalsha is not attempted if the script is + * executed in a pipeline or transaction. + * * @author Jennifer Hickey - * - * @param - * The type of keys that may be passed during script execution + * @param The type of keys that may be passed during script execution */ public class DefaultScriptExecutor implements ScriptExecutor { private RedisTemplate template; /** - * * @param template The {@link RedisTemplate} to use */ public DefaultScriptExecutor(RedisTemplate template) { @@ -50,12 +47,12 @@ public class DefaultScriptExecutor implements ScriptExecutor { @SuppressWarnings("unchecked") public T execute(final RedisScript script, final List keys, final Object... args) { // use the Template's value serializer for args and result - return execute(script, template.getValueSerializer(), - (RedisSerializer) template.getValueSerializer(), keys, args); + return execute(script, template.getValueSerializer(), (RedisSerializer) template.getValueSerializer(), keys, + args); } - public T execute(final RedisScript script, final RedisSerializer argsSerializer, final RedisSerializer resultSerializer, - final List keys, final Object... args) { + public T execute(final RedisScript script, final RedisSerializer argsSerializer, + final RedisSerializer resultSerializer, final List keys, final Object... args) { return template.execute(new RedisCallback() { public T doInRedis(RedisConnection connection) throws DataAccessException { final ReturnType returnType = ReturnType.fromJavaType(script.getResultType()); @@ -67,14 +64,13 @@ public class DefaultScriptExecutor implements ScriptExecutor { connection.eval(scriptBytes(script), returnType, keySize, keysAndArgs); return null; } - return eval(connection, script, returnType, keySize, keysAndArgs, - resultSerializer); + return eval(connection, script, returnType, keySize, keysAndArgs, resultSerializer); } }); } - protected T eval(RedisConnection connection, RedisScript script, ReturnType returnType, - int numKeys, byte[][] keysAndArgs, RedisSerializer resultSerializer) { + protected T eval(RedisConnection connection, RedisScript script, ReturnType returnType, int numKeys, + byte[][] keysAndArgs, RedisSerializer resultSerializer) { Object result; try { result = connection.evalSha(script.getSha1(), returnType, numKeys, keysAndArgs); @@ -92,7 +88,7 @@ public class DefaultScriptExecutor implements ScriptExecutor { final int keySize = keys != null ? keys.size() : 0; byte[][] keysAndArgs = new byte[args.length + keySize][]; int i = 0; - if(keys != null) { + if (keys != null) { for (K key : keys) { if (keySerializer() == null && key instanceof byte[]) { keysAndArgs[i++] = (byte[]) key; diff --git a/src/main/java/org/springframework/data/redis/core/script/DigestUtils.java b/src/main/java/org/springframework/data/redis/core/script/DigestUtils.java index de4f9c9c6..1ce87e48f 100644 --- a/src/main/java/org/springframework/data/redis/core/script/DigestUtils.java +++ b/src/main/java/org/springframework/data/redis/core/script/DigestUtils.java @@ -21,22 +21,20 @@ import java.security.NoSuchAlgorithmException; /** * Utilties for working with {@link MessageDigest} - * + * * @author Jennifer Hickey - * */ abstract public class DigestUtils { - private static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f' }; + private static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', + 'f' }; private static final Charset UTF8_CHARSET = Charset.forName("UTF8"); /** * Returns the SHA1 of the provided data - * - * @param data - * The data to calculate, such as the contents of a file + * + * @param data The data to calculate, such as the contents of a file * @return The human-readable SHA1 */ public static String sha1DigestAsHex(String data) { @@ -55,15 +53,14 @@ abstract public class DigestUtils { } /** - * Creates a new {@link MessageDigest} with the given algorithm. Necessary because - * {@code MessageDigest} is not thread-safe. + * Creates a new {@link MessageDigest} with the given algorithm. Necessary because {@code MessageDigest} is not + * thread-safe. */ private static MessageDigest getDigest(String algorithm) { try { return MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException ex) { - throw new IllegalStateException("Could not find MessageDigest with algorithm \"" - + algorithm + "\"", ex); + throw new IllegalStateException("Could not find MessageDigest with algorithm \"" + algorithm + "\"", ex); } } } diff --git a/src/main/java/org/springframework/data/redis/core/script/RedisScript.java b/src/main/java/org/springframework/data/redis/core/script/RedisScript.java index 069206756..5ea6b5639 100644 --- a/src/main/java/org/springframework/data/redis/core/script/RedisScript.java +++ b/src/main/java/org/springframework/data/redis/core/script/RedisScript.java @@ -16,32 +16,27 @@ package org.springframework.data.redis.core.script; /** - * A script to be executed using the Redis scripting - * support available as of version 2.6 - * + * A script to be executed using the Redis scripting support available as of + * version 2.6 + * * @author Jennifer Hickey - * - * @param - * The script result type. Should be one of Long, Boolean, List, or deserialized value - * type. Can be null if the script returns a throw-away status (i.e "OK") + * @param The script result type. Should be one of Long, Boolean, List, or deserialized value type. Can be null if + * the script returns a throw-away status (i.e "OK") */ public interface RedisScript { /** - * * @return The SHA1 of the script, used for executing Redis evalsha command */ String getSha1(); /** - * - * @return The script result type. Should be one of Long, Boolean, List, or deserialized value - * type. Can be null if the script returns a throw-away status (i.e "OK") + * @return The script result type. Should be one of Long, Boolean, List, or deserialized value type. Can be null if + * the script returns a throw-away status (i.e "OK") */ Class getResultType(); /** - * * @return The script contents */ String getScriptAsString(); diff --git a/src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java b/src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java index d28f3554e..41aec3615 100644 --- a/src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java +++ b/src/main/java/org/springframework/data/redis/core/script/ScriptExecutor.java @@ -21,44 +21,34 @@ import org.springframework.data.redis.serializer.RedisSerializer; /** * Executes {@link RedisScript}s - * + * * @author Jennifer Hickey - * - * @param - * The type of keys that may be passed during script execution + * @param The type of keys that may be passed during script execution */ public interface ScriptExecutor { /** * Executes the given {@link RedisScript} - * - * @param script - * The script to execute - * @param keys - * Any keys that need to be passed to the script - * @param args - * Any args that need to be passed to the script - * @return The return value of the script or null if {@link RedisScript#getResultType()} is - * null, likely indicating a throw-away status reply (i.e. "OK") + * + * @param script The script to execute + * @param keys Any keys that need to be passed to the script + * @param args Any args that need to be passed to the script + * @return The return value of the script or null if {@link RedisScript#getResultType()} is null, likely indicating a + * throw-away status reply (i.e. "OK") */ T execute(RedisScript script, List keys, Object... args); /** - * Executes the given {@link RedisScript}, using the provided {@link RedisSerializer}s to - * serialize the script arguments and result. - * - * @param script - * The script to execute - * @param argsSerializer - * The {@link RedisSerializer} to use for serializing args - * @param resultSerializer - * The {@link RedisSerializer} to use for serializing the script return value - * @param keys - * Any keys that need to be passed to the script - * @param args - * Any args that need to be passed to the script - * @return The return value of the script or null if {@link RedisScript#getResultType()} is - * null, likely indicating a throw-away status reply (i.e. "OK") + * Executes the given {@link RedisScript}, using the provided {@link RedisSerializer}s to serialize the script + * arguments and result. + * + * @param script The script to execute + * @param argsSerializer The {@link RedisSerializer} to use for serializing args + * @param resultSerializer The {@link RedisSerializer} to use for serializing the script return value + * @param keys Any keys that need to be passed to the script + * @param args Any args that need to be passed to the script + * @return The return value of the script or null if {@link RedisScript#getResultType()} is null, likely indicating a + * throw-away status reply (i.e. "OK") */ T execute(RedisScript script, RedisSerializer argsSerializer, RedisSerializer resultSerializer, List keys, Object... args); diff --git a/src/main/java/org/springframework/data/redis/core/script/ScriptingException.java b/src/main/java/org/springframework/data/redis/core/script/ScriptingException.java index c21c564fa..d6234949e 100644 --- a/src/main/java/org/springframework/data/redis/core/script/ScriptingException.java +++ b/src/main/java/org/springframework/data/redis/core/script/ScriptingException.java @@ -19,16 +19,15 @@ import org.springframework.core.NestedRuntimeException; /** * {@link RuntimeException} thrown when issues occur with {@link RedisScript}s - * + * * @author Jennifer Hickey - * */ @SuppressWarnings("serial") public class ScriptingException extends NestedRuntimeException { /** * Constructs a new ScriptingException instance. - * + * * @param msg * @param cause */ @@ -38,7 +37,7 @@ public class ScriptingException extends NestedRuntimeException { /** * Constructs a new ScriptingException instance. - * + * * @param msg */ public ScriptingException(String msg) { diff --git a/src/main/java/org/springframework/data/redis/hash/BeanUtilsHashMapper.java b/src/main/java/org/springframework/data/redis/hash/BeanUtilsHashMapper.java index 9eddfb420..d74602fea 100644 --- a/src/main/java/org/springframework/data/redis/hash/BeanUtilsHashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/BeanUtilsHashMapper.java @@ -32,7 +32,6 @@ public class BeanUtilsHashMapper implements HashMapper { this.type = type; } - public T fromHash(Map hash) { T instance = org.springframework.beans.BeanUtils.instantiate(type); try { @@ -43,7 +42,6 @@ public class BeanUtilsHashMapper implements HashMapper { return instance; } - public Map toHash(T object) { try { return BeanUtils.describe(object); diff --git a/src/main/java/org/springframework/data/redis/hash/DecoratingStringHashMapper.java b/src/main/java/org/springframework/data/redis/hash/DecoratingStringHashMapper.java index 40c2f25c6..fba3fb93b 100644 --- a/src/main/java/org/springframework/data/redis/hash/DecoratingStringHashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/DecoratingStringHashMapper.java @@ -19,8 +19,8 @@ import java.util.LinkedHashMap; import java.util.Map; /** - * Delegating hash mapper used for flattening objects into Strings. - * Suitable when dealing with mappers that support Strings and type conversion. + * Delegating hash mapper used for flattening objects into Strings. Suitable when dealing with mappers that support + * Strings and type conversion. * * @author Costin Leau */ @@ -36,7 +36,6 @@ public class DecoratingStringHashMapper implements HashMapper toHash(T object) { Map hash = delegate.toHash(object); Map flatten = new LinkedHashMap(hash.size()); diff --git a/src/main/java/org/springframework/data/redis/hash/HashMapper.java b/src/main/java/org/springframework/data/redis/hash/HashMapper.java index 4c6583406..711b15b77 100644 --- a/src/main/java/org/springframework/data/redis/hash/HashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/HashMapper.java @@ -18,8 +18,8 @@ package org.springframework.data.redis.hash; import java.util.Map; /** - * Core mapping contract between Java types and Redis hashes/maps. - * It's up to the implementation to support nested objects. + * Core mapping contract between Java types and Redis hashes/maps. It's up to the implementation to support nested + * objects. * * @author Costin Leau */ diff --git a/src/main/java/org/springframework/data/redis/hash/JacksonHashMapper.java b/src/main/java/org/springframework/data/redis/hash/JacksonHashMapper.java index cf98e0a01..0a67d341b 100644 --- a/src/main/java/org/springframework/data/redis/hash/JacksonHashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/JacksonHashMapper.java @@ -31,7 +31,8 @@ public class JacksonHashMapper implements HashMapper { private final ObjectMapper mapper; private final JavaType userType; - private final JavaType mapType = TypeFactory.defaultInstance().constructMapType(Map.class, String.class, Object.class); + private final JavaType mapType = TypeFactory.defaultInstance() + .constructMapType(Map.class, String.class, Object.class); public JacksonHashMapper(Class type) { this(type, new ObjectMapper()); @@ -43,12 +44,10 @@ public class JacksonHashMapper implements HashMapper { } @SuppressWarnings("unchecked") - public T fromHash(Map hash) { return (T) mapper.convertValue(hash, userType); } - public Map toHash(T object) { return mapper.convertValue(object, mapType); } diff --git a/src/main/java/org/springframework/data/redis/listener/ChannelTopic.java b/src/main/java/org/springframework/data/redis/listener/ChannelTopic.java index f4d162e54..f64a6fd0b 100644 --- a/src/main/java/org/springframework/data/redis/listener/ChannelTopic.java +++ b/src/main/java/org/springframework/data/redis/listener/ChannelTopic.java @@ -18,7 +18,7 @@ package org.springframework.data.redis.listener; import org.springframework.util.Assert; /** - * Channel topic implementation (maps to a Redis channel). + * Channel topic implementation (maps to a Redis channel). * * @author Costin Leau */ @@ -28,7 +28,7 @@ public class ChannelTopic implements Topic { /** * Constructs a new ChannelTopic instance. - * + * * @param name */ public ChannelTopic(String name) { @@ -38,7 +38,7 @@ public class ChannelTopic implements Topic { /** * Returns the topic name. - * + * * @return topic name */ public String getTopic() { @@ -66,8 +66,7 @@ public class ChannelTopic implements Topic { if (other.channelName != null) { return false; } - } - else if (!channelName.equals(other.channelName)) { + } else if (!channelName.equals(other.channelName)) { return false; } return true; @@ -77,4 +76,4 @@ public class ChannelTopic implements Topic { public String toString() { return channelName; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/listener/PatternTopic.java b/src/main/java/org/springframework/data/redis/listener/PatternTopic.java index a5619eaf5..e4052f969 100644 --- a/src/main/java/org/springframework/data/redis/listener/PatternTopic.java +++ b/src/main/java/org/springframework/data/redis/listener/PatternTopic.java @@ -56,8 +56,7 @@ public class PatternTopic implements Topic { if (other.channelPattern != null) { return false; } - } - else if (!channelPattern.equals(other.channelPattern)) { + } else if (!channelPattern.equals(other.channelPattern)) { return false; } return true; @@ -67,4 +66,4 @@ public class PatternTopic implements Topic { public String toString() { return channelPattern; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java index 72d814462..f449a680a 100644 --- a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java +++ b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java @@ -41,20 +41,17 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ErrorHandler; /** - * Container providing asynchronous behaviour for Redis message listeners. - * Handles the low level details of listening, converting and message dispatching. + * Container providing asynchronous behaviour for Redis message listeners. Handles the low level details of listening, + * converting and message dispatching. *

- * As oppose to the low level Redis (one connection per subscription), the container - * uses only one connection that is 'multiplexed' for all registered listeners, - * the message dispatch being done through the task executor. - * + * As oppose to the low level Redis (one connection per subscription), the container uses only one connection that is + * 'multiplexed' for all registered listeners, the message dispatch being done through the task executor. *

- * Note the container uses the connection in a lazy fashion (the connection is used only if at least one listener is configured). - * + * Note the container uses the connection in a lazy fashion (the connection is used only if at least one listener is + * configured). *

- * Adding and removing listeners at the same time has undefined results. It is strongly recommended to synchronize/order these - * methods accordingly. - * + * Adding and removing listeners at the same time has undefined results. It is strongly recommended to synchronize/order + * these methods accordingly. * * @author Costin Leau * @author Jennifer Hickey @@ -66,7 +63,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab /** Logger available to subclasses */ protected final Log logger = LogFactory.getLog(getClass()); - /** * Default thread name prefix: "RedisListeningContainer-". */ @@ -95,7 +91,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private ErrorHandler errorHandler; - private final Object monitor = new Object(); // whether the container is running (or not) private volatile boolean running = false; @@ -107,9 +102,9 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private volatile boolean manageExecutor = false; - // lookup maps - // to avoid creation of hashes for each message, the maps use raw byte arrays (wrapped to respect the equals/hashcode contract) + // to avoid creation of hashes for each message, the maps use raw byte arrays (wrapped to respect the equals/hashcode + // contract) // lookup map between patterns and listeners private final Map> patternMapping = new ConcurrentHashMap>(); @@ -121,7 +116,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private final SubscriptionTask subscriptionTask = new SubscriptionTask(); private volatile RedisSerializer serializer = new StringRedisSerializer(); - + private long recoveryInterval = DEFAULT_RECOVERY_INTERVAL; private long maxSubscriptionRegistrationWaitingTime = DEFAULT_SUBSCRIPTION_REGISTRATION_WAIT_TIME; @@ -141,8 +136,10 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab /** * Creates a default TaskExecutor. Called if no explicit TaskExecutor has been specified. - *

The default implementation builds a {@link org.springframework.core.task.SimpleAsyncTaskExecutor} - * with the specified bean name (or the class name, if no bean name specified) as thread name prefix. + *

+ * The default implementation builds a {@link org.springframework.core.task.SimpleAsyncTaskExecutor} with the + * specified bean name (or the class name, if no bean name specified) as thread name prefix. + * * @see org.springframework.core.task.SimpleAsyncTaskExecutor#SimpleAsyncTaskExecutor(String) */ protected TaskExecutor createDefaultTaskExecutor() { @@ -150,7 +147,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab return new SimpleAsyncTaskExecutor(threadNamePrefix); } - public void destroy() throws Exception { initialized = false; @@ -167,29 +163,24 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } - public boolean isAutoStartup() { return true; } - public void stop(Runnable callback) { stop(); callback.run(); } - public int getPhase() { // start the latest return Integer.MAX_VALUE; } - public boolean isRunning() { return running; } - public void start() { if (!running) { running = true; @@ -197,7 +188,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab // technically speaking we can only be notified right before the subscription starts synchronized (monitor) { lazyListen(); - if(listening) { + if (listening) { try { // wait up to 5 seconds for Subscription thread monitor.wait(initWait); @@ -213,7 +204,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } - public void stop() { if (isRunning()) { running = false; @@ -225,7 +215,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } - /** * Process a message received from the provider. * @@ -236,7 +225,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab executeListener(listener, message, pattern); } - /** * Execute the specified listener. * @@ -251,8 +239,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Return whether this container is currently active, - * that is, whether it has been set up but not shut down yet. + * Return whether this container is currently active, that is, whether it has been set up but not shut down yet. */ public final boolean isActive() { return initialized; @@ -260,8 +247,9 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab /** * Handle the given exception that arose during listener execution. - *

The default implementation logs the exception at error level. - * This can be overridden in subclasses. + *

+ * The default implementation logs the exception at error level. This can be overridden in subclasses. + * * @param ex the exception to handle */ protected void handleListenerException(Throwable ex) { @@ -269,8 +257,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab // Regular case: failed while active. // Invoke ErrorHandler if available. invokeErrorHandler(ex); - } - else { + } else { // Rare case: listener thread failed after container shutdown. // Log at debug level, to avoid spamming the shutdown logger. logger.debug("Listener exception after container shutdown", ex); @@ -279,21 +266,21 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab /** * Invoke the registered ErrorHandler, if any. Log at error level otherwise. + * * @param ex the uncaught error that arose during message processing. * @see #setErrorHandler */ protected void invokeErrorHandler(Throwable ex) { if (this.errorHandler != null) { this.errorHandler.handleError(ex); - } - else if (logger.isWarnEnabled()) { + } else if (logger.isWarnEnabled()) { logger.warn("Execution of JMS message listener failed, and no ErrorHandler has been set.", ex); } } /** * Returns the connectionFactory. - * + * * @return Returns the connectionFactory */ public RedisConnectionFactory getConnectionFactory() { @@ -307,17 +294,14 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab this.connectionFactory = connectionFactory; } - public void setBeanName(String name) { this.beanName = name; } - /** - * Sets the task executor used for running the message listeners when messages are received. - * If no task executor is set, an instance of {@link SimpleAsyncTaskExecutor} will be used by default. - * The task executor can be adjusted depending on the work done by the listeners and the number of - * messages coming in. + * Sets the task executor used for running the message listeners when messages are received. If no task executor is + * set, an instance of {@link SimpleAsyncTaskExecutor} will be used by default. The task executor can be adjusted + * depending on the work done by the listeners and the number of messages coming in. * * @param taskExecutor The taskExecutor to set. */ @@ -326,12 +310,12 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Sets the task execution used for subscribing to Redis channels. By default, if no executor is set, - * the {@link #setTaskExecutor(Executor)} will be used. In some cases, this might be undersired as - * the listening to the connection is a long running task. - * - *

Note: This implementation uses at most one long running thread (depending on whether there are any listeners registered or not) - * and up to two threads during the initial registration. + * Sets the task execution used for subscribing to Redis channels. By default, if no executor is set, the + * {@link #setTaskExecutor(Executor)} will be used. In some cases, this might be undersired as the listening to the + * connection is a long running task. + *

+ * Note: This implementation uses at most one long running thread (depending on whether there are any listeners + * registered or not) and up to two threads during the initial registration. * * @param subscriptionExecutor The subscriptionExecutor to set. */ @@ -340,8 +324,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Sets the serializer for converting the {@link Topic}s into low-level channels and patterns. - * By default, {@link StringRedisSerializer} is used. + * Sets the serializer for converting the {@link Topic}s into low-level channels and patterns. By default, + * {@link StringRedisSerializer} is used. * * @param serializer The serializer to set. */ @@ -350,9 +334,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown - * while processing a Message. By default there will be no ErrorHandler - * so that error-level logging is the only result. + * Set an ErrorHandler to be invoked in case of any uncaught exceptions thrown while processing a Message. By default + * there will be no ErrorHandler so that error-level logging is the only result. */ public void setErrorHandler(ErrorHandler errorHandler) { this.errorHandler = errorHandler; @@ -360,11 +343,10 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab /** * Attaches the given listeners (and their topics) to the container. - * *

- * Note: it's possible to call this method while the container is running forcing a reinitialization - * of the container. Note however that this might cause some messages to be lost (while the container - * reinitializes) - hence calling this method at runtime is considered advanced usage. + * Note: it's possible to call this method while the container is running forcing a reinitialization of the container. + * Note however that this might cause some messages to be lost (while the container reinitializes) - hence calling + * this method at runtime is considered advanced usage. * * @param listeners map of message listeners and their associated topics */ @@ -373,8 +355,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Adds a message listener to the (potentially running) container. If the container is running, - * the listener starts receiving (matching) messages as soon as possible. + * Adds a message listener to the (potentially running) container. If the container is running, the listener starts + * receiving (matching) messages as soon as possible. * * @param listener message listener * @param topics message listener topic @@ -385,8 +367,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Adds a message listener to the (potentially running) container. If the container is running, - * the listener starts receiving (matching) messages as soon as possible. + * Adds a message listener to the (potentially running) container. If the container is running, the listener starts + * receiving (matching) messages as soon as possible. * * @param listener message listener * @param topic message topic @@ -396,12 +378,11 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Removes a message listener from the given topics. If the container is running, - * the listener stops receiving (matching) messages as soon as possible. + * Removes a message listener from the given topics. If the container is running, the listener stops receiving + * (matching) messages as soon as possible. *

* Note that this method obeys the Redis (p)unsubscribe semantics - meaning an empty/null collection will remove - * listener from all channels. - * Similarly a null listener will unsubscribe all listeners from the given topic. + * listener from all channels. Similarly a null listener will unsubscribe all listeners from the given topic. * * @param listener message listener * @param topics message listener topics @@ -411,13 +392,12 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Removes a message listener from the from the given topic. If the container is running, - * the listener stops receiving (matching) messages as soon as possible. - * + * Removes a message listener from the from the given topic. If the container is running, the listener stops receiving + * (matching) messages as soon as possible. *

* Note that this method obeys the Redis (p)unsubscribe semantics - meaning an empty/null collection will remove * listener from all channels. Similarly a null listener will unsubscribe all listeners from the given topic. - * + * * @param listener message listener * @param topic message topic */ @@ -426,9 +406,9 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Removes the given message listener completely (from all topics). If the container is running, - * the listener stops receiving (matching) messages as soon as possible. - * Similarly a null listener will unsubscribe all listeners from the given topic. + * Removes the given message listener completely (from all topics). If the container is running, the listener stops + * receiving (matching) messages as soon as possible. Similarly a null listener will unsubscribe all listeners from + * the given topic. * * @param listener message listener */ @@ -479,8 +459,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab if (debug) { if (started) { logger.debug("Started listening for Redis messages"); - } - else { + } else { logger.debug("Postpone listening for Redis messages until actual listeners are added"); } } @@ -604,7 +583,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } - private void remove(MessageListener listener, Topic topic, ByteArrayWrapper holder, Map> mapping, List topicToRemove) { + private void remove(MessageListener listener, Topic topic, ByteArrayWrapper holder, + Map> mapping, List topicToRemove) { Collection listeners = mapping.get(holder); Collection listenersToRemove = null; @@ -631,7 +611,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab listenerTopics.remove(messageListener); } } - // if we removed everything, remove the empty holder collection + // if we removed everything, remove the empty holder collection if (listener == null || listeners.isEmpty()) { mapping.remove(holder); topicToRemove.add(holder.getArray()); @@ -640,17 +620,17 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Handle subscription task exception. Will attempt to restart the subscription - * if the Exception is a connection failure (for example, Redis was restarted). + * Handle subscription task exception. Will attempt to restart the subscription if the Exception is a connection + * failure (for example, Redis was restarted). + * * @param ex Throwable exception */ protected void handleSubscriptionException(Throwable ex) { listening = false; subscriptionTask.closeConnection(); - if(ex instanceof RedisConnectionFailureException) { - if(isRunning()) { - logger.error("Connection failure occurred. Restarting subscription task after " + - recoveryInterval + " ms"); + if (ex instanceof RedisConnectionFailureException) { + if (isRunning()) { + logger.error("Connection failure occurred. Restarting subscription task after " + recoveryInterval + " ms"); sleepBeforeRecoveryAttempt(); lazyListen(); } @@ -660,34 +640,31 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Sleep according to the specified recovery interval. - * Called between recovery attempts. + * Sleep according to the specified recovery interval. Called between recovery attempts. */ protected void sleepBeforeRecoveryAttempt() { if (this.recoveryInterval > 0) { try { Thread.sleep(this.recoveryInterval); - } - catch (InterruptedException interEx) { + } catch (InterruptedException interEx) { logger.debug("Thread interrupted while sleeping the recovery interval"); } } } - + /** - * Runnable used for Redis subscription. Implemented as a dedicated class to provide as many hints - * as possible to the underlying thread pool. + * Runnable used for Redis subscription. Implemented as a dedicated class to provide as many hints as possible to the + * underlying thread pool. * * @author Costin Leau */ private class SubscriptionTask implements SchedulingAwareRunnable { /** - * Runnable used, on a parallel thread, to do the initial pSubscribe. - * This is required since, during initialization, both subscribe and pSubscribe - * might be needed but since the first call is blocking, the second call needs to + * Runnable used, on a parallel thread, to do the initial pSubscribe. This is required since, during initialization, + * both subscribe and pSubscribe might be needed but since the first call is blocking, the second call needs to * executed in parallel. - * + * * @author Costin Leau */ private class PatternSubscriptionTask implements SchedulingAwareRunnable { @@ -695,12 +672,10 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private long WAIT = 500; private long ROUNDS = 3; - public boolean isLongLived() { return false; } - public void run() { // wait for subscription to be initialized boolean done = false; @@ -711,8 +686,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab if (connection.isSubscribed()) { done = true; connection.getSubscription().pSubscribe(unwrap(patternMapping.keySet())); - } - else { + } else { try { Thread.sleep(WAIT); } catch (InterruptedException ex) { @@ -734,7 +708,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab return true; } - public void run() { synchronized (localMonitor) { subscriptionTaskRunning = true; @@ -748,7 +721,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab boolean asyncConnection = ConnectionUtils.isAsync(connectionFactory); // NB: async drivers' Xsubscribe calls block, so we notify the RDMLC before performing the actual subscription. - if(!asyncConnection){ + if (!asyncConnection) { synchronized (monitor) { monitor.notify(); } @@ -756,11 +729,10 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab SubscriptionPresentCondition subscriptionPresent = eventuallyPerformSubscription(); - - if(asyncConnection){ + if (asyncConnection) { SpinBarrier.waitFor(subscriptionPresent, getMaxSubscriptionRegistrationWaitingTime()); - synchronized (monitor){ + synchronized (monitor) { monitor.notify(); } } @@ -778,7 +750,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab /** * Performs a potentially asynchronous registration of a subscription. - * + * * @return #SubscriptionPresentCondition that can serve as a handle to check whether the subscription is ready. */ private SubscriptionPresentCondition eventuallyPerformSubscription() { @@ -806,9 +778,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * * Checks whether the current connection has an associated subscription. - * + * * @author Thomas Darimont */ private class SubscriptionPresentCondition implements Condition { @@ -820,9 +791,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab /** * Checks whether the current connection has an associated pattern subscription. - * + * * @author Thomas Darimont - * * @see org.springframework.data.redis.listener.RedisMessageListenerContainer.SubscriptionTask.SubscriptionPresentTestCondition */ private class PatternSubscriptionPresentCondition extends SubscriptionPresentCondition { @@ -860,20 +830,20 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab if (connection != null) { Subscription sub = connection.getSubscription(); if (sub != null) { - synchronized(localMonitor) { + synchronized (localMonitor) { logger.trace("Unsubscribing from all channels"); sub.pUnsubscribe(); sub.unsubscribe(); - if(subscriptionTaskRunning) { + if (subscriptionTaskRunning) { try { localMonitor.wait(subscriptionWait); } catch (InterruptedException e) { // Stop waiting } } - if(!subscriptionTaskRunning) { + if (!subscriptionTaskRunning) { closeConnection(); - }else { + } else { logger.warn("Unable to close connection. Subscription task still running"); } } @@ -882,11 +852,11 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } void closeConnection() { - if(connection != null) { + if (connection != null) { logger.trace("Closing connection"); try { connection.close(); - } catch(Exception e) { + } catch (Exception e) { logger.warn("Error closing subscription connection", e); } connection = null; @@ -935,7 +905,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab void unsubscribePattern(byte[]... patterns) { if (patterns != null && patterns.length > 0) { if (connection != null) { - synchronized(localMonitor) { + synchronized (localMonitor) { Subscription sub = connection.getSubscription(); if (sub != null) { sub.pUnsubscribe(patterns); @@ -959,8 +929,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab // if it's a pattern, disregard channel if (pattern != null && pattern.length > 0) { listeners = patternMapping.get(new ByteArrayWrapper(pattern)); - } - else { + } else { pattern = null; // do channel matching first listeners = channelMapping.get(new ByteArrayWrapper(message.getChannel())); @@ -985,8 +954,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Specify the interval between recovery attempts, in milliseconds. - * The default is 5000 ms, that is, 5 seconds. + * Specify the interval between recovery attempts, in milliseconds. The default is 5000 ms, that is, 5 seconds. + * * @see #handleSubscriptionException */ public void setRecoveryInterval(long recoveryInterval) { @@ -998,11 +967,10 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } /** - * Specify the max time to wait for subscription registrations, in milliseconds. - * The default is 2000ms, that is, 2 second. - * + * Specify the max time to wait for subscription registrations, in milliseconds. The default is 2000ms, that + * is, 2 second. + * * @param maxSubscriptionRegistrationWaitingTime - * * @see #DEFAULT_SUBSCRIPTION_REGISTRATION_WAIT_TIME */ public void setMaxSubscriptionRegistrationWaitingTime(long maxSubscriptionRegistrationWaitingTime) { @@ -1011,28 +979,23 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab /** * @author Jennifer Hickey - * @author Thomas Darimont - * - * Note: Placed here to avoid API exposure. + * @author Thomas Darimont Note: Placed here to avoid API exposure. */ private static abstract class SpinBarrier { - + /** * Periodically tests, in 100ms intervals, for a condition until it is met or a timeout occurs. - * - * @param condition - * The condition to periodically test - * @param timeout - * The timeout - * @return true if condition passes, false if condition does not pass within - * timeout + * + * @param condition The condition to periodically test + * @param timeout The timeout + * @return true if condition passes, false if condition does not pass within timeout */ - static boolean waitFor(Condition condition, long timeout) { - - long startTime=System.currentTimeMillis(); - - while(!timedOut(startTime, timeout)) { - if(condition.passes()) { + static boolean waitFor(Condition condition, long timeout) { + + long startTime = System.currentTimeMillis(); + + while (!timedOut(startTime, timeout)) { + if (condition.passes()) { return true; } try { @@ -1043,28 +1006,24 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } return false; } - + private static boolean timedOut(long startTime, long timeout) { return (startTime + timeout) < System.currentTimeMillis(); } } - + /** - * * A condition to test periodically, used in conjunction with * {@link org.springframework.data.redis.listener.RedisMessageListenerContainer.SpinBarrier} - * + * * @author Jennifer Hickey - * @author Thomas Darimont - * - * Note: Placed here to avoid API exposure. + * @author Thomas Darimont Note: Placed here to avoid API exposure. */ private static interface Condition { /** - * * @return true if condition passes */ boolean passes(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/listener/Topic.java b/src/main/java/org/springframework/data/redis/listener/Topic.java index 288fc31d9..add7fe24f 100644 --- a/src/main/java/org/springframework/data/redis/listener/Topic.java +++ b/src/main/java/org/springframework/data/redis/listener/Topic.java @@ -16,8 +16,7 @@ package org.springframework.data.redis.listener; /** - * Topic for a Redis message. Acts a high-level abstraction on top - * of Redis low-level channels or patterns. + * Topic for a Redis message. Acts a high-level abstraction on top of Redis low-level channels or patterns. * * @author Costin Leau */ diff --git a/src/main/java/org/springframework/data/redis/listener/adapter/MessageListenerAdapter.java b/src/main/java/org/springframework/data/redis/listener/adapter/MessageListenerAdapter.java index a6d8dd423..1e9b8fb31 100644 --- a/src/main/java/org/springframework/data/redis/listener/adapter/MessageListenerAdapter.java +++ b/src/main/java/org/springframework/data/redis/listener/adapter/MessageListenerAdapter.java @@ -39,37 +39,26 @@ import org.springframework.util.ReflectionUtils.MethodFilter; import org.springframework.util.StringUtils; /** - * Message listener adapter that delegates the handling of messages to target - * listener methods via reflection, with flexible message type conversion. - * Allows listener methods to operate on message content types, completely - * independent from the Redis API. - * - *

Make sure to call {@link #afterPropertiesSet()} after setting all the parameters - * on the adapter. - * - *

Note that if the underlying "delegate" is implementing {@link MessageListener}, the adapter - * will delegate to it and allow an invalid method to be specified. However if it is not, the method - * becomes mandatory. - * This lenient behavior allows the adapter to be used uniformly across existing listeners and message POJOs. - * + * Message listener adapter that delegates the handling of messages to target listener methods via reflection, with + * flexible message type conversion. Allows listener methods to operate on message content types, completely independent + * from the Redis API. *

- * Modeled as much as possible after the JMS MessageListenerAdapter in Spring - * Framework. - * + * Make sure to call {@link #afterPropertiesSet()} after setting all the parameters on the adapter. + *

+ * Note that if the underlying "delegate" is implementing {@link MessageListener}, the adapter will delegate to it and + * allow an invalid method to be specified. However if it is not, the method becomes mandatory. This lenient behavior + * allows the adapter to be used uniformly across existing listeners and message POJOs. + *

+ * Modeled as much as possible after the JMS MessageListenerAdapter in Spring Framework. *

- * By default, the content of incoming Redis messages gets extracted before - * being passed into the target listener method, to let the target method - * operate on message content types such as String or byte array instead of the - * raw {@link Message}. Message type conversion is delegated to a Spring Data - * {@link RedisSerializer}. By default, the - * {@link JdkSerializationRedisSerializer} will be used. (If you do not want - * such automatic message conversion taking place, then be sure to set the - * {@link #setSerializer Serializer} to null.) - * + * By default, the content of incoming Redis messages gets extracted before being passed into the target listener + * method, to let the target method operate on message content types such as String or byte array instead of the raw + * {@link Message}. Message type conversion is delegated to a Spring Data {@link RedisSerializer}. By default, the + * {@link JdkSerializationRedisSerializer} will be used. (If you do not want such automatic message conversion taking + * place, then be sure to set the {@link #setSerializer Serializer} to null.) *

- * Find below some examples of method signatures compliant with this adapter - * class. This first example handles all Message types and gets - * passed the contents of each Message type as an argument. + * Find below some examples of method signatures compliant with this adapter class. This first example handles all + * Message types and gets passed the contents of each Message type as an argument. * *

  * public interface MessageContentsDelegate {
@@ -80,11 +69,10 @@ import org.springframework.util.StringUtils;
  * 	void handleMessage(Person obj);
  * }
  * 
- * *

- * In addition, the channel or pattern to which a message is sent can be passed in - * to the method as a second argument of type String: - * + * In addition, the channel or pattern to which a message is sent can be passed in to the method as a second argument of + * type String: + * *

  * public interface MessageContentsDelegate {
  * 	void handleMessage(String text, String channel);
@@ -93,15 +81,10 @@ import org.springframework.util.StringUtils;
  * }
  * 
* - * - * For further examples and discussion please do refer to the Spring Data - * reference documentation which describes this class (and its attendant - * configuration) in detail. - * - * Important: Due to the nature of messages, the default serializer used - * by the adapter is {@link StringRedisSerializer}. If the messages are of a - * different type, change them accordingly through - * {@link #setSerializer(RedisSerializer)}. + * For further examples and discussion please do refer to the Spring Data reference documentation which describes this + * class (and its attendant configuration) in detail. Important: Due to the nature of messages, the default + * serializer used by the adapter is {@link StringRedisSerializer}. If the messages are of a different type, change them + * accordingly through {@link #setSerializer(RedisSerializer)}. * * @author Juergen Hoeller * @author Costin Leau @@ -147,8 +130,7 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener }); Assert.isTrue(lenient || !methods.isEmpty(), "Cannot find a suitable method named [" + c.getName() + "#" - + methodName - + "] - is the method public and has the proper arguments?"); + + methodName + "] - is the method public and has the proper arguments?"); } void invoke(Object[] arguments) throws InvocationTargetException, IllegalAccessException { @@ -163,7 +145,7 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener /** * Returns the current methodName. - * + * * @return the methodName */ public String getMethodName() { @@ -200,20 +182,18 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener /** * Create a new {@link MessageListenerAdapter} for the given delegate. * - * @param delegate - * the delegate object + * @param delegate the delegate object */ public MessageListenerAdapter(Object delegate) { initDefaultStrategies(); setDelegate(delegate); } - + /** * Create a new {@link MessageListenerAdapter} for the given delegate. * * @param delegate the delegate object * @param defaultListenerMethod method to call when a message comes - * * @see #getListenerMethodName */ public MessageListenerAdapter(Object delegate, String defaultListenerMethod) { @@ -222,15 +202,13 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener } /** - * Set a target object to delegate message listening to. Specified listener - * methods have to be present on this target object. + * Set a target object to delegate message listening to. Specified listener methods have to be present on this target + * object. *

- * If no explicit delegate object has been specified, listener methods are - * expected to present on this adapter instance, that is, on a custom - * subclass of this adapter, defining listener methods. + * If no explicit delegate object has been specified, listener methods are expected to present on this adapter + * instance, that is, on a custom subclass of this adapter, defining listener methods. * - * @param delegate - * delegate object + * @param delegate delegate object */ public void setDelegate(Object delegate) { Assert.notNull(delegate, "Delegate must not be null"); @@ -247,10 +225,8 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener } /** - * Specify the name of the default listener method to delegate to, for the - * case where no specific listener method has been determined. - * Out-of-the-box value is {@link #ORIGINAL_DEFAULT_LISTENER_METHOD - * "handleMessage"}. + * Specify the name of the default listener method to delegate to, for the case where no specific listener method has + * been determined. Out-of-the-box value is {@link #ORIGINAL_DEFAULT_LISTENER_METHOD "handleMessage"}. * * @see #getListenerMethodName */ @@ -266,8 +242,7 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener } /** - * Set the serializer that will convert incoming raw Redis messages to - * listener method arguments. + * Set the serializer that will convert incoming raw Redis messages to listener method arguments. *

* The default converter is a {@link StringRedisSerializer}. * @@ -279,7 +254,6 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener /** * Sets the serializer used for converting the channel/pattern to a String. - * *

* The default converter is a {@link StringRedisSerializer}. * @@ -289,7 +263,6 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener this.stringSerializer = serializer; } - public void afterPropertiesSet() { String methodName = getDefaultListenerMethod(); @@ -305,15 +278,13 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener /** * Standard Redis {@link MessageListener} entry point. *

- * Delegates the message to the target listener method, with appropriate - * conversion of the message argument. In case of an exception, the - * {@link #handleListenerException(Throwable)} method will be invoked. + * Delegates the message to the target listener method, with appropriate conversion of the message argument. In case + * of an exception, the {@link #handleListenerException(Throwable)} method will be invoked. * - * @param message - * the incoming Redis message + * @param message the incoming Redis message * @see #handleListenerException */ - + public void onMessage(Message message, byte[] pattern) { try { // Check whether the delegate is a MessageListener impl itself. @@ -350,11 +321,10 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener } /** - * Handle the given exception that arose during listener execution. The - * default implementation logs the exception at error level. + * Handle the given exception that arose during listener execution. The default implementation logs the exception at + * error level. * - * @param ex - * the exception to handle + * @param ex the exception to handle */ protected void handleListenerException(Throwable ex) { logger.error("Listener execution failed", ex); @@ -363,10 +333,8 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener /** * Extract the message body from the given Redis message. * - * @param message - * the Redis Message - * @return the content of the message, to be passed into the listener method - * as argument + * @param message the Redis Message + * @return the content of the message, to be passed into the listener method as argument */ protected Object extractMessage(Message message) { if (serializer != null) { @@ -376,17 +344,12 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener } /** - * Determine the name of the listener method that is supposed to handle the - * given message. + * Determine the name of the listener method that is supposed to handle the given message. *

- * The default implementation simply returns the configured default listener - * method, if any. + * The default implementation simply returns the configured default listener method, if any. * - * @param originalMessage - * the Redis request message - * @param extractedMessage - * the converted Redis request message, to be passed into the - * listener method as argument + * @param originalMessage the Redis request message + * @param extractedMessage the converted Redis request message, to be passed into the listener method as argument * @return the name of the listener method (never null) * @see #setDefaultListenerMethod */ @@ -397,10 +360,8 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener /** * Invoke the specified listener method. * - * @param methodName - * the name of the listener method - * @param arguments - * the message arguments to be passed in + * @param methodName the name of the listener method + * @param arguments the message arguments to be passed in * @see #getListenerMethodName */ protected void invokeListenerMethod(String methodName, Object[] arguments) { @@ -410,8 +371,7 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener Throwable targetEx = ex.getTargetException(); if (targetEx instanceof DataAccessException) { throw (DataAccessException) targetEx; - } - else { + } else { throw new RedisListenerExecutionFailedException("Listener method '" + methodName + "' threw exception", targetEx); } @@ -420,4 +380,4 @@ public class MessageListenerAdapter implements InitializingBean, MessageListener + "' with arguments " + ObjectUtils.nullSafeToString(arguments), ex); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/listener/adapter/RedisListenerExecutionFailedException.java b/src/main/java/org/springframework/data/redis/listener/adapter/RedisListenerExecutionFailedException.java index 00c609a1b..91bf8c0a4 100644 --- a/src/main/java/org/springframework/data/redis/listener/adapter/RedisListenerExecutionFailedException.java +++ b/src/main/java/org/springframework/data/redis/listener/adapter/RedisListenerExecutionFailedException.java @@ -18,7 +18,7 @@ package org.springframework.data.redis.listener.adapter; import org.springframework.dao.InvalidDataAccessApiUsageException; /** - * Exception thrown when the execution of a listener method failed. + * Exception thrown when the execution of a listener method failed. * * @author Costin Leau * @see MessageListenerAdapter @@ -27,7 +27,7 @@ public class RedisListenerExecutionFailedException extends InvalidDataAccessApiU /** * Constructs a new RedisListenerExecutionFailedException instance. - * + * * @param msg * @param cause */ @@ -37,7 +37,7 @@ public class RedisListenerExecutionFailedException extends InvalidDataAccessApiU /** * Constructs a new RedisListenerExecutionFailedException instance. - * + * * @param msg */ public RedisListenerExecutionFailedException(String msg) { diff --git a/src/main/java/org/springframework/data/redis/serializer/GenericToStringSerializer.java b/src/main/java/org/springframework/data/redis/serializer/GenericToStringSerializer.java index 563a42fd6..067ed077c 100644 --- a/src/main/java/org/springframework/data/redis/serializer/GenericToStringSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/GenericToStringSerializer.java @@ -27,15 +27,11 @@ import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.util.Assert; /** - * Generic String to byte[] (and back) serializer. Relies on the Spring {@link ConversionService} - * to transform objects into String and vice versa. The Strings are convert into bytes and vice-versa - * using the specified charset (by default UTF-8). - * - * Note: The conversion service initialization happens automatically if the class is defined - * as a Spring bean. + * Generic String to byte[] (and back) serializer. Relies on the Spring {@link ConversionService} to transform objects + * into String and vice versa. The Strings are convert into bytes and vice-versa using the specified charset (by default + * UTF-8). Note: The conversion service initialization happens automatically if the class is defined as a Spring + * bean. Note: Does not handle nulls in any special way delegating everything to the container. * - * Note: Does not handle nulls in any special way delegating everything to the container. - * * @author Costin Leau */ public class GenericToStringSerializer implements RedisSerializer, BeanFactoryAware { @@ -64,7 +60,6 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac converter = new Converter(typeConverter); } - public T deserialize(byte[] bytes) { if (bytes == null) { return null; @@ -74,7 +69,6 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac return converter.convert(string, type); } - public byte[] serialize(T object) { if (object == null) { return null; @@ -83,14 +77,12 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac return string.getBytes(charset); } - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (converter == null && beanFactory instanceof ConfigurableBeanFactory) { ConfigurableBeanFactory cFB = (ConfigurableBeanFactory) beanFactory; ConversionService conversionService = cFB.getConversionService(); - converter = (conversionService != null ? new Converter(conversionService) : new Converter( - cFB.getTypeConverter())); + converter = (conversionService != null ? new Converter(conversionService) : new Converter(cFB.getTypeConverter())); } } @@ -115,4 +107,4 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac return typeConverter.convertIfNecessary(value, targetType); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java index 19e0ea7c2..a752ab4e3 100644 --- a/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializer.java @@ -49,7 +49,7 @@ public class Jackson2JsonRedisSerializer implements RedisSerializer { @SuppressWarnings("unchecked") public T deserialize(byte[] bytes) throws SerializationException { - + if (SerializationUtils.isEmpty(bytes)) { return null; } @@ -61,7 +61,7 @@ public class Jackson2JsonRedisSerializer implements RedisSerializer { } public byte[] serialize(Object t) throws SerializationException { - + if (t == null) { return SerializationUtils.EMPTY_ARRAY; } @@ -82,7 +82,7 @@ public class Jackson2JsonRedisSerializer implements RedisSerializer { * the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary. */ public void setObjectMapper(ObjectMapper objectMapper) { - + Assert.notNull(objectMapper, "'objectMapper' must not be null"); this.objectMapper = objectMapper; } diff --git a/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java index cb59e1c5a..544b7467d 100644 --- a/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/JacksonJsonRedisSerializer.java @@ -23,12 +23,12 @@ import org.springframework.util.Assert; import java.nio.charset.Charset; /** - * {@link RedisSerializer} that can read and write JSON using Jackson's {@link ObjectMapper}. - * - *

This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances. - * + * {@link RedisSerializer} that can read and write JSON using Jackson's + * {@link ObjectMapper}. + *

+ * This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances. * Note:Null objects are serialized as empty arrays and vice versa. - * + * * @author Costin Leau * @author Thomas Darimont */ @@ -45,7 +45,6 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { } @SuppressWarnings("unchecked") - public T deserialize(byte[] bytes) throws SerializationException { if (SerializationUtils.isEmpty(bytes)) { return null; @@ -57,7 +56,6 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { } } - public byte[] serialize(Object t) throws SerializationException { if (t == null) { return SerializationUtils.EMPTY_ARRAY; @@ -70,12 +68,14 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { } /** - * Sets the {@code ObjectMapper} for this view. If not set, a default - * {@link ObjectMapper#ObjectMapper() ObjectMapper} is used. - *

Setting a custom-configured {@code ObjectMapper} is one way to take further control of the JSON serialization - * process. For example, an extended {@link org.codehaus.jackson.map.SerializerFactory} can be configured that provides - * custom serializers for specific types. The other option for refining the serialization process is to use Jackson's - * provided annotations on the types to be serialized, in which case a custom-configured ObjectMapper is unnecessary. + * Sets the {@code ObjectMapper} for this view. If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} + * is used. + *

+ * Setting a custom-configured {@code ObjectMapper} is one way to take further control of the JSON serialization + * process. For example, an extended {@link org.codehaus.jackson.map.SerializerFactory} can be configured that + * provides custom serializers for specific types. The other option for refining the serialization process is to use + * Jackson's provided annotations on the types to be serialized, in which case a custom-configured ObjectMapper is + * unnecessary. */ public void setObjectMapper(ObjectMapper objectMapper) { Assert.notNull(objectMapper, "'objectMapper' must not be null"); @@ -84,23 +84,24 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { /** * Returns the Jackson {@link JavaType} for the specific class. - * - *

Default implementation returns {@link TypeFactory#type(java.lang.reflect.Type)}, but this can be overridden - * in subclasses, to allow for custom generic collection handling. For instance: + *

+ * Default implementation returns {@link TypeFactory#type(java.lang.reflect.Type)}, but this can be overridden in + * subclasses, to allow for custom generic collection handling. For instance: + * *

 	 * protected JavaType getJavaType(Class<?> clazz) {
-	 *   if (List.class.isAssignableFrom(clazz)) {
-	 *     return TypeFactory.collectionType(ArrayList.class, MyBean.class);
-	 *   } else {
-	 *     return super.getJavaType(clazz);
-	 *   }
+	 * 	if (List.class.isAssignableFrom(clazz)) {
+	 * 		return TypeFactory.collectionType(ArrayList.class, MyBean.class);
+	 * 	} else {
+	 * 		return super.getJavaType(clazz);
+	 * 	}
 	 * }
 	 * 
- * + * * @param clazz the class to return the java type for * @return the java type */ protected JavaType getJavaType(Class clazz) { return TypeFactory.defaultInstance().constructType(clazz); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java index e6cf82d04..e45612aa4 100644 --- a/src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/JdkSerializationRedisSerializer.java @@ -20,8 +20,7 @@ import org.springframework.core.serializer.support.DeserializingConverter; import org.springframework.core.serializer.support.SerializingConverter; /** - * Java Serialization Redis serializer. - * Delegates to the default (Java based) serializer in Spring 3. + * Java Serialization Redis serializer. Delegates to the default (Java based) serializer in Spring 3. * * @author Mark Pollack * @author Costin Leau @@ -43,7 +42,6 @@ public class JdkSerializationRedisSerializer implements RedisSerializer } } - public byte[] serialize(Object object) { if (object == null) { return SerializationUtils.EMPTY_ARRAY; @@ -54,4 +52,4 @@ public class JdkSerializationRedisSerializer implements RedisSerializer throw new SerializationException("Cannot serialize", ex); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/serializer/OxmSerializer.java b/src/main/java/org/springframework/data/redis/serializer/OxmSerializer.java index 072fcb018..0555f2ab9 100644 --- a/src/main/java/org/springframework/data/redis/serializer/OxmSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/OxmSerializer.java @@ -27,11 +27,8 @@ import org.springframework.oxm.Unmarshaller; import org.springframework.util.Assert; /** - * Serializer adapter on top of Spring's O/X Mapping. - * Delegates serialization/deserialization to OXM {@link Marshaller} and - * {@link Unmarshaller}. - * - * Note:Null objects are serialized as empty arrays and vice versa. + * Serializer adapter on top of Spring's O/X Mapping. Delegates serialization/deserialization to OXM {@link Marshaller} + * and {@link Unmarshaller}. Note:Null objects are serialized as empty arrays and vice versa. * * @author Costin Leau */ @@ -40,8 +37,7 @@ public class OxmSerializer implements InitializingBean, RedisSerializer private Marshaller marshaller; private Unmarshaller unmarshaller; - public OxmSerializer() { - } + public OxmSerializer() {} public OxmSerializer(Marshaller marshaller, Unmarshaller unmarshaller) { this.marshaller = marshaller; @@ -50,7 +46,6 @@ public class OxmSerializer implements InitializingBean, RedisSerializer afterPropertiesSet(); } - public void afterPropertiesSet() { Assert.notNull(marshaller, "non-null marshaller required"); Assert.notNull(unmarshaller, "non-null unmarshaller required"); @@ -70,7 +65,6 @@ public class OxmSerializer implements InitializingBean, RedisSerializer this.unmarshaller = unmarshaller; } - public Object deserialize(byte[] bytes) throws SerializationException { if (SerializationUtils.isEmpty(bytes)) { return null; @@ -83,7 +77,6 @@ public class OxmSerializer implements InitializingBean, RedisSerializer } } - public byte[] serialize(Object t) throws SerializationException { if (t == null) { return SerializationUtils.EMPTY_ARRAY; @@ -99,4 +92,4 @@ public class OxmSerializer implements InitializingBean, RedisSerializer } return stream.toByteArray(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/serializer/RedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/RedisSerializer.java index abdc4f80f..434fa73ad 100644 --- a/src/main/java/org/springframework/data/redis/serializer/RedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/RedisSerializer.java @@ -16,10 +16,9 @@ package org.springframework.data.redis.serializer; /** - * Basic interface serialization and deserialization of Objects to byte arrays (binary data). - * - * It is recommended that implementations are designed to handle null objects/empty arrays on serialization and deserialization side. - * Note that Redis does not accept null keys or values but can return null replies (for non existing keys). + * Basic interface serialization and deserialization of Objects to byte arrays (binary data). It is recommended that + * implementations are designed to handle null objects/empty arrays on serialization and deserialization side. Note that + * Redis does not accept null keys or values but can return null replies (for non existing keys). * * @author Mark Pollack * @author Costin Leau diff --git a/src/main/java/org/springframework/data/redis/serializer/SerializationException.java b/src/main/java/org/springframework/data/redis/serializer/SerializationException.java index 76ab7d20c..6397de261 100644 --- a/src/main/java/org/springframework/data/redis/serializer/SerializationException.java +++ b/src/main/java/org/springframework/data/redis/serializer/SerializationException.java @@ -26,7 +26,7 @@ public class SerializationException extends NestedRuntimeException { /** * Constructs a new SerializationException instance. - * + * * @param msg * @param cause */ @@ -36,7 +36,7 @@ public class SerializationException extends NestedRuntimeException { /** * Constructs a new SerializationException instance. - * + * * @param msg */ public SerializationException(String msg) { diff --git a/src/main/java/org/springframework/data/redis/serializer/SerializationUtils.java b/src/main/java/org/springframework/data/redis/serializer/SerializationUtils.java index e94257aee..36b7566d3 100644 --- a/src/main/java/org/springframework/data/redis/serializer/SerializationUtils.java +++ b/src/main/java/org/springframework/data/redis/serializer/SerializationUtils.java @@ -36,9 +36,9 @@ public abstract class SerializationUtils { return (data == null || data.length == 0); } - @SuppressWarnings("unchecked") - static > T deserializeValues(Collection rawValues, Class type, RedisSerializer redisSerializer) { + static > T deserializeValues(Collection rawValues, Class type, + RedisSerializer redisSerializer) { // connection in pipeline/multi mode if (rawValues == null) { return null; @@ -68,34 +68,31 @@ public abstract class SerializationUtils { return deserializeValues(rawValues, List.class, redisSerializer); } - public static Map deserialize(Map rawValues, - RedisSerializer redisSerializer) { + public static Map deserialize(Map rawValues, RedisSerializer redisSerializer) { if (rawValues == null) { return null; } Map ret = new LinkedHashMap(rawValues.size()); for (Map.Entry entry : rawValues.entrySet()) { - ret.put(redisSerializer.deserialize(entry.getKey()), - redisSerializer.deserialize(entry.getValue())); + ret.put(redisSerializer.deserialize(entry.getKey()), redisSerializer.deserialize(entry.getValue())); } return ret; } @SuppressWarnings("unchecked") - public static Map deserialize(Map rawValues, - RedisSerializer hashKeySerializer, RedisSerializer hashValueSerializer) { + public static Map deserialize(Map rawValues, RedisSerializer hashKeySerializer, + RedisSerializer hashValueSerializer) { if (rawValues == null) { return null; } Map map = new LinkedHashMap(rawValues.size()); for (Map.Entry entry : rawValues.entrySet()) { // May want to deserialize only key or value - HK key = hashKeySerializer != null ? (HK) hashKeySerializer.deserialize(entry.getKey()) : - (HK) entry.getKey(); - HV value = hashValueSerializer != null ? (HV) hashValueSerializer.deserialize(entry.getValue()) : - (HV) entry.getValue(); + HK key = hashKeySerializer != null ? (HK) hashKeySerializer.deserialize(entry.getKey()) : (HK) entry.getKey(); + HV value = hashValueSerializer != null ? (HV) hashValueSerializer.deserialize(entry.getValue()) : (HV) entry + .getValue(); map.put(key, value); } return map; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/serializer/StringRedisSerializer.java b/src/main/java/org/springframework/data/redis/serializer/StringRedisSerializer.java index 260dd627d..dea8d61b6 100644 --- a/src/main/java/org/springframework/data/redis/serializer/StringRedisSerializer.java +++ b/src/main/java/org/springframework/data/redis/serializer/StringRedisSerializer.java @@ -20,12 +20,12 @@ import java.nio.charset.Charset; import org.springframework.util.Assert; /** - * Simple String to byte[] (and back) serializer. Converts Strings into bytes and vice-versa - * using the specified charset (by default UTF-8). - *

+ * Simple String to byte[] (and back) serializer. Converts Strings into bytes and vice-versa using the specified charset + * (by default UTF-8). + *

* Useful when the interaction with the Redis happens mainly through Strings. - * - *

Does not perform any null conversion since empty strings are valid keys/values. + *

+ * Does not perform any null conversion since empty strings are valid keys/values. * * @author Costin Leau */ @@ -42,13 +42,11 @@ public class StringRedisSerializer implements RedisSerializer { this.charset = charset; } - public String deserialize(byte[] bytes) { return (bytes == null ? null : new String(bytes, charset)); } - public byte[] serialize(String string) { return (string == null ? null : string.getBytes(charset)); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicDouble.java b/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicDouble.java index b14d20966..916a32a15 100644 --- a/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicDouble.java +++ b/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicDouble.java @@ -32,9 +32,9 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.util.Assert; /** - * Atomic double backed by Redis. Uses Redis atomic increment/decrement and watch/multi/exec - * operations for CAS operations. - * + * Atomic double backed by Redis. Uses Redis atomic increment/decrement and watch/multi/exec operations for CAS + * operations. + * * @author Jennifer Hickey */ @SuppressWarnings("serial") @@ -45,13 +45,10 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO private RedisOperations generalOps; /** - * Constructs a new RedisAtomicDouble instance. Uses the value existing in Redis or - * 0 if none is found. - * - * @param redisCounter - * redis counter - * @param factory - * connection factory + * Constructs a new RedisAtomicDouble instance. Uses the value existing in Redis or 0 if none is found. + * + * @param redisCounter redis counter + * @param factory connection factory */ public RedisAtomicDouble(String redisCounter, RedisConnectionFactory factory) { this(redisCounter, factory, null); @@ -59,18 +56,16 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Constructs a new RedisAtomicDouble instance. - * + * * @param redisCounter * @param factory * @param initialValue */ - public RedisAtomicDouble(String redisCounter, RedisConnectionFactory factory, - double initialValue) { + public RedisAtomicDouble(String redisCounter, RedisConnectionFactory factory, double initialValue) { this(redisCounter, factory, Double.valueOf(initialValue)); } - private RedisAtomicDouble(String redisCounter, RedisConnectionFactory factory, - Double initialValue) { + private RedisAtomicDouble(String redisCounter, RedisConnectionFactory factory, Double initialValue) { Assert.hasText(redisCounter, "a valid counter name is required"); Assert.notNull(factory, "a valid factory is required"); @@ -95,13 +90,10 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO } /** - * Constructs a new RedisAtomicDouble instance. Uses the value existing in Redis or - * 0 if none is found. - * - * @param redisCounter - * the redis counter - * @param template - * the template + * Constructs a new RedisAtomicDouble instance. Uses the value existing in Redis or 0 if none is found. + * + * @param redisCounter the redis counter + * @param template the template */ public RedisAtomicDouble(String redisCounter, RedisOperations template) { this(redisCounter, template, null); @@ -109,21 +101,16 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Constructs a new RedisAtomicDouble instance. - * - * @param redisCounter - * the redis counter - * @param template - * the template - * @param initialValue - * the initial value + * + * @param redisCounter the redis counter + * @param template the template + * @param initialValue the initial value */ - public RedisAtomicDouble(String redisCounter, RedisOperations template, - double initialValue) { + public RedisAtomicDouble(String redisCounter, RedisOperations template, double initialValue) { this(redisCounter, template, Double.valueOf(initialValue)); } - private RedisAtomicDouble(String redisCounter, RedisOperations template, - Double initialValue) { + private RedisAtomicDouble(String redisCounter, RedisOperations template, Double initialValue) { Assert.hasText(redisCounter, "a valid counter name is required"); Assert.notNull(template, "a valid template is required"); @@ -142,7 +129,7 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Gets the current value. - * + * * @return the current value */ public double get() { @@ -151,9 +138,8 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Sets to the given value. - * - * @param newValue - * the new value + * + * @param newValue the new value */ public void set(double newValue) { operations.set(key, newValue); @@ -161,9 +147,8 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Atomically sets to the given value and returns the old value. - * - * @param newValue - * the new value + * + * @param newValue the new value * @return the previous value */ public double getAndSet(double newValue) { @@ -171,15 +156,11 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO } /** - * Atomically sets the value to the given updated value if the current value {@code ==} the - * expected value. - * - * @param expect - * the expected value - * @param update - * the new value - * @return true if successful. False return indicates that the actual value was not equal to the - * expected value. + * Atomically sets the value to the given updated value if the current value {@code ==} the expected value. + * + * @param expect the expected value + * @param update the new value + * @return true if successful. False return indicates that the actual value was not equal to the expected value. */ public boolean compareAndSet(final double expect, final double update) { return generalOps.execute(new SessionCallback() { @@ -205,7 +186,7 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Atomically increments by one the current value. - * + * * @return the previous value */ public double getAndIncrement() { @@ -214,7 +195,7 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Atomically decrements by one the current value. - * + * * @return the previous value */ public double getAndDecrement() { @@ -223,9 +204,8 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Atomically adds the given value to the current value. - * - * @param delta - * the value to add + * + * @param delta the value to add * @return the previous value */ public double getAndAdd(final double delta) { @@ -234,7 +214,7 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Atomically increments by one the current value. - * + * * @return the updated value */ public double incrementAndGet() { @@ -243,7 +223,7 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Atomically decrements by one the current value. - * + * * @return the updated value */ public double decrementAndGet() { @@ -252,9 +232,8 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Atomically adds the given value to the current value. - * - * @param delta - * the value to add + * + * @param delta the value to add * @return the updated value */ public double addAndGet(double delta) { @@ -263,7 +242,7 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO /** * Returns the String representation of the current value. - * + * * @return the String representation of the current value. */ public String toString() { diff --git a/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicInteger.java b/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicInteger.java index 09a26027f..16325abc4 100644 --- a/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicInteger.java +++ b/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicInteger.java @@ -31,8 +31,8 @@ import org.springframework.data.redis.serializer.GenericToStringSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; /** - * Atomic integer backed by Redis. - * Uses Redis atomic increment/decrement and watch/multi/exec operations for CAS operations. + * Atomic integer backed by Redis. Uses Redis atomic increment/decrement and watch/multi/exec operations for CAS + * operations. * * @see java.util.concurrent.atomic.AtomicInteger * @author Costin Leau @@ -43,11 +43,9 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey private ValueOperations operations; private RedisOperations generalOps; - /** - * Constructs a new RedisAtomicInteger instance. Uses the value existing - * in Redis or 0 if none is found. - * + * Constructs a new RedisAtomicInteger instance. Uses the value existing in Redis or 0 if none is found. + * * @param redisCounter redis counter * @param factory connection factory */ @@ -57,7 +55,7 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey /** * Constructs a new RedisAtomicInteger instance. - * + * * @param redisCounter the redis counter * @param factory the factory * @param initialValue the initial value @@ -67,9 +65,8 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey } /** - * Constructs a new RedisAtomicInteger instance. Uses the value existing - * in Redis or 0 if none is found. - * + * Constructs a new RedisAtomicInteger instance. Uses the value existing in Redis or 0 if none is found. + * * @param redisCounter the redis counter * @param template the template */ @@ -79,7 +76,7 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey /** * Constructs a new RedisAtomicInteger instance. - * + * * @param redisCounter the redis counter * @param template the template * @param initialValue the initial value @@ -104,8 +101,7 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey if (this.operations.get(redisCounter) == null) { set(0); } - } - else { + } else { set(initialValue); } } @@ -119,14 +115,14 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey if (this.operations.get(redisCounter) == null) { set(0); } - } - else { + } else { set(initialValue); } } + /** * Get the current value. - * + * * @return the current value */ public int get() { @@ -135,7 +131,7 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey /** * Set to the given value. - * + * * @param newValue the new value */ public void set(int newValue) { @@ -144,7 +140,7 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey /** * Set to the give value and return the old value. - * + * * @param newValue the new value * @return the previous value */ @@ -153,18 +149,16 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey } /** - * Atomically set the value to the given updated value - * if the current value == the expected value. + * Atomically set the value to the given updated value if the current value == the expected value. + * * @param expect the expected value * @param update the new value - * @return true if successful. False return indicates that - * the actual value was not equal to the expected value. + * @return true if successful. False return indicates that the actual value was not equal to the expected value. */ public boolean compareAndSet(final int expect, final int update) { return generalOps.execute(new SessionCallback() { @SuppressWarnings("unchecked") - public Boolean execute(RedisOperations operations) { for (;;) { operations.watch(Collections.singleton(key)); @@ -192,18 +186,18 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey return incrementAndGet() - 1; } - /** * Atomically decrement by one the current value. + * * @return the previous value */ public int getAndDecrement() { return decrementAndGet() + 1; } - /** * Atomically add the given value to current value. + * * @param delta the value to add * @return the previous value */ @@ -213,6 +207,7 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey /** * Atomically increment by one the current value. + * * @return the updated value */ public int incrementAndGet() { @@ -221,15 +216,16 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey /** * Atomically decrement by one the current value. + * * @return the updated value */ public int decrementAndGet() { return operations.increment(key, -1).intValue(); } - /** * Atomically add the given value to current value. + * * @param delta the value to add * @return the updated value */ @@ -239,13 +235,13 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey /** * Returns the String representation of the current value. + * * @return the String representation of the current value. */ public String toString() { return Integer.toString(get()); } - public int intValue() { return get(); } @@ -262,39 +258,32 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey return (double) get(); } - public String getKey() { return key; } - public Boolean expire(long timeout, TimeUnit unit) { return generalOps.expire(key, timeout, unit); } - public Boolean expireAt(Date date) { return generalOps.expireAt(key, date); } - public Long getExpire() { return generalOps.getExpire(key); } - public Boolean persist() { return generalOps.persist(key); } - public void rename(String newKey) { generalOps.rename(key, newKey); key = newKey; } - public DataType getType() { return DataType.STRING; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicLong.java b/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicLong.java index 7299ec72e..318040600 100644 --- a/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicLong.java +++ b/src/main/java/org/springframework/data/redis/support/atomic/RedisAtomicLong.java @@ -32,9 +32,9 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.util.Assert; /** - * Atomic long backed by Redis. - * Uses Redis atomic increment/decrement and watch/multi/exec operations for CAS operations. - * + * Atomic long backed by Redis. Uses Redis atomic increment/decrement and watch/multi/exec operations for CAS + * operations. + * * @see java.util.concurrent.atomic.AtomicLong * @author Costin Leau */ @@ -44,11 +44,9 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe private ValueOperations operations; private RedisOperations generalOps; - /** - * Constructs a new RedisAtomicLong instance. Uses the value existing - * in Redis or 0 if none is found. - * + * Constructs a new RedisAtomicLong instance. Uses the value existing in Redis or 0 if none is found. + * * @param redisCounter redis counter * @param factory connection factory */ @@ -58,7 +56,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Constructs a new RedisAtomicLong instance. - * + * * @param redisCounter * @param factory * @param initialValue @@ -86,16 +84,14 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe if (this.operations.get(redisCounter) == null) { set(0); } - } - else { + } else { set(initialValue); } } /** - * Constructs a new RedisAtomicLong instance. Uses the value existing - * in Redis or 0 if none is found. - * + * Constructs a new RedisAtomicLong instance. Uses the value existing in Redis or 0 if none is found. + * * @param redisCounter the redis counter * @param template the template */ @@ -105,7 +101,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Constructs a new RedisAtomicLong instance. - * + * * @param redisCounter the redis counter * @param template the template * @param initialValue the initial value @@ -126,16 +122,14 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe if (this.operations.get(redisCounter) == null) { set(0); } - } - else { + } else { set(initialValue); } } - /** * Gets the current value. - * + * * @return the current value */ public long get() { @@ -144,7 +138,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Sets to the given value. - * + * * @param newValue the new value */ public void set(long newValue) { @@ -153,7 +147,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Atomically sets to the given value and returns the old value. - * + * * @param newValue the new value * @return the previous value */ @@ -162,13 +156,11 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe } /** - * Atomically sets the value to the given updated value - * if the current value {@code ==} the expected value. - * + * Atomically sets the value to the given updated value if the current value {@code ==} the expected value. + * * @param expect the expected value * @param update the new value - * @return true if successful. False return indicates that - * the actual value was not equal to the expected value. + * @return true if successful. False return indicates that the actual value was not equal to the expected value. */ public boolean compareAndSet(final long expect, final long update) { return generalOps.execute(new SessionCallback() { @@ -194,7 +186,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Atomically increments by one the current value. - * + * * @return the previous value */ public long getAndIncrement() { @@ -203,7 +195,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Atomically decrements by one the current value. - * + * * @return the previous value */ public long getAndDecrement() { @@ -212,7 +204,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Atomically adds the given value to the current value. - * + * * @param delta the value to add * @return the previous value */ @@ -222,7 +214,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Atomically increments by one the current value. - * + * * @return the updated value */ public long incrementAndGet() { @@ -231,7 +223,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Atomically decrements by one the current value. - * + * * @return the updated value */ public long decrementAndGet() { @@ -240,7 +232,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe /** * Atomically adds the given value to the current value. - * + * * @param delta the value to add * @return the updated value */ @@ -257,7 +249,6 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe return Long.toString(get()); } - public int intValue() { return (int) get(); } @@ -274,39 +265,32 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe return (double) get(); } - public String getKey() { return key; } - public Boolean expire(long timeout, TimeUnit unit) { return generalOps.expire(key, timeout, unit); } - public Boolean expireAt(Date date) { return generalOps.expireAt(key, date); } - public Long getExpire() { return generalOps.getExpire(key); } - public Boolean persist() { return generalOps.persist(key); } - public void rename(String newKey) { generalOps.rename(key, newKey); key = newKey; } - public DataType getType() { return DataType.STRING; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/atomic/package-info.java b/src/main/java/org/springframework/data/redis/support/atomic/package-info.java index 78604ece8..872a8018a 100644 --- a/src/main/java/org/springframework/data/redis/support/atomic/package-info.java +++ b/src/main/java/org/springframework/data/redis/support/atomic/package-info.java @@ -2,3 +2,4 @@ * Small toolkit mirroring the {@code java.util.atomic} package in Redis. */ package org.springframework.data.redis.support.atomic; + diff --git a/src/main/java/org/springframework/data/redis/support/collections/AbstractRedisCollection.java b/src/main/java/org/springframework/data/redis/support/collections/AbstractRedisCollection.java index d17a00098..1dd7f526f 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/AbstractRedisCollection.java +++ b/src/main/java/org/springframework/data/redis/support/collections/AbstractRedisCollection.java @@ -23,11 +23,8 @@ import java.util.concurrent.TimeUnit; import org.springframework.data.redis.core.RedisOperations; /** - * Base implementation for {@link RedisCollection}. - * Provides a skeletal implementation. - * - * Note that the collection support works only with normal, non-pipeline/multi-exec connections as it requires - * a reply to be sent right away. + * Base implementation for {@link RedisCollection}. Provides a skeletal implementation. Note that the collection support + * works only with normal, non-pipeline/multi-exec connections as it requires a reply to be sent right away. * * @author Costin Leau */ @@ -43,17 +40,14 @@ public abstract class AbstractRedisCollection extends AbstractCollection i this.operations = operations; } - public String getKey() { return key; } - public RedisOperations getOperations() { return operations; } - public boolean addAll(Collection c) { boolean modified = false; for (E e : c) { @@ -66,7 +60,6 @@ public abstract class AbstractRedisCollection extends AbstractCollection i public abstract void clear(); - public boolean containsAll(Collection c) { boolean contains = true; for (Object object : c) { @@ -77,8 +70,6 @@ public abstract class AbstractRedisCollection extends AbstractCollection i public abstract boolean remove(Object o); - - public boolean removeAll(Collection c) { boolean modified = false; for (Object object : c) { @@ -101,15 +92,12 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return false; } - public int hashCode() { int result = 17 + getClass().hashCode(); result = result * 31 + key.hashCode(); return result; } - - public String toString() { StringBuilder sb = new StringBuilder(); sb.append("RedisStore for key:"); @@ -117,27 +105,22 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return sb.toString(); } - public Boolean expire(long timeout, TimeUnit unit) { return operations.expire(key, timeout, unit); } - public Boolean expireAt(Date date) { return operations.expireAt(key, date); } - public Long getExpire() { return operations.getExpire(key); } - public Boolean persist() { return operations.persist(key); } - public void rename(final String newKey) { CollectionUtils.rename(key, newKey, operations); key = newKey; @@ -148,4 +131,4 @@ public abstract class AbstractRedisCollection extends AbstractCollection i throw new IllegalStateException("Cannot read collection with Redis connection in pipeline/multi-exec mode"); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/collections/CollectionUtils.java b/src/main/java/org/springframework/data/redis/support/collections/CollectionUtils.java index b01fb00ad..8f0084950 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/CollectionUtils.java +++ b/src/main/java/org/springframework/data/redis/support/collections/CollectionUtils.java @@ -25,8 +25,7 @@ import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.SessionCallback; /** - * Utility class used mainly for type conversion by the default collection implementations. - * Meant for internal use. + * Utility class used mainly for type conversion by the default collection implementations. Meant for internal use. * * @author Costin Leau */ @@ -56,7 +55,6 @@ abstract class CollectionUtils { static void rename(final K key, final K newKey, RedisOperations operations) { operations.execute(new SessionCallback() { @SuppressWarnings("unchecked") - public Object execute(RedisOperations operations) throws DataAccessException { do { operations.watch(key); @@ -64,8 +62,7 @@ abstract class CollectionUtils { if (operations.hasKey(key)) { operations.multi(); operations.rename(key, newKey); - } - else { + } else { operations.multi(); } } while (operations.exec() == null); @@ -77,7 +74,6 @@ abstract class CollectionUtils { static Boolean renameIfAbsent(final K key, final K newKey, RedisOperations operations) { return operations.execute(new SessionCallback() { @SuppressWarnings("unchecked") - public Boolean execute(RedisOperations operations) throws DataAccessException { List exec = null; do { @@ -86,8 +82,7 @@ abstract class CollectionUtils { if (operations.hasKey(key)) { operations.multi(); operations.renameIfAbsent(key, newKey); - } - else { + } else { operations.watch(newKey); operations.multi(); operations.hasKey(newKey); @@ -104,4 +99,4 @@ abstract class CollectionUtils { } }); } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisList.java b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisList.java index 356f81c1e..dc822b98b 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisList.java +++ b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisList.java @@ -28,15 +28,11 @@ import org.springframework.data.redis.core.BoundListOperations; import org.springframework.data.redis.core.RedisOperations; /** - * Default implementation for {@link RedisList}. - * Suitable for not just lists, but also queues (FIFO ordering) or stacks (LIFO ordering) and deques - * (or double ended queues). + * Default implementation for {@link RedisList}. Suitable for not just lists, but also queues (FIFO ordering) or stacks + * (LIFO ordering) and deques (or double ended queues). Allows the maximum size (or the cap) to be specified to prevent + * the list from over growing. Note that all write operations will execute immediately, whether a cap is specified or + * not - the list will always accept new items (trimming the tail after each insert in case of capped collections). * - * Allows the maximum size (or the cap) to be specified to prevent the list from over growing. - * - * Note that all write operations will execute immediately, whether a cap is specified or not - the list - * will always accept new items (trimming the tail after each insert in case of capped collections). - * * @author Costin Leau */ public class DefaultRedisList extends AbstractRedisCollection implements RedisList { @@ -53,7 +49,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R super(delegate); } - protected void removeFromRedisStorage(E item) { DefaultRedisList.this.remove(item); } @@ -61,7 +56,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R /** * Constructs a new, uncapped DefaultRedisList instance. - * + * * @param key * @param operations */ @@ -71,7 +66,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R /** * Constructs a new, uncapped DefaultRedisList instance. - * + * * @param boundOps */ public DefaultRedisList(BoundListOperations boundOps) { @@ -80,7 +75,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R /** * Constructs a new DefaultRedisList instance. - * + * * @param boundOps * @param maxSize */ @@ -100,12 +95,10 @@ public class DefaultRedisList extends AbstractRedisCollection implements R capped = (maxSize > 0); } - public List range(long start, long end) { return listOps.range(start, end); } - public RedisList trim(int start, int end) { listOps.trim(start, end); return this; @@ -120,37 +113,34 @@ public class DefaultRedisList extends AbstractRedisCollection implements R listOps.trim(0, maxSize - 1); } } - + public Iterator iterator() { List list = content(); checkResult(list); return new DefaultRedisListIterator(list.iterator()); } - public int size() { Long size = listOps.size(); checkResult(size); return size.intValue(); } - + public boolean add(E value) { listOps.rightPush(value); cap(); return true; } - public void clear() { listOps.trim(size() + 1, 0); } - public boolean remove(Object o) { Long result = listOps.remove(1, o); return (result != null && result.longValue() > 0); } - + public void add(int index, E element) { if (index == 0) { listOps.leftPush(element); @@ -173,7 +163,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R throw new IllegalArgumentException("Redis supports insertion only at the beginning or the end of the list"); } - public boolean addAll(int index, Collection c) { // insert collection in reverse if (index == 0) { @@ -203,7 +192,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R throw new IllegalArgumentException("Redis supports insertion only at the beginning or the end of the list"); } - public E get(int index) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException(); @@ -211,40 +199,32 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return listOps.index(index); } - public int indexOf(Object o) { throw new UnsupportedOperationException(); } - public int lastIndexOf(Object o) { throw new UnsupportedOperationException(); } - public ListIterator listIterator() { throw new UnsupportedOperationException(); } - public ListIterator listIterator(int index) { throw new UnsupportedOperationException(); } - public E remove(int index) { throw new UnsupportedOperationException(); } - - public E set(int index, E e) { E object = get(index); listOps.set(index, e); return object; } - public List subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException(); } @@ -253,7 +233,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // Queue methods // - public E element() { E value = peek(); if (value == null) @@ -262,28 +241,20 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return value; } - - public boolean offer(E e) { listOps.rightPush(e); cap(); return true; } - - public E peek() { return listOps.index(0); } - - public E poll() { return listOps.leftPop(); } - - public E remove() { E value = poll(); if (value == null) @@ -296,30 +267,25 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // Dequeue // - public void addFirst(E e) { listOps.leftPush(e); cap(); } - public void addLast(E e) { add(e); } - public Iterator descendingIterator() { List content = content(); Collections.reverse(content); return new DefaultRedisListIterator(content.iterator()); } - public E getFirst() { return element(); } - public E getLast() { E e = peekLast(); if (e == null) { @@ -328,39 +294,32 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } - public boolean offerFirst(E e) { addFirst(e); return true; } - public boolean offerLast(E e) { addLast(e); return true; } - public E peekFirst() { return peek(); } - public E peekLast() { return listOps.index(-1); } - public E pollFirst() { return poll(); } - public E pollLast() { return listOps.rightPop(); } - public E pop() { E e = poll(); if (e == null) { @@ -369,22 +328,18 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } - public void push(E e) { addFirst(e); } - public E removeFirst() { return pop(); } - public boolean removeFirstOccurrence(Object o) { return remove(o); } - public E removeLast() { E e = pollLast(); if (e == null) { @@ -393,18 +348,15 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } - public boolean removeLastOccurrence(Object o) { Long result = listOps.remove(-1, o); return (result != null && result.longValue() > 0); } - // // BlockingQueue // - public int drainTo(Collection c, int maxElements) { if (this.equals(c)) { throw new IllegalArgumentException("Cannot drain a queue to itself"); @@ -420,85 +372,69 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return loop; } - public int drainTo(Collection c) { return drainTo(c, size()); } - public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { return offer(e); } - public E poll(long timeout, TimeUnit unit) throws InterruptedException { E element = listOps.leftPop(timeout, unit); return (element == null ? null : element); } - public void put(E e) throws InterruptedException { offer(e); } - public int remainingCapacity() { return Integer.MAX_VALUE; } - public E take() throws InterruptedException { return poll(0, TimeUnit.SECONDS); } - // // BlockingDeque // - public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { return offerFirst(e); } - public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { return offerLast(e); } - public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException { return poll(timeout, unit); } - public E pollLast(long timeout, TimeUnit unit) throws InterruptedException { E element = listOps.rightPop(timeout, unit); return (element == null ? null : element); } - public void putFirst(E e) throws InterruptedException { add(e); } - public void putLast(E e) throws InterruptedException { put(e); } - public E takeFirst() throws InterruptedException { return take(); } - public E takeLast() throws InterruptedException { return pollLast(0, TimeUnit.SECONDS); } - public DataType getType() { return DataType.LIST; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisMap.java b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisMap.java index d0288ac3d..195f886fd 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisMap.java +++ b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisMap.java @@ -30,10 +30,8 @@ import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.SessionCallback; /** - * Default implementation for {@link RedisMap}. - * - * Note that the current implementation doesn't provide the same locking semantics across all methods. - * In highly concurrent environments, race conditions might appear. + * Default implementation for {@link RedisMap}. Note that the current implementation doesn't provide the same locking + * semantics across all methods. In highly concurrent environments, race conditions might appear. * * @author Costin Leau */ @@ -51,17 +49,14 @@ public class DefaultRedisMap implements RedisMap { this.value = value; } - public K getKey() { return key; } - public V getValue() { return value; } - public V setValue(V value) { throw new UnsupportedOperationException(); } @@ -69,7 +64,7 @@ public class DefaultRedisMap implements RedisMap { /** * Constructs a new DefaultRedisMap instance. - * + * * @param key * @param operations */ @@ -79,14 +74,13 @@ public class DefaultRedisMap implements RedisMap { /** * Constructs a new DefaultRedisMap instance. - * + * * @param boundOps */ public DefaultRedisMap(BoundHashOperations boundOps) { this.hashOps = boundOps; } - public Long increment(K key, long delta) { return hashOps.increment(key, delta); } @@ -98,22 +92,21 @@ public class DefaultRedisMap implements RedisMap { public RedisOperations getOperations() { return hashOps.getOperations(); } - + public void clear() { getOperations().delete(Collections.singleton(getKey())); } - + public boolean containsKey(Object key) { Boolean result = hashOps.hasKey(key); checkResult(result); return result; } - public boolean containsValue(Object value) { throw new UnsupportedOperationException(); } - + public Set> entrySet() { Set keySet = keySet(); checkResult(keySet); @@ -129,15 +122,15 @@ public class DefaultRedisMap implements RedisMap { return entries; } - + public V get(Object key) { return hashOps.get(key); } - + public boolean isEmpty() { return size() == 0; } - + public Set keySet() { return hashOps.keys(); } @@ -147,27 +140,27 @@ public class DefaultRedisMap implements RedisMap { hashOps.put(key, value); return oldV; } - + public void putAll(Map m) { hashOps.putAll(m); } - + public V remove(Object key) { V v = get(key); hashOps.delete(key); return v; } - + public int size() { Long size = hashOps.size(); checkResult(size); return size.intValue(); } - + public Collection values() { return hashOps.values(); } - + public boolean equals(Object o) { if (o == this) return true; @@ -177,13 +170,13 @@ public class DefaultRedisMap implements RedisMap { } return false; } - + public int hashCode() { int result = 17 + getClass().hashCode(); result = result * 31 + getKey().hashCode(); return result; } - + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("RedisStore for key:"); @@ -191,14 +184,12 @@ public class DefaultRedisMap implements RedisMap { return sb.toString(); } - public V putIfAbsent(K key, V value) { return (hashOps.putIfAbsent(key, value) ? null : get(key)); } - public boolean remove(final Object key, final Object value) { - if (value == null){ + if (value == null) { throw new NullPointerException(); } return hashOps.getOperations().execute(new SessionCallback() { @@ -221,9 +212,8 @@ public class DefaultRedisMap implements RedisMap { }); } - public boolean replace(final K key, final V oldValue, final V newValue) { - if(oldValue == null || newValue == null) { + if (oldValue == null || newValue == null) { throw new NullPointerException(); } return hashOps.getOperations().execute(new SessionCallback() { @@ -246,9 +236,8 @@ public class DefaultRedisMap implements RedisMap { }); } - public V replace(final K key, final V value) { - if(value == null) { + if (value == null) { throw new NullPointerException(); } return hashOps.getOperations().execute(new SessionCallback() { @@ -271,38 +260,30 @@ public class DefaultRedisMap implements RedisMap { }); } - public Boolean expire(long timeout, TimeUnit unit) { return hashOps.expire(timeout, unit); } - public Boolean expireAt(Date date) { return hashOps.expireAt(date); } - public Long getExpire() { return hashOps.getExpire(); } - public Boolean persist() { return hashOps.persist(); } - - public String getKey() { return hashOps.getKey(); } - public void rename(String newKey) { hashOps.rename(newKey); } - public DataType getType() { return hashOps.getType(); } @@ -312,4 +293,4 @@ public class DefaultRedisMap implements RedisMap { throw new IllegalStateException("Cannot read collection with Redis connection in pipeline/multi-exec mode"); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java index 12670ad86..473fd9b92 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java +++ b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java @@ -26,11 +26,9 @@ import org.springframework.data.redis.core.BoundSetOperations; import org.springframework.data.redis.core.RedisOperations; /** - * Default implementation for {@link RedisSet}. + * Default implementation for {@link RedisSet}. Note that the collection support works only with normal, + * non-pipeline/multi-exec connections as it requires a reply to be sent right away. * - * Note that the collection support works only with normal, non-pipeline/multi-exec connections as it requires - * a reply to be sent right away. - * * @author Costin Leau */ public class DefaultRedisSet extends AbstractRedisCollection implements RedisSet { @@ -43,7 +41,6 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re super(delegate); } - protected void removeFromRedisStorage(E item) { DefaultRedisSet.this.remove(item); } @@ -51,7 +48,7 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re /** * Constructs a new DefaultRedisSet instance. - * + * * @param key * @param operations */ @@ -70,75 +67,60 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re this.boundSetOps = boundOps; } - - public Set diff(RedisSet set) { return boundSetOps.diff(set.getKey()); } - public Set diff(Collection> sets) { return boundSetOps.diff(CollectionUtils.extractKeys(sets)); } - - public RedisSet diffAndStore(RedisSet set, String destKey) { boundSetOps.diffAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - public RedisSet diffAndStore(Collection> sets, String destKey) { boundSetOps.diffAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - public Set intersect(RedisSet set) { return boundSetOps.intersect(set.getKey()); } - public Set intersect(Collection> sets) { return boundSetOps.intersect(CollectionUtils.extractKeys(sets)); } - public RedisSet intersectAndStore(RedisSet set, String destKey) { boundSetOps.intersectAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - public RedisSet intersectAndStore(Collection> sets, String destKey) { boundSetOps.intersectAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - public Set union(RedisSet set) { return boundSetOps.union(set.getKey()); } - public Set union(Collection> sets) { return boundSetOps.union(CollectionUtils.extractKeys(sets)); } - public RedisSet unionAndStore(RedisSet set, String destKey) { boundSetOps.unionAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - public RedisSet unionAndStore(Collection> sets, String destKey) { boundSetOps.unionAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - @SuppressWarnings("unchecked") public boolean add(E e) { Long result = boundSetOps.add(e); @@ -146,7 +128,6 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re return result == 1; } - public void clear() { // intersect the set with a non existing one // TODO: find a safer way to clean the set @@ -154,36 +135,31 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re boundSetOps.intersectAndStore(Collections.singleton(randomKey), getKey()); } - public boolean contains(Object o) { Boolean result = boundSetOps.isMember(o); checkResult(result); return result; } - public Iterator iterator() { Set members = boundSetOps.members(); checkResult(members); return new DefaultRedisSetIterator(members.iterator()); } - public boolean remove(Object o) { Long result = boundSetOps.remove(o); checkResult(result); return result == 1; } - public int size() { Long result = boundSetOps.size(); checkResult(result); return result.intValue(); } - public DataType getType() { return DataType.SET; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java index 42cb51a68..780113cf5 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java +++ b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisZSet.java @@ -26,11 +26,9 @@ import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; /** - * Default implementation for {@link RedisZSet}. + * Default implementation for {@link RedisZSet}. Note that the collection support works only with normal, + * non-pipeline/multi-exec connections as it requires a reply to be sent right away. * - * Note that the collection support works only with normal, non-pipeline/multi-exec connections as it requires - * a reply to be sent right away. - * * @author Costin Leau */ public class DefaultRedisZSet extends AbstractRedisCollection implements RedisZSet { @@ -44,7 +42,6 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R super(delegate); } - protected void removeFromRedisStorage(E item) { DefaultRedisZSet.this.remove(item); } @@ -52,7 +49,7 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R /** * Constructs a new DefaultRedisZSet instance with a default score of '1'. - * + * * @param key * @param operations */ @@ -62,7 +59,7 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R /** * Constructs a new DefaultRedisSortedSet instance. - * + * * @param key * @param operations * @param defaultScore @@ -73,10 +70,9 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R this.defaultScore = defaultScore; } - /** * Constructs a new DefaultRedisZSet instance with a default score of '1'. - * + * * @param boundOps */ public DefaultRedisZSet(BoundZSetOperations boundOps) { @@ -85,7 +81,7 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R /** * Constructs a new DefaultRedisZSet instance. - * + * * @param boundOps * @param defaultScore */ @@ -95,71 +91,58 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R this.defaultScore = defaultScore; } - public RedisZSet intersectAndStore(RedisZSet set, String destKey) { boundZSetOps.intersectAndStore(set.getKey(), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } - public RedisZSet intersectAndStore(Collection> sets, String destKey) { boundZSetOps.intersectAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } - public Set range(long start, long end) { return boundZSetOps.range(start, end); } - public Set reverseRange(long start, long end) { return boundZSetOps.reverseRange(start, end); } - public Set rangeByScore(double min, double max) { return boundZSetOps.rangeByScore(min, max); } - public Set reverseRangeByScore(double min, double max) { return boundZSetOps.reverseRangeByScore(min, max); } - public Set> rangeByScoreWithScores(double min, double max) { return boundZSetOps.rangeByScoreWithScores(min, max); } - public Set> rangeWithScores(long start, long end) { return boundZSetOps.rangeWithScores(start, end); } - public Set> reverseRangeByScoreWithScores(double min, double max) { return boundZSetOps.reverseRangeByScoreWithScores(min, max); } - public Set> reverseRangeWithScores(long start, long end) { return boundZSetOps.reverseRangeWithScores(start, end); } - public RedisZSet remove(long start, long end) { boundZSetOps.removeRange(start, end); return this; } - public RedisZSet removeByScore(double min, double max) { boundZSetOps.removeRangeByScore(min, max); return this; } - public RedisZSet unionAndStore(RedisZSet set, String destKey) { boundZSetOps.unionAndStore(set.getKey(), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); @@ -170,7 +153,6 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } - public boolean add(E e) { Boolean result = add(e, getDefaultScore()); checkResult(result); @@ -183,43 +165,36 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R return result; } - public void clear() { boundZSetOps.removeRange(0, -1); } - public boolean contains(Object o) { return (boundZSetOps.rank(o) != null); } - public Iterator iterator() { Set members = boundZSetOps.range(0, -1); checkResult(members); return new DefaultRedisSortedSetIterator(members.iterator()); } - public boolean remove(Object o) { Long result = boundZSetOps.remove(o); checkResult(result); return result == 1; } - public int size() { Long result = boundZSetOps.size(); checkResult(result); return result.intValue(); } - public Double getDefaultScore() { return defaultScore; } - public E first() { Set members = boundZSetOps.range(0, 0); checkResult(members); @@ -230,7 +205,6 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R throw new NoSuchElementException(); } - public E last() { Set members = boundZSetOps.reverseRange(0, 0); checkResult(members); @@ -240,23 +214,19 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R throw new NoSuchElementException(); } - public Long rank(Object o) { return boundZSetOps.rank(o); } - public Long reverseRank(Object o) { return boundZSetOps.reverseRank(o); } - public Double score(Object o) { return boundZSetOps.score(o); } - public DataType getType() { return DataType.ZSET; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBean.java b/src/main/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBean.java index cc84de09e..110751d48 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBean.java +++ b/src/main/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBean.java @@ -24,8 +24,8 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * Factory bean that facilitates creation of Redis-based collections. Supports list, set, zset (or sortedSet), map (or hash) and properties. - * Will use the key type if it exists or to create a dedicated collection (Properties vs Map). + * Factory bean that facilitates creation of Redis-based collections. Supports list, set, zset (or sortedSet), map (or + * hash) and properties. Will use the key type if it exists or to create a dedicated collection (Properties vs Map). * Otherwise uses the provided type (default is list). * * @author Costin Leau @@ -39,31 +39,31 @@ public class RedisCollectionFactoryBean implements InitializingBean, BeanNameAwa */ public enum CollectionType { LIST { - + public DataType dataType() { return DataType.LIST; } }, SET { - + public DataType dataType() { return DataType.SET; } }, ZSET { - + public DataType dataType() { return DataType.ZSET; } }, MAP { - + public DataType dataType() { return DataType.HASH; } }, PROPERTIES { - + public DataType dataType() { return DataType.HASH; } @@ -72,14 +72,12 @@ public class RedisCollectionFactoryBean implements InitializingBean, BeanNameAwa abstract DataType dataType(); } - private RedisStore store; private CollectionType type = null; private RedisTemplate template; private String key; private String beanName; - public void afterPropertiesSet() { if (!StringUtils.hasText(key)) { key = beanName; @@ -106,40 +104,36 @@ public class RedisCollectionFactoryBean implements InitializingBean, BeanNameAwa @SuppressWarnings("unchecked") private RedisStore createStore(DataType dt) { switch (dt) { - case LIST: - return new DefaultRedisList(key, template); + case LIST: + return new DefaultRedisList(key, template); - case SET: - return new DefaultRedisSet(key, template); + case SET: + return new DefaultRedisSet(key, template); - case ZSET: - return new DefaultRedisZSet(key, template); + case ZSET: + return new DefaultRedisZSet(key, template); - case HASH: - if (CollectionType.PROPERTIES.equals(type)) { - return new RedisProperties(key, template); - } - return new DefaultRedisMap(key, template); + case HASH: + if (CollectionType.PROPERTIES.equals(type)) { + return new RedisProperties(key, template); + } + return new DefaultRedisMap(key, template); } return null; } - public RedisStore getObject() { return store; } - public Class getObjectType() { return (store != null ? store.getClass() : RedisStore.class); } - public boolean isSingleton() { return true; } - public void setBeanName(String name) { this.beanName = name; } @@ -164,10 +158,10 @@ public class RedisCollectionFactoryBean implements InitializingBean, BeanNameAwa /** * Sets the key of the store. - * + * * @param key The key to set. */ public void setKey(String key) { this.key = key; } -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/collections/RedisIterator.java b/src/main/java/org/springframework/data/redis/support/collections/RedisIterator.java index afbfac969..569803991 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/RedisIterator.java +++ b/src/main/java/org/springframework/data/redis/support/collections/RedisIterator.java @@ -30,7 +30,7 @@ abstract class RedisIterator implements Iterator { /** * Constructs a new RedisIterator instance. - * + * * @param delegate */ RedisIterator(Iterator delegate) { @@ -55,7 +55,6 @@ abstract class RedisIterator implements Iterator { } /** - * * @see java.util.Iterator#remove() */ public void remove() { @@ -65,4 +64,4 @@ abstract class RedisIterator implements Iterator { } protected abstract void removeFromRedisStorage(E item); -} \ No newline at end of file +} diff --git a/src/main/java/org/springframework/data/redis/support/collections/RedisList.java b/src/main/java/org/springframework/data/redis/support/collections/RedisList.java index b7331b796..61570dd2d 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/RedisList.java +++ b/src/main/java/org/springframework/data/redis/support/collections/RedisList.java @@ -21,8 +21,8 @@ import java.util.Queue; import java.util.concurrent.BlockingDeque; /** - * Redis extension for the {@link List} contract. Supports {@link List}, {@link Queue} and {@link Deque} contracts - * as well as their equivalent blocking siblings {@link BlockingDeque} and {@link BlockingDeque}. + * Redis extension for the {@link List} contract. Supports {@link List}, {@link Queue} and {@link Deque} contracts as + * well as their equivalent blocking siblings {@link BlockingDeque} and {@link BlockingDeque}. * * @author Costin Leau */ diff --git a/src/main/java/org/springframework/data/redis/support/collections/RedisMap.java b/src/main/java/org/springframework/data/redis/support/collections/RedisMap.java index 67c5c0ce7..10a1166f5 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/RedisMap.java +++ b/src/main/java/org/springframework/data/redis/support/collections/RedisMap.java @@ -17,7 +17,6 @@ package org.springframework.data.redis.support.collections; import java.util.concurrent.ConcurrentMap; - /** * Map view of a Redis hash. * diff --git a/src/main/java/org/springframework/data/redis/support/collections/RedisProperties.java b/src/main/java/org/springframework/data/redis/support/collections/RedisProperties.java index 622127b08..6b6706601 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/RedisProperties.java +++ b/src/main/java/org/springframework/data/redis/support/collections/RedisProperties.java @@ -32,9 +32,9 @@ import org.springframework.data.redis.core.BoundHashOperations; import org.springframework.data.redis.core.RedisOperations; /** - * {@link Properties} extension for a Redis back-store. Useful for reading (and storing) properties - * inside a Redis hash. Particularly useful inside a Spring container for hooking into Spring's property - * placeholder or {@link org.springframework.beans.factory.config.PropertiesFactoryBean}. + * {@link Properties} extension for a Redis back-store. Useful for reading (and storing) properties inside a Redis hash. + * Particularly useful inside a Spring container for hooking into Spring's property placeholder or + * {@link org.springframework.beans.factory.config.PropertiesFactoryBean}. *

* Note that this implementation only accepts Strings - objects of other type are not supported. * @@ -49,7 +49,6 @@ public class RedisProperties extends Properties implements RedisMapRedisProperties instance. - * */ public RedisProperties(BoundHashOperations boundOps) { this(null, boundOps); @@ -57,7 +56,7 @@ public class RedisProperties extends Properties implements RedisMapRedisProperties instance. - * + * * @param key * @param operations */ @@ -67,7 +66,7 @@ public class RedisProperties extends Properties implements RedisMapRedisProperties instance. - * + * * @param defaults * @param boundOps */ @@ -79,7 +78,7 @@ public class RedisProperties extends Properties implements RedisMapRedisProperties instance. - * + * * @param defaults * @param key * @param operations @@ -88,23 +87,19 @@ public class RedisProperties extends Properties implements RedisMap boundHashOps(key)); } - public synchronized Object get(Object key) { return delegate.get(key); } - public synchronized Object put(Object key, Object value) { return delegate.put((String) key, (String) value); } @SuppressWarnings("unchecked") - public synchronized void putAll(Map t) { delegate.putAll((Map) t); } - public Enumeration propertyNames() { Set keys = new LinkedHashSet(delegate.keySet()); if (defaults != null) { @@ -113,46 +108,38 @@ public class RedisProperties extends Properties implements RedisMap elements() { Collection values = delegate.values(); return Collections.enumeration(values); } - @SuppressWarnings("unchecked") public Set> entrySet() { Set entries = delegate.entrySet(); return entries; } - public synchronized boolean equals(Object o) { if (o == this) return true; @@ -163,52 +150,44 @@ public class RedisProperties extends Properties implements RedisMap keys() { Set keys = keySet(); return Collections.enumeration(keys); } @SuppressWarnings("unchecked") - public Set keySet() { Set keys = delegate.keySet(); return keys; } - public synchronized Object remove(Object key) { return delegate.remove(key); } - public synchronized int size() { return delegate.size(); } @SuppressWarnings("unchecked") - public Collection values() { Collection vals = delegate.values(); return vals; } - public Long increment(Object key, long delta) { return hashOps.increment((String) key, delta); } - + public Double increment(Object key, double delta) { return hashOps.increment((String) key, delta); } @@ -217,68 +196,55 @@ public class RedisProperties extends Properties implements RedisMap * Since using a {@link Comparator} does not apply, a ZSet implements the {@link SortedSet} methods where applicable. * @@ -61,8 +62,7 @@ public interface RedisZSet extends RedisCollection, Set { RedisZSet removeByScore(double min, double max); /** - * Adds an element to the set with the given score, or updates the score if - * the element exists. + * Adds an element to the set with the given score, or updates the score if the element exists. * * @param e element to add * @param score element score @@ -71,13 +71,8 @@ public interface RedisZSet extends RedisCollection, Set { boolean add(E e, double score); /** - * Adds an element to the set with a default score. Equivalent to - * {@code add(e, getDefaultScore())}. - * - * - * The score value is implementation specific. - * - * {@inheritDoc} + * Adds an element to the set with a default score. Equivalent to {@code add(e, getDefaultScore())}. The score value + * is implementation specific. {@inheritDoc} */ boolean add(E e); @@ -90,8 +85,8 @@ public interface RedisZSet extends RedisCollection, Set { Double score(Object o); /** - * Returns the rank (position) of the given element in the set, in ascending order. - * Returns null if the element is not contained by the set. + * Returns the rank (position) of the given element in the set, in ascending order. Returns null if the element is not + * contained by the set. * * @param o object * @return rank of the given object @@ -99,8 +94,8 @@ public interface RedisZSet extends RedisCollection, Set { Long rank(Object o); /** - * Returns the rank (position) of the given element in the set, in descending order. - * Returns null if the element is not contained by the set. + * Returns the rank (position) of the given element in the set, in descending order. Returns null if the element is + * not contained by the set. * * @param o object * @return reverse rank of the given object @@ -116,17 +111,17 @@ public interface RedisZSet extends RedisCollection, Set { /** * Returns the first (lowest) element currently in this sorted set. - * + * * @return the first (lowest) element currently in this sorted set. - * @throws NoSuchElementException sorted set is empty. + * @throws NoSuchElementException sorted set is empty. */ E first(); /** * Returns the last (highest) element currently in this sorted set. - * + * * @return the last (highest) element currently in this sorted set. - * @throws NoSuchElementException sorted set is empty. + * @throws NoSuchElementException sorted set is empty. */ E last(); -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/Address.java b/src/test/java/org/springframework/data/redis/Address.java index 28276cdb5..52605cd2b 100644 --- a/src/test/java/org/springframework/data/redis/Address.java +++ b/src/test/java/org/springframework/data/redis/Address.java @@ -30,12 +30,11 @@ public class Address implements Serializable { private Integer number; - public Address() { - } + public Address() {} /** * Constructs a new Address instance. - * + * * @param street * @param number */ @@ -45,10 +44,9 @@ public class Address implements Serializable { this.number = number; } - /** * Returns the street. - * + * * @return Returns the street */ public String getStreet() { @@ -64,7 +62,7 @@ public class Address implements Serializable { /** * Returns the number. - * + * * @return Returns the number */ public Integer getNumber() { @@ -78,7 +76,6 @@ public class Address implements Serializable { this.number = number; } - public int hashCode() { final int prime = 31; int result = 1; @@ -87,7 +84,6 @@ public class Address implements Serializable { return result; } - public boolean equals(Object obj) { if (this == obj) return true; @@ -99,15 +95,13 @@ public class Address implements Serializable { if (number == null) { if (other.number != null) return false; - } - else if (!number.equals(other.number)) + } else if (!number.equals(other.number)) return false; if (street == null) { if (other.street != null) return false; - } - else if (!street.equals(other.street)) + } else if (!street.equals(other.street)) return false; return true; } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/ConnectionFactoryTracker.java b/src/test/java/org/springframework/data/redis/ConnectionFactoryTracker.java index 929a1f8de..de6722d18 100644 --- a/src/test/java/org/springframework/data/redis/ConnectionFactoryTracker.java +++ b/src/test/java/org/springframework/data/redis/ConnectionFactoryTracker.java @@ -22,8 +22,8 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.data.redis.connection.RedisConnectionFactory; /** - * Basic utility to help with the destruction of {@link RedisConnectionFactory} inside JUnit 4 tests. - * Simply add the factory during setup and then call {@link #cleanUp()} through the @AfterClass method. + * Basic utility to help with the destruction of {@link RedisConnectionFactory} inside JUnit 4 tests. Simply add the + * factory during setup and then call {@link #cleanUp()} through the @AfterClass method. * * @author Costin Leau */ @@ -40,7 +40,7 @@ public abstract class ConnectionFactoryTracker { for (RedisConnectionFactory connectionFactory : connFactories) { try { ((DisposableBean) connectionFactory).destroy(); - //System.out.println("Succesfully cleaned up factory " + connectionFactory); + // System.out.println("Succesfully cleaned up factory " + connectionFactory); } catch (Exception ex) { System.err.println("Cannot clean factory " + connectionFactory + ex); } diff --git a/src/test/java/org/springframework/data/redis/DoubleAsStringObjectFactory.java b/src/test/java/org/springframework/data/redis/DoubleAsStringObjectFactory.java index a9d59cde0..c5a5f6fdd 100644 --- a/src/test/java/org/springframework/data/redis/DoubleAsStringObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/DoubleAsStringObjectFactory.java @@ -18,11 +18,9 @@ package org.springframework.data.redis; import java.util.concurrent.atomic.AtomicLong; /** - * - * Implementation of {@link ObjectFactory} that returns unique Doubles as Strings, - * incrementing by 1 each time + * Implementation of {@link ObjectFactory} that returns unique Doubles as Strings, incrementing by 1 each time + * * @author Jennifer Hickey - * */ public class DoubleAsStringObjectFactory implements ObjectFactory { diff --git a/src/test/java/org/springframework/data/redis/DoubleObjectFactory.java b/src/test/java/org/springframework/data/redis/DoubleObjectFactory.java index f8bd5e055..28e0755fd 100644 --- a/src/test/java/org/springframework/data/redis/DoubleObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/DoubleObjectFactory.java @@ -19,9 +19,8 @@ import java.util.concurrent.atomic.AtomicLong; /** * Returns unique Doubles, incrementing by 1 each time - * + * * @author Jennifer Hickey - * */ public class DoubleObjectFactory implements ObjectFactory { diff --git a/src/test/java/org/springframework/data/redis/LongAsStringObjectFactory.java b/src/test/java/org/springframework/data/redis/LongAsStringObjectFactory.java index cd7622a21..db39f6c4f 100644 --- a/src/test/java/org/springframework/data/redis/LongAsStringObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/LongAsStringObjectFactory.java @@ -18,11 +18,10 @@ package org.springframework.data.redis; import java.util.concurrent.atomic.AtomicLong; /** -* -* Implementation of {@link ObjectFactory} that returns unique incremented Longs as Strings -* @author Jennifer Hickey -* -*/ + * Implementation of {@link ObjectFactory} that returns unique incremented Longs as Strings + * + * @author Jennifer Hickey + */ public class LongAsStringObjectFactory implements ObjectFactory { private AtomicLong counter = new AtomicLong(); diff --git a/src/test/java/org/springframework/data/redis/LongObjectFactory.java b/src/test/java/org/springframework/data/redis/LongObjectFactory.java index d1c131f38..e3ec84ccb 100644 --- a/src/test/java/org/springframework/data/redis/LongObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/LongObjectFactory.java @@ -19,9 +19,8 @@ import java.util.concurrent.atomic.AtomicLong; /** * Returns unique Longs by incrementing a counter each time - * + * * @author Jennifer Hickey - * */ public class LongObjectFactory implements ObjectFactory { diff --git a/src/test/java/org/springframework/data/redis/ObjectFactory.java b/src/test/java/org/springframework/data/redis/ObjectFactory.java index 5d4803444..b9cd4f34d 100644 --- a/src/test/java/org/springframework/data/redis/ObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/ObjectFactory.java @@ -16,7 +16,7 @@ package org.springframework.data.redis; /** - * Simple object factory. + * Simple object factory. * * @author Costin Leau */ diff --git a/src/test/java/org/springframework/data/redis/Person.java b/src/test/java/org/springframework/data/redis/Person.java index 53307ba27..a29371999 100644 --- a/src/test/java/org/springframework/data/redis/Person.java +++ b/src/test/java/org/springframework/data/redis/Person.java @@ -33,8 +33,7 @@ public class Person implements Serializable { private Integer age; private Address address; - public Person() { - } + public Person() {} public Person(String firstName, String lastName, int age) { this(firstName, lastName, age, null); @@ -80,7 +79,6 @@ public class Person implements Serializable { this.address = address; } - public int hashCode() { final int prime = 31; int result = 1; @@ -91,7 +89,6 @@ public class Person implements Serializable { return result; } - public boolean equals(Object obj) { if (this == obj) return true; @@ -103,27 +100,23 @@ public class Person implements Serializable { if (address == null) { if (other.address != null) return false; - } - else if (!address.equals(other.address)) + } else if (!address.equals(other.address)) return false; if (age == null) { if (other.age != null) return false; - } - else if (!age.equals(other.age)) + } else if (!age.equals(other.age)) return false; if (firstName == null) { if (other.firstName != null) return false; - } - else if (!firstName.equals(other.firstName)) + } else if (!firstName.equals(other.firstName)) return false; if (lastName == null) { if (other.lastName != null) return false; - } - else if (!lastName.equals(other.lastName)) + } else if (!lastName.equals(other.lastName)) return false; return true; } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/PersonObjectFactory.java b/src/test/java/org/springframework/data/redis/PersonObjectFactory.java index db3389b68..9fb59656f 100644 --- a/src/test/java/org/springframework/data/redis/PersonObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/PersonObjectFactory.java @@ -17,7 +17,6 @@ package org.springframework.data.redis; import java.util.UUID; - /** * @author Costin Leau */ diff --git a/src/test/java/org/springframework/data/redis/RawObjectFactory.java b/src/test/java/org/springframework/data/redis/RawObjectFactory.java index 3684195cc..fd4e5cbe7 100644 --- a/src/test/java/org/springframework/data/redis/RawObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/RawObjectFactory.java @@ -19,9 +19,8 @@ import java.util.UUID; /** * Implementation of {@link ObjectFactory} that returns random byte[]s - * + * * @author Jennifer Hickey - * */ public class RawObjectFactory implements ObjectFactory { diff --git a/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java b/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java index ffcdc9b55..f2e8c1011 100644 --- a/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java +++ b/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java @@ -20,15 +20,12 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactor import org.springframework.test.annotation.ProfileValueSource; /** - * Implementation of {@link ProfileValueSource} that handles profile value name - * "redisVersion" by checking the current version of Redis. 2.4.x will be - * returned as "2.4" and 2.6.x will be returned as "2.6". Any other version - * found will cause an {@link UnsupportedOperationException} - * - * System property values will be returned for any key other than "redisVersion" + * Implementation of {@link ProfileValueSource} that handles profile value name "redisVersion" by checking the current + * version of Redis. 2.4.x will be returned as "2.4" and 2.6.x will be returned as "2.6". Any other version found will + * cause an {@link UnsupportedOperationException} System property values will be returned for any key other than + * "redisVersion" * * @author Jennifer Hickey - * */ public class RedisTestProfileValueSource implements ProfileValueSource { @@ -40,8 +37,8 @@ public class RedisTestProfileValueSource implements ProfileValueSource { public RedisTestProfileValueSource() { if (redisVersion == null) { - LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory( - SettingsUtils.getHost(), SettingsUtils.getPort()); + LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(SettingsUtils.getHost(), + SettingsUtils.getPort()); connectionFactory.afterPropertiesSet(); RedisConnection connection = connectionFactory.getConnection(); redisVersion = RedisVersionUtils.getRedisVersion(connection); diff --git a/src/test/java/org/springframework/data/redis/RedisVersionUtils.java b/src/test/java/org/springframework/data/redis/RedisVersionUtils.java index 0638930b5..d3503db05 100644 --- a/src/test/java/org/springframework/data/redis/RedisVersionUtils.java +++ b/src/test/java/org/springframework/data/redis/RedisVersionUtils.java @@ -22,14 +22,12 @@ import org.springframework.data.redis.connection.RedisConnection; /** * Utilities for examining the Redis version - * + * * @author Jennifer Hickey - * */ public abstract class RedisVersionUtils { - private static final Pattern VERSION_MATCHER = Pattern - .compile("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?"); + private static final Pattern VERSION_MATCHER = Pattern.compile("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?"); public static Version getRedisVersion(RedisConnection connection) { return parseVersion((String) connection.info().get("redis_version")); diff --git a/src/test/java/org/springframework/data/redis/RedisViewPE.java b/src/test/java/org/springframework/data/redis/RedisViewPE.java index a16735392..c6a45edb4 100644 --- a/src/test/java/org/springframework/data/redis/RedisViewPE.java +++ b/src/test/java/org/springframework/data/redis/RedisViewPE.java @@ -71,4 +71,4 @@ public class RedisViewPE { public void setHashOps(HashOperations hashOps) { this.hashOps = hashOps; } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/SpinBarrier.java b/src/test/java/org/springframework/data/redis/SpinBarrier.java index 2e44ba005..20be06bac 100644 --- a/src/test/java/org/springframework/data/redis/SpinBarrier.java +++ b/src/test/java/org/springframework/data/redis/SpinBarrier.java @@ -16,21 +16,16 @@ package org.springframework.data.redis; /** - * * @author Jennifer Hickey - * */ abstract public class SpinBarrier { /** * Periodically tests for a condition until it is met or a timeout occurs * - * @param condition - * The condition to periodically test - * @param timeout - * The timeout - * @return true if condition passes, false if condition does not pass within - * timeout + * @param condition The condition to periodically test + * @param timeout The timeout + * @return true if condition passes, false if condition does not pass within timeout */ public static boolean waitFor(TestCondition condition, long timeout) { boolean passes = false; @@ -41,8 +36,7 @@ abstract public class SpinBarrier { } try { Thread.sleep(100); - } catch (InterruptedException e) { - } + } catch (InterruptedException e) {} } return passes; } diff --git a/src/test/java/org/springframework/data/redis/StringObjectFactory.java b/src/test/java/org/springframework/data/redis/StringObjectFactory.java index 9ad76d977..c72841671 100644 --- a/src/test/java/org/springframework/data/redis/StringObjectFactory.java +++ b/src/test/java/org/springframework/data/redis/StringObjectFactory.java @@ -17,10 +17,9 @@ package org.springframework.data.redis; import java.util.UUID; - /** * String object factory based on UUID. - * + * * @author Costin Leau */ public class StringObjectFactory implements ObjectFactory { diff --git a/src/test/java/org/springframework/data/redis/TestCondition.java b/src/test/java/org/springframework/data/redis/TestCondition.java index 5a0c20b2a..22faf4fed 100644 --- a/src/test/java/org/springframework/data/redis/TestCondition.java +++ b/src/test/java/org/springframework/data/redis/TestCondition.java @@ -16,17 +16,13 @@ package org.springframework.data.redis; /** + * A condition to test periodically, used in conjunction with {@link SpinBarrier} * - * A condition to test periodically, used in conjunction with - * {@link SpinBarrier} - * * @author Jennifer Hickey - * */ public interface TestCondition { /** - * * @return true if condition passes */ boolean passes(); diff --git a/src/test/java/org/springframework/data/redis/Version.java b/src/test/java/org/springframework/data/redis/Version.java index 09d457947..c8e766607 100644 --- a/src/test/java/org/springframework/data/redis/Version.java +++ b/src/test/java/org/springframework/data/redis/Version.java @@ -17,9 +17,8 @@ package org.springframework.data.redis; /** * A {@link Comparable} software version - * + * * @author Jennifer Hickey - * */ public class Version implements Comparable { Integer major; diff --git a/src/test/java/org/springframework/data/redis/cache/AbstractNativeCacheTest.java b/src/test/java/org/springframework/data/redis/cache/AbstractNativeCacheTest.java index da3eac85c..184843fc7 100644 --- a/src/test/java/org/springframework/data/redis/cache/AbstractNativeCacheTest.java +++ b/src/test/java/org/springframework/data/redis/cache/AbstractNativeCacheTest.java @@ -46,7 +46,6 @@ public abstract class AbstractNativeCacheTest { cache.clear(); } - protected abstract T createNativeCache() throws Exception; protected abstract Cache createCache(T nativeCache); @@ -77,10 +76,10 @@ public abstract class AbstractNativeCacheTest { if (valueWrapper != null) { assertThat(valueWrapper.get(), isEqual(value)); } - // keeps failing on the CI server so do + // keeps failing on the CI server so do else { - // Thread.sleep(200); - // assertNotNull(cache.get(key)); + // Thread.sleep(200); + // assertNotNull(cache.get(key)); // ignore for now } } @@ -90,7 +89,6 @@ public abstract class AbstractNativeCacheTest { Object key1 = getKey(); Object value1 = getValue(); - Object key2 = getKey(); Object value2 = getValue(); @@ -102,4 +100,4 @@ public abstract class AbstractNativeCacheTest { assertNull(cache.get(key2)); assertNull(cache.get(key1)); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/cache/RedisCacheTest.java b/src/test/java/org/springframework/data/redis/cache/RedisCacheTest.java index 6d099d5cd..7400a6e73 100644 --- a/src/test/java/org/springframework/data/redis/cache/RedisCacheTest.java +++ b/src/test/java/org/springframework/data/redis/cache/RedisCacheTest.java @@ -58,7 +58,6 @@ public class RedisCacheTest extends AbstractNativeCacheTest { private ObjectFactory valueFactory; private RedisTemplate template; - public RedisCacheTest(RedisTemplate template, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.keyFactory = keyFactory; this.valueFactory = valueFactory; @@ -71,14 +70,11 @@ public class RedisCacheTest extends AbstractNativeCacheTest { return AbstractOperationsTestParams.testParams(); } - @SuppressWarnings("unchecked") protected Cache createCache(RedisTemplate nativeCache) { - return new RedisCache(CACHE_NAME, CACHE_NAME.concat(":").getBytes(), nativeCache, - TimeUnit.MINUTES.toSeconds(10)); + return new RedisCache(CACHE_NAME, CACHE_NAME.concat(":").getBytes(), nativeCache, TimeUnit.MINUTES.toSeconds(10)); } - protected RedisTemplate createNativeCache() throws Exception { return template; } @@ -174,7 +170,7 @@ public class RedisCacheTest extends AbstractNativeCacheTest { public void run() { try { cache.put(key1, value1); - }catch(IllegalMonitorStateException e) { + } catch (IllegalMonitorStateException e) { monitorStateException.set(true); } finally { latch.countDown(); @@ -188,33 +184,33 @@ public class RedisCacheTest extends AbstractNativeCacheTest { latch.await(); assertFalse(monitorStateException.get()); } - + /** * @see DATAREDIS-243 */ @Test public void testCacheGetShouldReturnCachedInstance() { assumeThat(cache, instanceOf(RedisCache.class)); - + Object key = getKey(); Object value = getValue(); cache.put(key, value); - - assertThat(value, isEqual(((RedisCache)cache).get(key, Object.class))); + + assertThat(value, isEqual(((RedisCache) cache).get(key, Object.class))); } - + /** * @see DATAREDIS-243 */ @Test public void testCacheGetShouldRetunInstanceOfCorrectType() { assumeThat(cache, instanceOf(RedisCache.class)); - + Object key = getKey(); Object value = getValue(); cache.put(key, value); - - RedisCache redisCache = (RedisCache)cache; + + RedisCache redisCache = (RedisCache) cache; assertThat(redisCache.get(key, value.getClass()), instanceOf(value.getClass())); } @@ -224,29 +220,29 @@ public class RedisCacheTest extends AbstractNativeCacheTest { @Test(expected = ClassCastException.class) public void testCacheGetShouldThrowExceptionOnInvalidType() { assumeThat(cache, instanceOf(RedisCache.class)); - + Object key = getKey(); Object value = getValue(); cache.put(key, value); - - RedisCache redisCache = (RedisCache)cache; + + RedisCache redisCache = (RedisCache) cache; @SuppressWarnings("unused") Cache retrievedObject = redisCache.get(key, Cache.class); } - + /** * @see DATAREDIS-243 */ @Test public void testCacheGetShouldReturnNullIfNoCachedValueFound() { assumeThat(cache, instanceOf(RedisCache.class)); - + Object key = getKey(); Object value = getValue(); cache.put(key, value); - - RedisCache redisCache = (RedisCache)cache; - + + RedisCache redisCache = (RedisCache) cache; + Object invalidKey = template.getKeySerializer() == null ? "spring-data-redis".getBytes() : "spring-data-redis"; assertThat(redisCache.get(invalidKey, value.getClass()), nullValue()); } diff --git a/src/test/java/org/springframework/data/redis/config/NamespaceTest.java b/src/test/java/org/springframework/data/redis/config/NamespaceTest.java index d7f881f11..23032fbea 100644 --- a/src/test/java/org/springframework/data/redis/config/NamespaceTest.java +++ b/src/test/java/org/springframework/data/redis/config/NamespaceTest.java @@ -38,14 +38,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ProfileValueSourceConfiguration public class NamespaceTest { - @Autowired - private RedisMessageListenerContainer container; + @Autowired private RedisMessageListenerContainer container; - @Autowired - private StringRedisTemplate template; + @Autowired private StringRedisTemplate template; - @Autowired - private StubErrorHandler handler; + @Autowired private StubErrorHandler handler; @Test @IfProfileValue(name = "runLongTests", value = "true") diff --git a/src/test/java/org/springframework/data/redis/config/StubErrorHandler.java b/src/test/java/org/springframework/data/redis/config/StubErrorHandler.java index e80bc4317..c5b4fae9d 100644 --- a/src/test/java/org/springframework/data/redis/config/StubErrorHandler.java +++ b/src/test/java/org/springframework/data/redis/config/StubErrorHandler.java @@ -27,7 +27,6 @@ public class StubErrorHandler implements ErrorHandler { public BlockingDeque throwables = new LinkedBlockingDeque(); - public void handleError(Throwable t) { throwables.add(t); } 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 e9f75df60..f869bfd30 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -65,10 +65,9 @@ import org.springframework.test.annotation.ProfileValueSourceConfiguration; /** * Base test class for AbstractConnection integration tests - * + * * @author Costin Leau * @author Jennifer Hickey - * */ @ProfileValueSourceConfiguration(RedisTestProfileValueSource.class) public abstract class AbstractConnectionIntegrationTests { @@ -81,8 +80,7 @@ public abstract class AbstractConnectionIntegrationTests { protected List actual = new ArrayList(); - @Autowired - protected RedisConnectionFactory connectionFactory; + @Autowired protected RedisConnectionFactory connectionFactory; protected RedisConnection byteConnection; @@ -90,7 +88,7 @@ public abstract class AbstractConnectionIntegrationTests { public void setUp() { byteConnection = connectionFactory.getConnection(); connection = new DefaultStringRedisConnection(byteConnection); - ((DefaultStringRedisConnection)connection).setDeserializePipelineAndTxResults(true); + ((DefaultStringRedisConnection) connection).setDeserializePipelineAndTxResults(true); initConnection(); } @@ -105,7 +103,7 @@ public abstract class AbstractConnectionIntegrationTests { connection.close(); connection = null; } - + @Test public void testSelect() { // Make sure this doesn't throw Exception @@ -182,13 +180,11 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.evalSha(sha1, ReturnType.MULTI, 1, "key1", "arg1")); List results = getResults(); List scriptResults = (List) results.get(0); - assertEquals( - Arrays.asList(new Object[] { "key1", "arg1" }), - Arrays.asList(new Object[] { new String(scriptResults.get(0)), - new String(scriptResults.get(1)) })); + assertEquals(Arrays.asList(new Object[] { "key1", "arg1" }), + Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) })); } - @Test(expected=RedisSystemException.class) + @Test(expected = RedisSystemException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayError() { connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1"); @@ -251,8 +247,8 @@ public abstract class AbstractConnectionIntegrationTests { public void testEvalReturnArrayStrings() { actual.add(connection.eval("return {KEYS[1],ARGV[1]}", ReturnType.MULTI, 1, "foo", "bar")); List result = (List) getResults().get(0); - assertEquals(Arrays.asList(new Object[] { "foo", "bar" }), Arrays.asList(new Object[] { - new String(result.get(0)), new String(result.get(1)) })); + assertEquals(Arrays.asList(new Object[] { "foo", "bar" }), + Arrays.asList(new Object[] { new String(result.get(0)), new String(result.get(1)) })); } @Test @@ -262,7 +258,7 @@ public abstract class AbstractConnectionIntegrationTests { verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, 2l }) })); } - @Test(expected=RedisSystemException.class) + @Test(expected = RedisSystemException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalArrayScriptError() { // Syntax error @@ -274,12 +270,11 @@ public abstract class AbstractConnectionIntegrationTests { @Test @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayOKs() { - actual.add(connection.eval( - "return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}", + actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}", ReturnType.MULTI, 0)); List result = (List) getResults().get(0); - assertEquals(Arrays.asList(new Object[] { "OK", "OK" }), Arrays.asList(new Object[] { - new String(result.get(0)), new String(result.get(1)) })); + assertEquals(Arrays.asList(new Object[] { "OK", "OK" }), + Arrays.asList(new Object[] { new String(result.get(0)), new String(result.get(1)) })); } @Test @@ -315,11 +310,9 @@ public abstract class AbstractConnectionIntegrationTests { final AtomicBoolean scriptDead = new AtomicBoolean(false); Thread th = new Thread(new Runnable() { public void run() { - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); try { - conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", - ReturnType.BOOLEAN, 0); + conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0); } catch (DataAccessException e) { scriptDead.set(true); } @@ -480,7 +473,7 @@ public abstract class AbstractConnectionIntegrationTests { verifyResults(Arrays.asList(new Object[] { 4l })); } - @Test(expected =UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testBitOpNotMultipleSources() { connection.set("key1", "abcd"); @@ -691,7 +684,7 @@ public abstract class AbstractConnectionIntegrationTests { public void testExecuteNoArgs() { actual.add(connection.execute("PING")); List results = getResults(); - assertEquals("PONG", stringSerializer.deserialize((byte[])results.get(0))); + assertEquals("PONG", stringSerializer.deserialize((byte[]) results.get(0))); } @SuppressWarnings("unchecked") @@ -703,7 +696,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.exec()); List results = getResults(); List execResults = (List) results.get(0); - assertEquals(Arrays.asList(new Object[] {"value"}), execResults); + assertEquals(Arrays.asList(new Object[] { "value" }), execResults); assertEquals("value", connection.get("key")); } @@ -714,16 +707,16 @@ public abstract class AbstractConnectionIntegrationTests { testMultiExec(); } - @Test(expected=RedisSystemException.class) + @Test(expected = RedisSystemException.class) public void testExecWithoutMulti() { connection.exec(); getResults(); } - @Test(expected=RedisSystemException.class) + @Test(expected = RedisSystemException.class) public void testErrorInTx() { connection.multi(); - connection.set("foo","bar"); + connection.set("foo", "bar"); // Try to do a list op on a value connection.lPop("foo"); connection.exec(); @@ -732,8 +725,7 @@ public abstract class AbstractConnectionIntegrationTests { @Test public void testMultiDiscard() throws Exception { - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.set("testitnow", "willdo"); connection.multi(); connection.set("testitnow2", "notok"); @@ -750,10 +742,9 @@ public abstract class AbstractConnectionIntegrationTests { public void testWatch() throws Exception { connection.set("testitnow", "willdo"); connection.watch("testitnow".getBytes()); - //Give some time for watch to be asynch executed in extending tests + // Give some time for watch to be asynch executed in extending tests Thread.sleep(500); - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.set("testitnow", "something"); conn2.close(); connection.multi(); @@ -770,17 +761,16 @@ public abstract class AbstractConnectionIntegrationTests { connection.watch("testitnow".getBytes()); connection.unwatch(); connection.multi(); - //Give some time for unwatch to be asynch executed + // Give some time for unwatch to be asynch executed Thread.sleep(100); - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.set("testitnow", "something"); connection.set("testitnow", "somethingelse"); connection.get("testitnow"); actual.add(connection.exec()); List results = getResults(); List execResults = (List) results.get(0); - assertEquals(Arrays.asList(new Object[] {"somethingelse"}), execResults); + assertEquals(Arrays.asList(new Object[] { "somethingelse" }), execResults); } @Test @@ -789,9 +779,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPush("sortlist", "bar")); actual.add(connection.rPush("sortlist", "baz")); actual.add(connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true))); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, - Arrays.asList(new String[] { "bar", "baz", "foo" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "bar", "baz", "foo" }) })); } @Test @@ -799,12 +787,9 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPush("sortlist", "foo")); actual.add(connection.rPush("sortlist", "bar")); actual.add(connection.rPush("sortlist", "baz")); - actual.add(connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true), - "newlist")); + actual.add(connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true), "newlist")); actual.add(connection.lRange("newlist", 0, 9)); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, 3l, - Arrays.asList(new String[] { "bar", "baz", "foo" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 3l, Arrays.asList(new String[] { "bar", "baz", "foo" }) })); } @Test @@ -813,9 +798,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPush("sortlist", "2")); actual.add(connection.rPush("sortlist", "3")); actual.add(connection.sort("sortlist", null)); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, - Arrays.asList(new String[] { "2", "3", "5" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "2", "3", "5" }) })); } @Test @@ -825,9 +808,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPush("sortlist", "5")); actual.add(connection.sort("sortlist", null, "newlist")); actual.add(connection.lRange("newlist", 0, 9)); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, 3l, - Arrays.asList(new String[] { "3", "5", "9" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 3l, Arrays.asList(new String[] { "3", "5", "9" }) })); } @Test @@ -981,7 +962,7 @@ public abstract class AbstractConnectionIntegrationTests { @Test public void testDel() { - connection.set("testing","123"); + connection.set("testing", "123"); actual.add(connection.del("testing")); actual.add(connection.exists("testing")); verifyResults(Arrays.asList(new Object[] { 1l, false })); @@ -1076,7 +1057,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.incrBy(key, largeNumber)); actual.add(connection.decrBy(key, largeNumber)); actual.add(connection.decrBy(key, 2 * largeNumber)); - verifyResults(Arrays.asList(new Object[] {largeNumber, 0l, -2 * largeNumber})); + verifyResults(Arrays.asList(new Object[] { largeNumber, 0l, -2 * largeNumber })); } @Test @@ -1087,10 +1068,10 @@ public abstract class AbstractConnectionIntegrationTests { long largeNumber = 0x123456789L; // > 32bits actual.add(connection.hSet(key, hkey, "0")); actual.add(connection.hIncrBy(key, hkey, largeNumber)); - //assertEquals(largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue()); + // assertEquals(largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue()); actual.add(connection.hIncrBy(key, hkey, -2 * largeNumber)); - //assertEquals(-largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue()); - verifyResults(Arrays.asList(new Object[] {true, largeNumber, -largeNumber})); + // assertEquals(-largeNumber, Long.valueOf(connection.hGet(key, hkey)).longValue()); + verifyResults(Arrays.asList(new Object[] { true, largeNumber, -largeNumber })); } @Test @@ -1114,26 +1095,20 @@ public abstract class AbstractConnectionIntegrationTests { @Test public void testBLPop() { - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.lPush("poplist", "foo"); conn2.lPush("poplist", "bar"); actual.add(connection.bLPop(100, "poplist", "otherlist")); - verifyResults( - Arrays.asList(new Object[] { - Arrays.asList(new String[] { "poplist", "bar" }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "poplist", "bar" }) })); } @Test public void testBRPop() { - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.rPush("rpoplist", "bar"); conn2.rPush("rpoplist", "foo"); actual.add(connection.bRPop(1, "rpoplist")); - verifyResults( - Arrays.asList(new Object[] { - Arrays.asList(new String[] { "rpoplist", "foo" }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "rpoplist", "foo" }) })); } @Test @@ -1144,10 +1119,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.lRange("MyList", 0, -1)); actual.add(connection.lInsert("MyList", Position.BEFORE, "big", "very")); actual.add(connection.lRange("MyList", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, - Arrays.asList(new String[] { "hello", "big", "world" }), 4l, - Arrays.asList(new String[] { "hello", "very", "big", "world" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "big", "world" }), 4l, + Arrays.asList(new String[] { "hello", "very", "big", "world" }) })); } @Test @@ -1166,9 +1139,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPush("PopList", "hello")); actual.add(connection.lRem("PopList", 2, "hello")); actual.add(connection.lRange("PopList", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 2l, - Arrays.asList(new String[] { "big", "world" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 2l, Arrays.asList(new String[] { "big", "world" }) })); } @Test @@ -1178,8 +1149,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPush("PopList", "world")); actual.add(connection.rPush("PopList", "hello")); actual.add(connection.lLen("PopList")); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 4l })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 4l })); } @Test @@ -1189,9 +1159,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPush("PopList", "world")); connection.lSet("PopList", 1, "cruel"); actual.add(connection.lRange("PopList", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, - Arrays.asList(new String[] { "hello", "cruel", "world" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "cruel", "world" }) })); } @Test @@ -1201,9 +1169,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPush("PopList", "world")); connection.lTrim("PopList", 1, -1); actual.add(connection.lRange("PopList", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, - Arrays.asList(new String[] { "big", "world" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "big", "world" }) })); } @Test @@ -1222,17 +1188,14 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.rPopLPush("PopList", "pop2")); actual.add(connection.lRange("PopList", 0, -1)); actual.add(connection.lRange("pop2", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 1l, "world", - Arrays.asList(new String[] { "hello" }), - Arrays.asList(new String[] { "world", "hey" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, 1l, "world", Arrays.asList(new String[] { "hello" }), + Arrays.asList(new String[] { "world", "hey" }) })); } @Test public void testBRPopLPush() { - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.rPush("PopList", "hello"); conn2.rPush("PopList", "world"); conn2.rPush("pop2", "hey"); @@ -1240,8 +1203,7 @@ public abstract class AbstractConnectionIntegrationTests { List results = getResults(); assertEquals(Arrays.asList(new String[] { "world" }), results); assertEquals(Arrays.asList(new String[] { "hello" }), connection.lRange("PopList", 0, -1)); - assertEquals(Arrays.asList(new String[] { "world", "hey" }), - connection.lRange("pop2", 0, -1)); + assertEquals(Arrays.asList(new String[] { "world", "hey" }), connection.lRange("pop2", 0, -1)); } @Test @@ -1279,16 +1241,14 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.lPush("testlist", "bar")); actual.add(connection.lPush("testlist", "baz")); actual.add(connection.lRange("testlist", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, - Arrays.asList(new String[] { "baz", "bar" }) })); + verifyResults(Arrays.asList(new Object[] { 1l, 2l, Arrays.asList(new String[] { "baz", "bar" }) })); } @Test public void testLPushMultiple() { actual.add(connection.lPush("testlist", "bar", "baz")); actual.add(connection.lRange("testlist", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 2l, - Arrays.asList(new String[] { "baz", "bar" }) })); + verifyResults(Arrays.asList(new Object[] { 2l, Arrays.asList(new String[] { "baz", "bar" }) })); } // Set operations @@ -1298,8 +1258,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sMembers("myset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, new HashSet(Arrays.asList(new String[] { - "foo", "bar" })) })); + verifyResults(Arrays.asList(new Object[] { 1l, 1l, + new HashSet(Arrays.asList(new String[] { "foo", "bar" })) })); } @Test @@ -1307,8 +1267,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("myset", "foo", "bar")); actual.add(connection.sAdd("myset", "baz")); actual.add(connection.sMembers("myset")); - verifyResults(Arrays.asList(new Object[] { 2l, 1l, new HashSet(Arrays.asList(new String[] { - "foo", "bar", "baz" })) })); + verifyResults(Arrays.asList(new Object[] { 2l, 1l, + new HashSet(Arrays.asList(new String[] { "foo", "bar", "baz" })) })); } @Test @@ -1325,9 +1285,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sDiff("myset", "otherset")); - verifyResults( - Arrays.asList(new Object[] { 1l, 1l, 1l, - new HashSet(Collections.singletonList("foo")) })); + verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet(Collections.singletonList("foo")) })); } @Test @@ -1337,9 +1295,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sDiffStore("thirdset", "myset", "otherset")); actual.add(connection.sMembers("thirdset")); - verifyResults( - Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, - new HashSet(Collections.singletonList("foo")) })); + verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet(Collections.singletonList("foo")) })); } @Test @@ -1348,9 +1304,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sInter("myset", "otherset")); - verifyResults( - Arrays.asList(new Object[] { 1l, 1l, 1l, - new HashSet(Collections.singletonList("bar")) })); + verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet(Collections.singletonList("bar")) })); } @Test @@ -1360,9 +1314,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sInterStore("thirdset", "myset", "otherset")); actual.add(connection.sMembers("thirdset")); - verifyResults( - Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, - new HashSet(Collections.singletonList("bar")) })); + verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet(Collections.singletonList("bar")) })); } @Test @@ -1388,8 +1340,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sPop("myset")); - assertTrue(new HashSet(Arrays.asList(new String[] { "foo", "bar" })) - .contains((String) getResults().get(2))); + assertTrue(new HashSet(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2))); } @Test @@ -1397,8 +1348,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sRandMember("myset")); - assertTrue(new HashSet(Arrays.asList(new String[] { "foo", "bar" })) - .contains((String) getResults().get(2))); + assertTrue(new HashSet(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2))); } @Test @@ -1442,9 +1392,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sRem("myset", "foo")); actual.add(connection.sRem("myset", "baz")); actual.add(connection.sMembers("myset")); - verifyResults( - Arrays.asList(new Object[] { 1l, 1l, 1l, 0l, - new HashSet(Collections.singletonList("bar")) })); + verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l, new HashSet(Collections.singletonList("bar")) })); } @Test @@ -1454,9 +1402,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sAdd("myset", "baz")); actual.add(connection.sRem("myset", "foo", "nope", "baz")); actual.add(connection.sMembers("myset")); - verifyResults( - Arrays.asList(new Object[] { 1l, 1l, 1l, 2l, - new HashSet(Collections.singletonList("bar")) })); + verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 2l, new HashSet(Collections.singletonList("bar")) })); } @Test @@ -1500,7 +1446,7 @@ public abstract class AbstractConnectionIntegrationTests { strTuples.add(new DefaultStringTuple("James".getBytes(), "James", 1.0)); Set tuples = new HashSet(); tuples.add(new DefaultTuple("Joe".getBytes(), 2.5)); - actual.add(connection.zAdd("myset",strTuples)); + actual.add(connection.zAdd("myset", strTuples)); actual.add(connection.zAdd("myset".getBytes(), tuples)); actual.add(connection.zRange("myset", 0, -1)); verifyResults(Arrays.asList(new Object[] { 2l, 1l, @@ -1531,9 +1477,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 4, "Joe")); actual.add(connection.zIncrBy("myset", 2, "Joe")); actual.add(connection.zRangeByScore("myset", 6, 6)); - verifyResults( - Arrays.asList(new Object[] { true, true, true, 6d, - new LinkedHashSet(Collections.singletonList("Joe")) })); + verifyResults(Arrays.asList(new Object[] { true, true, true, 6d, + new LinkedHashSet(Collections.singletonList("Joe")) })); } @Test @@ -1556,21 +1501,19 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 4, "Joe")); actual.add(connection.zAdd("otherset", 1, "Bob")); actual.add(connection.zAdd("otherset", 4, "James")); - actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", - "otherset")); + actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset")); actual.add(connection.zRangeWithScores("thirdset", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { - true, - true, - true, - true, - true, - 2l, - new LinkedHashSet(Arrays.asList(new StringTuple[] { - new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), - new DefaultStringTuple("James".getBytes(), "James", 12d) })) })); + verifyResults(Arrays.asList(new Object[] { + true, + true, + true, + true, + true, + 2l, + new LinkedHashSet(Arrays.asList(new StringTuple[] { + new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), + new DefaultStringTuple("James".getBytes(), "James", 12d) })) })); } @Test @@ -1578,13 +1521,12 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRangeWithScores("myset", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { - true, - true, - new LinkedHashSet(Arrays.asList(new StringTuple[] { - new DefaultStringTuple("James".getBytes(), "James", 1d), - new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) })); + verifyResults(Arrays.asList(new Object[] { + true, + true, + new LinkedHashSet(Arrays.asList(new StringTuple[] { + new DefaultStringTuple("James".getBytes(), "James", 1d), + new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) })); } @Test @@ -1593,7 +1535,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRangeByScore("myset", 1, 1)); verifyResults(Arrays.asList(new Object[] { true, true, - new LinkedHashSet(Arrays.asList(new String[] { "James" })) })); + new LinkedHashSet(Arrays.asList(new String[] { "James" })) })); } @Test @@ -1601,9 +1543,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRangeByScore("myset", 1d, 3d, 1, -1)); - verifyResults( - Arrays.asList(new Object[] { true, true, - new LinkedHashSet(Arrays.asList(new String[] { "Bob" })) })); + verifyResults(Arrays.asList(new Object[] { true, true, + new LinkedHashSet(Arrays.asList(new String[] { "Bob" })) })); } @Test @@ -1614,9 +1555,8 @@ public abstract class AbstractConnectionIntegrationTests { verifyResults(Arrays.asList(new Object[] { true, true, - new LinkedHashSet(Arrays - .asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", - 2d) })) })); + new LinkedHashSet(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), + "Bob", 2d) })) })); } @Test @@ -1627,9 +1567,8 @@ public abstract class AbstractConnectionIntegrationTests { verifyResults(Arrays.asList(new Object[] { true, true, - new LinkedHashSet(Arrays - .asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), - "James", 1d) })) })); + new LinkedHashSet(Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), + "James", 1d) })) })); } @Test @@ -1646,13 +1585,12 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRevRangeWithScores("myset", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { - true, - true, - new LinkedHashSet(Arrays.asList(new StringTuple[] { - new DefaultStringTuple("Bob".getBytes(), "Bob", 2d), - new DefaultStringTuple("James".getBytes(), "James", 1d) })) })); + verifyResults(Arrays.asList(new Object[] { + true, + true, + new LinkedHashSet(Arrays.asList(new StringTuple[] { + new DefaultStringTuple("Bob".getBytes(), "Bob", 2d), + new DefaultStringTuple("James".getBytes(), "James", 1d) })) })); } @Test @@ -1660,8 +1598,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes())); actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes())); actual.add(connection.zRevRangeByScore("myset", 0d, 3d, 0, 5)); - verifyResults(Arrays.asList(new Object[] {true, true, - new LinkedHashSet(Arrays.asList(new String[] { "Bob", "James" }))})); + verifyResults(Arrays.asList(new Object[] { true, true, + new LinkedHashSet(Arrays.asList(new String[] { "Bob", "James" })) })); } @Test @@ -1669,8 +1607,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes())); actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes())); actual.add(connection.zRevRangeByScore("myset", 0d, 3d)); - verifyResults(Arrays.asList(new Object[] {true, true, - new LinkedHashSet(Arrays.asList(new String[] { "Bob", "James" }))})); + verifyResults(Arrays.asList(new Object[] { true, true, + new LinkedHashSet(Arrays.asList(new String[] { "Bob", "James" })) })); } @Test @@ -1678,9 +1616,11 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes())); actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes())); actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 3d, 0, 1)); - verifyResults(Arrays.asList(new Object[] {true, true, - new LinkedHashSet(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob" - .getBytes(), "Bob", 2d) }))})); + verifyResults(Arrays.asList(new Object[] { + true, + true, + new LinkedHashSet(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), + "Bob", 2d) })) })); } @Test @@ -1689,10 +1629,13 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 3, "Joe")); actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 2d)); - verifyResults(Arrays.asList(new Object[] {true, true, true, + verifyResults(Arrays.asList(new Object[] { + true, + true, + true, new LinkedHashSet(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d), - new DefaultStringTuple("James".getBytes(), "James", 1d) }))})); + new DefaultStringTuple("James".getBytes(), "James", 1d) })) })); } @Test @@ -1710,9 +1653,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRem("myset", "James")); actual.add(connection.zRange("myset", 0l, -1l)); - verifyResults( - Arrays.asList(new Object[] { true, true, 1l, - new LinkedHashSet(Arrays.asList(new String[] { "Bob" })) })); + verifyResults(Arrays.asList(new Object[] { true, true, 1l, + new LinkedHashSet(Arrays.asList(new String[] { "Bob" })) })); } @Test @@ -1723,9 +1665,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 2.5, "Jen")); actual.add(connection.zRem("myset", "James", "Jen")); actual.add(connection.zRange("myset", 0l, -1l)); - verifyResults( - Arrays.asList(new Object[] { true, true, true, true, 2l, - new LinkedHashSet(Arrays.asList(new String[] { "Joe", "Bob" })) })); + verifyResults(Arrays.asList(new Object[] { true, true, true, true, 2l, + new LinkedHashSet(Arrays.asList(new String[] { "Joe", "Bob" })) })); } @Test @@ -1743,9 +1684,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRemRangeByScore("myset", 0d, 1d)); actual.add(connection.zRange("myset", 0l, -1l)); - verifyResults( - Arrays.asList(new Object[] { true, true, 1l, - new LinkedHashSet(Arrays.asList(new String[] { "Bob" })) })); + verifyResults(Arrays.asList(new Object[] { true, true, 1l, + new LinkedHashSet(Arrays.asList(new String[] { "Bob" })) })); } @Test @@ -1775,16 +1715,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("otherset", 4, "James")); actual.add(connection.zUnionStore("thirdset", "myset", "otherset")); actual.add(connection.zRange("thirdset", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { - true, - true, - true, - true, - true, - 3l, - new LinkedHashSet(Arrays.asList(new String[] { "Bob", "James", - "Joe" })) })); + verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 3l, + new LinkedHashSet(Arrays.asList(new String[] { "Bob", "James", "Joe" })) })); } @Test @@ -1794,21 +1726,18 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset", 4, "Joe")); actual.add(connection.zAdd("otherset", 1, "Bob")); actual.add(connection.zAdd("otherset", 4, "James")); - actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", - "otherset")); + actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset")); actual.add(connection.zRangeWithScores("thirdset", 0, -1)); - verifyResults( - Arrays.asList(new Object[] { - true, - true, - true, - true, - true, - 3l, - new LinkedHashSet(Arrays.asList(new StringTuple[] { - new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), - new DefaultStringTuple("Joe".getBytes(), "Joe", 8d), - new DefaultStringTuple("James".getBytes(), "James", 12d) })) })); + verifyResults(Arrays.asList(new Object[] { + true, + true, + true, + true, + true, + 3l, + new LinkedHashSet(Arrays.asList(new StringTuple[] { + new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), new DefaultStringTuple("Joe".getBytes(), "Joe", 8d), + new DefaultStringTuple("James".getBytes(), "James", 12d) })) })); } // Hash Ops @@ -1880,7 +1809,7 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.hSet("test", "key2", "2")); actual.add(connection.hKeys("test")); verifyResults(Arrays.asList(new Object[] { true, true, - new LinkedHashSet(Arrays.asList(new String[] { "key", "key2" })) })); + new LinkedHashSet(Arrays.asList(new String[] { "key", "key2" })) })); } @Test @@ -1906,21 +1835,19 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.hSet("test", "key", "foo")); actual.add(connection.hSet("test", "key2", "bar")); actual.add(connection.hVals("test")); - verifyResults( - Arrays.asList(new Object[] { true, true, - Arrays.asList(new String[] { "foo", "bar" }) })); + verifyResults(Arrays.asList(new Object[] { true, true, Arrays.asList(new String[] { "foo", "bar" }) })); } @Test public void testMove() { connection.set("foo", "bar"); actual.add(connection.move("foo", 1)); - verifyResults(Arrays.asList(new Object[] { true})); + verifyResults(Arrays.asList(new Object[] { true })); connection.select(1); try { - assertEquals("bar",connection.get("foo")); + assertEquals("bar", connection.get("foo")); } finally { - if(connection.exists("foo")) { + if (connection.exists("foo")) { connection.del("foo"); } } @@ -1956,4 +1883,4 @@ public abstract class AbstractConnectionIntegrationTests { return (!connection.exists(key)); } } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java index 892aebe60..8f2d8738d 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java @@ -27,50 +27,40 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** - * Base test class for integration tests that execute each operation of a - * Connection while a pipeline is open, verifying that the operations return - * null and the proper values are returned when closing the pipeline. + * Base test class for integration tests that execute each operation of a Connection while a pipeline is open, verifying + * that the operations return null and the proper values are returned when closing the pipeline. *

- * Pipelined results are generally native to the provider and not transformed by - * our {@link RedisConnection}, so this test overrides - * {@link AbstractConnectionIntegrationTests} when result types are different - * + * Pipelined results are generally native to the provider and not transformed by our {@link RedisConnection}, so this + * test overrides {@link AbstractConnectionIntegrationTests} when result types are different + * * @author Jennifer Hickey - * */ -abstract public class AbstractConnectionPipelineIntegrationTests extends - AbstractConnectionIntegrationTests { +abstract public class AbstractConnectionPipelineIntegrationTests extends AbstractConnectionIntegrationTests { @Ignore - public void testNullKey() throws Exception { - } + public void testNullKey() throws Exception {} @Ignore - public void testNullValue() throws Exception { - } + public void testNullValue() throws Exception {} @Ignore - public void testHashNullKey() throws Exception { - } + public void testHashNullKey() throws Exception {} @Ignore - public void testHashNullValue() throws Exception { - } + public void testHashNullValue() throws Exception {} @Ignore("Pub/Sub not supported while pipelining") - public void testPubSubWithNamedChannels() throws Exception { - } + public void testPubSubWithNamedChannels() throws Exception {} @Ignore("Pub/Sub not supported while pipelining") - public void testPubSubWithPatterns() throws Exception { - } + public void testPubSubWithPatterns() throws Exception {} - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) public void testExecWithoutMulti() { super.testExecWithoutMulti(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) public void testErrorInTx() { super.testErrorInTx(); } @@ -104,20 +94,20 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends super.testRestoreExistingKey(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalArrayScriptError() { super.testEvalArrayScriptError(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayError() { super.testEvalShaArrayError(); } @Test - public void testOpenPipelineTwice() { + public void testOpenPipelineTwice() { connection.openPipeline(); // ensure things still proceed normally with an extra openPipeline testGetSet(); @@ -146,13 +136,13 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends protected List getResults() { - try { - //we give redis some time to keep up - Thread.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } + try { + // we give redis some time to keep up + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); + } - return connection.closePipeline(); + return connection.closePipeline(); } } diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionTransactionIntegrationTests.java index 950fbed4c..6e7d419a7 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionTransactionIntegrationTests.java @@ -9,34 +9,27 @@ import org.junit.Ignore; import org.junit.Test; import org.springframework.test.annotation.IfProfileValue; -abstract public class AbstractConnectionTransactionIntegrationTests extends - AbstractConnectionIntegrationTests { +abstract public class AbstractConnectionTransactionIntegrationTests extends AbstractConnectionIntegrationTests { @Ignore - public void testMultiDiscard() { - } + public void testMultiDiscard() {} @Ignore - public void testMultiExec() { - } + public void testMultiExec() {} @Ignore - public void testUnwatch() { - } + public void testUnwatch() {} @Ignore - public void testWatch() { - } + public void testWatch() {} @Ignore @Test - public void testExecWithoutMulti() { - } + public void testExecWithoutMulti() {} @Ignore @Test - public void testErrorInTx() { - } + public void testErrorInTx() {} /* * Using blocking ops inside a tx does not make a lot of sense as it would require blocking the @@ -45,52 +38,40 @@ abstract public class AbstractConnectionTransactionIntegrationTests extends */ @Ignore - public void testBLPop() { - } + public void testBLPop() {} @Ignore - public void testBRPop() { - } + public void testBRPop() {} @Ignore - public void testBRPopLPush() { - } + public void testBRPopLPush() {} @Ignore - public void testBLPopTimeout() { - } + public void testBLPopTimeout() {} @Ignore - public void testBRPopTimeout() { - } + public void testBRPopTimeout() {} @Ignore - public void testBRPopLPushTimeout() { - } + public void testBRPopLPushTimeout() {} @Ignore("Pub/Sub not supported with transactions") - public void testPubSubWithNamedChannels() throws Exception { - } + public void testPubSubWithNamedChannels() throws Exception {} @Ignore("Pub/Sub not supported with transactions") - public void testPubSubWithPatterns() throws Exception { - } + public void testPubSubWithPatterns() throws Exception {} @Ignore - public void testNullKey() throws Exception { - } + public void testNullKey() throws Exception {} @Ignore - public void testNullValue() throws Exception { - } + public void testNullValue() throws Exception {} @Ignore - public void testHashNullKey() throws Exception { - } + public void testHashNullKey() throws Exception {} @Ignore - public void testHashNullValue() throws Exception { - } + public void testHashNullValue() throws Exception {} @Test(expected = UnsupportedOperationException.class) public void testWatchWhileInTx() { diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java index 02db76704..951309090 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java @@ -28,9 +28,8 @@ import org.junit.Test; /** * Unit test of {@link DefaultStringRedisConnection} that executes commands in a pipeline - * + * * @author Jennifer Hickey - * */ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedisConnectionTests { @@ -152,7 +151,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi connection.lLen(fooBytes); connection.exec(); // closePipeline should only return the results of exec, not of llen - verifyResults(Arrays.asList(new Object[] {results})); + verifyResults(Arrays.asList(new Object[] { results })); } @Test @@ -973,15 +972,13 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testTypeBytes() { - doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection) - .closePipeline(); + doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).closePipeline(); super.testTypeBytes(); } @Test public void testType() { - doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection) - .closePipeline(); + doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).closePipeline(); super.testType(); } @@ -1426,8 +1423,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi // Only call one method, but return 2 results from nativeConnection.closePipeline() // Emulates scenario where user has called some methods directly on the native connection // while pipeline is open - doReturn(Arrays.asList(new Object[] { barBytes, 3l })).when(nativeConnection) - .closePipeline(); + doReturn(Arrays.asList(new Object[] { barBytes, 3l })).when(nativeConnection).closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); connection.get(foo); verifyResults(Arrays.asList(new Object[] { barBytes, 3l })); diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java index fecb514f9..29354d069 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java @@ -12,8 +12,7 @@ import java.util.Properties; import org.junit.Before; import org.junit.Test; -public class DefaultStringRedisConnectionPipelineTxTests extends - DefaultStringRedisConnectionTxTests { +public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRedisConnectionTxTests { @Before public void setUp() { @@ -23,380 +22,420 @@ public class DefaultStringRedisConnectionPipelineTxTests extends @Test public void testAppend() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testAppend(); } @Test public void testAppendBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testAppendBytes(); } @Test public void testBlPopBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testBlPopBytes(); } @Test public void testBlPop() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testBlPop(); } @Test public void testBrPopBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testBrPopBytes(); } @Test public void testBrPop() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testBrPop(); } @Test public void testBrPopLPushBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testBrPopLPushBytes(); } @Test public void testBrPopLPush() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testBrPopLPush(); } @Test public void testDbSize() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testDbSize(); } @Test public void testDecrBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testDecrBytes(); } @Test public void testDecr() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testDecr(); } @Test public void testDecrByBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testDecrByBytes(); } @Test public void testDecrBy() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testDecrBy(); } @Test public void testDelBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testDelBytes(); } @Test public void testDel() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testDel(); } @Test public void testEchoBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testEchoBytes(); } @Test public void testEcho() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testEcho(); } @Test public void testExistsBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testExistsBytes(); } @Test public void testExists() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testExists(); } @Test public void testExpireBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testExpireBytes(); } @Test public void testExpire() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testExpire(); } @Test public void testExpireAtBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testExpireAtBytes(); } @Test public void testExpireAt() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testExpireAt(); } @Test public void testGetBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testGetBytes(); } @Test public void testGet() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testGet(); } @Test public void testGetBitBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testGetBitBytes(); } @Test public void testGetBit() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testGetBit(); } @Test public void testGetConfig() { List results = Collections.singletonList("bar"); - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { results })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { results }) })).when(nativeConnection) + .closePipeline(); super.testGetConfig(); } @Test public void testGetNativeConnection() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testGetNativeConnection(); } @Test public void testGetRangeBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testGetRangeBytes(); } @Test public void testGetRange() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testGetRange(); } @Test public void testGetSetBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testGetSetBytes(); } @Test public void testGetSet() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testGetSet(); } @Test public void testHDelBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testHDelBytes(); } @Test public void testHDel() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testHDel(); } @Test public void testHExistsBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testHExistsBytes(); } @Test public void testHExists() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testHExists(); } @Test public void testHGetBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testHGetBytes(); } @Test public void testHGet() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testHGet(); } @Test public void testHGetAllBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesMap })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesMap }) })).when(nativeConnection) + .closePipeline(); super.testHGetAllBytes(); } @Test public void testHGetAll() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesMap })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesMap }) })).when(nativeConnection) + .closePipeline(); super.testHGetAll(); } @Test public void testHIncrByBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testHIncrByBytes(); } @Test public void testHIncrBy() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testHIncrBy(); } @Test public void testHIncrByDoubleBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3d })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); super.testHIncrByDoubleBytes(); } @Test public void testHIncrByDouble() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3d })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); super.testHIncrByDouble(); } @Test public void testHKeysBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testHKeysBytes(); } @Test public void testHKeys() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testHKeys(); } @Test public void testHLenBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testHLenBytes(); } @Test public void testHLen() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testHLen(); } @Test public void testHMGetBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testHMGetBytes(); } @Test public void testHMGet() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testHMGet(); } @Test public void testHSetBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testHSetBytes(); } @Test public void testHSet() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testHSet(); } @Test public void testHSetNXBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testHSetNXBytes(); } @Test public void testHSetNX() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testHSetNX(); } @Test public void testHValsBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testHValsBytes(); } @Test public void testHVals() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testHVals(); } @Test public void testIncrBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 2l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); super.testIncrBytes(); } @Test public void testIncr() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 2l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); super.testIncr(); } @Test public void testIncrByBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 2l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); super.testIncrByBytes(); } @Test public void testIncrBy() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 2l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); super.testIncrBy(); } @Test public void testIncrByDoubleBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 2d })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2d }) })).when(nativeConnection).closePipeline(); super.testIncrByDoubleBytes(); } @Test public void testIncrByDouble() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 2d })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2d }) })).when(nativeConnection).closePipeline(); super.testIncrByDouble(); } @@ -404,7 +443,8 @@ public class DefaultStringRedisConnectionPipelineTxTests extends public void testInfo() { Properties props = new Properties(); props.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { props })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { props }) })).when(nativeConnection) + .closePipeline(); super.testInfo(); } @@ -412,971 +452,1059 @@ public class DefaultStringRedisConnectionPipelineTxTests extends public void testInfoBySection() { Properties props = new Properties(); props.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { props })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { props }) })).when(nativeConnection) + .closePipeline(); super.testInfoBySection(); } @Test public void testKeysBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testKeysBytes(); } @Test public void testKeys() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testKeys(); } @Test public void testLastSave() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 6l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 6l }) })).when(nativeConnection).closePipeline(); super.testLastSave(); } @Test public void testLIndexBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testLIndexBytes(); } @Test public void testLIndex() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testLIndex(); } @Test public void testLInsertBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLInsertBytes(); } @Test public void testLInsert() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLInsert(); } @Test public void testLLenBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLLenBytes(); } @Test public void testLLen() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLLen(); } @Test public void testLPopBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); actual.add(connection.lPop(fooBytes)); verifyResults(Arrays.asList(new Object[] { barBytes })); } @Test public void testLPop() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testLPop(); } @Test public void testLPushBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLPushBytes(); } @Test public void testLPush() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLPush(); } @Test public void testLPushXBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLPushXBytes(); } @Test public void testLPushX() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLPushX(); } @Test public void testLRangeBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testLRangeBytes(); } @Test public void testLRange() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testLRange(); } @Test public void testLRemBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLRemBytes(); } @Test public void testLRem() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 8l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); super.testLRem(); } @Test public void testMGetBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testMGetBytes(); } @Test public void testMGet() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testMGet(); } @Test public void testMSetNXBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testMSetNXBytes(); } @Test public void testMSetNXString() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testMSetNXString(); } @Test public void testPersistBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testPersistBytes(); } @Test public void testPersist() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testPersist(); } @Test public void testMoveBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testMoveBytes(); } @Test public void testMove() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testMove(); } @Test public void testPing() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "pong" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "pong" }) })).when(nativeConnection) + .closePipeline(); super.testPing(); } @Test public void testPublishBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 2l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); super.testPublishBytes(); } @Test public void testPublish() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 2l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); super.testPublish(); } @Test public void testRandomKey() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { fooBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { fooBytes }) })).when(nativeConnection) + .closePipeline(); super.testRandomKey(); } @Test public void testRenameNXBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testRenameNXBytes(); } @Test public void testRenameNX() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testRenameNX(); } @Test public void testRPopBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testRPopBytes(); } @Test public void testRPop() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testRPop(); } @Test public void testRPopLPushBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testRPopLPushBytes(); } @Test public void testRPopLPush() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testRPopLPush(); } @Test public void testRPushBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 4l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); super.testRPushBytes(); } @Test public void testRPush() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 4l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); super.testRPush(); } @Test public void testRPushXBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 4l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); super.testRPushXBytes(); } @Test public void testRPushX() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 4l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); super.testRPushX(); } @Test public void testSAddBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testSAddBytes(); } @Test public void testSAdd() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testSAdd(); } @Test public void testSCardBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 4l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); super.testSCardBytes(); } @Test public void testSCard() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 4l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); super.testSCard(); } @Test public void testSDiffBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testSDiffBytes(); } @Test public void testSDiff() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testSDiff(); } @Test public void testSDiffStoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testSDiffStoreBytes(); } @Test public void testSDiffStore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testSDiffStore(); } @Test public void testSetNXBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testSetNXBytes(); } @Test public void testSetNX() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testSetNX(); } @Test public void testSInterBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testSInterBytes(); } @Test public void testSInter() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testSInter(); } @Test public void testSInterStoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testSInterStoreBytes(); } @Test public void testSInterStore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testSInterStore(); } @Test public void testSIsMemberBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testSIsMemberBytes(); } @Test public void testSIsMember() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testSIsMember(); } @Test public void testSMembersBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testSMembersBytes(); } @Test public void testSMembers() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testSMembers(); } @Test public void testSMoveBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testSMoveBytes(); } @Test public void testSMove() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testSMove(); } @Test public void testSortStoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testSortStoreBytes(); } @Test public void testSortStore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); super.testSortStore(); } @Test public void testSortBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testSortBytes(); } @Test public void testSort() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testSort(); } @Test public void testSPopBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testSPopBytes(); } @Test public void testSPop() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testSPop(); } @Test public void testSRandMemberBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testSRandMemberBytes(); } @Test public void testSRandMember() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testSRandMember(); } @Test public void testSRandMemberCountBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testSRandMemberCountBytes(); } @Test public void testSRandMemberCount() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesList })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + .closePipeline(); super.testSRandMemberCount(); } @Test public void testSRemBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testSRemBytes(); } @Test public void testSRem() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testSRem(); } @Test public void testStrLenBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testStrLenBytes(); } @Test public void testStrLen() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testStrLen(); } @Test public void testBitCountBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testBitCountBytes(); } @Test public void testBitCount() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testBitCount(); } @Test public void testBitCountRangeBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testBitCountRangeBytes(); } @Test public void testBitCountRange() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testBitCountRange(); } @Test public void testBitOpBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testBitOpBytes(); } @Test public void testBitOp() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testBitOp(); } @Test public void testSUnionBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testSUnionBytes(); } @Test public void testSUnion() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testSUnion(); } @Test public void testSUnionStoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testSUnionStoreBytes(); } @Test public void testSUnionStore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testSUnionStore(); } @Test public void testTtlBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testTtlBytes(); } @Test public void testTtl() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testTtl(); } @Test public void testTypeBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { DataType.HASH })})).when(nativeConnection) + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { DataType.HASH }) })).when(nativeConnection) .closePipeline(); super.testTypeBytes(); } @Test public void testType() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { DataType.HASH })})).when(nativeConnection) + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { DataType.HASH }) })).when(nativeConnection) .closePipeline(); super.testType(); } @Test public void testZAddBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testZAddBytes(); } @Test public void testZAdd() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testZAdd(); } @Test public void testZAddMultipleBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testZAddMultipleBytes(); } @Test public void testZAddMultiple() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testZAddMultiple(); } @Test public void testZCardBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZCardBytes(); } @Test public void testZCard() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZCard(); } @Test public void testZCountBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZCountBytes(); } @Test public void testZCount() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZCount(); } @Test public void testZIncrByBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3d })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); super.testZIncrByBytes(); } @Test public void testZIncrBy() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3d })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); super.testZIncrBy(); } @Test public void testZInterStoreAggWeightsBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZInterStoreAggWeightsBytes(); } @Test public void testZInterStoreAggWeights() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZInterStoreAggWeights(); } @Test public void testZInterStoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZInterStoreBytes(); } @Test public void testZInterStore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZInterStore(); } @Test public void testZRangeBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeBytes(); } @Test public void testZRange() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRange(); } @Test public void testZRangeByScoreOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeByScoreOffsetCountBytes(); } @Test public void testZRangeByScoreOffsetCount() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeByScoreOffsetCount(); } @Test public void testZRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeByScoreBytes(); } @Test public void testZRangeByScore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeByScore(); } @Test public void testZRangeByScoreWithScoresOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeByScoreWithScoresOffsetCountBytes(); } @Test public void testZRangeByScoreWithScoresOffsetCount() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeByScoreWithScoresOffsetCount(); } @Test public void testZRangeByScoreWithScoresBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeByScoreWithScoresBytes(); } @Test public void testZRangeByScoreWithScores() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeByScoreWithScores(); } @Test public void testZRangeWithScoresBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeWithScoresBytes(); } @Test public void testZRangeWithScores() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRangeWithScores(); } @Test public void testZRevRangeByScoreOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeByScoreOffsetCountBytes(); } @Test public void testZRevRangeByScoreOffsetCount() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeByScoreOffsetCount(); } @Test public void testZRevRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeByScoreBytes(); } @Test public void testZRevRangeByScore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeByScore(); } @Test public void testZRevRangeByScoreWithScoresOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeByScoreWithScoresOffsetCountBytes(); } @Test public void testZRevRangeByScoreWithScoresOffsetCount() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeByScoreWithScoresOffsetCount(); } @Test public void testZRevRangeByScoreWithScoresBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeByScoreWithScoresBytes(); } @Test public void testZRevRangeByScoreWithScores() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeByScoreWithScores(); } @Test public void testZRankBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZRankBytes(); } @Test public void testZRank() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZRank(); } @Test public void testZRemBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testZRemBytes(); } @Test public void testZRem() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); super.testZRem(); } @Test public void testZRemRangeBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZRemRangeBytes(); } @Test public void testZRemRange() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZRemRange(); } @Test public void testZRemRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZRemRangeByScoreBytes(); } @Test public void testZRemRangeByScore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZRemRangeByScore(); } @Test public void testZRevRangeBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeBytes(); } @Test public void testZRevRange() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bytesSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRange(); } @Test public void testZRevRangeWithScoresBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeWithScoresBytes(); } @Test public void testZRevRangeWithScores() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { tupleSet })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + .closePipeline(); super.testZRevRangeWithScores(); } @Test public void testZRevRankBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZRevRankBytes(); } @Test public void testZRevRank() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZRevRank(); } @Test public void testZScoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3d })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); super.testZScoreBytes(); } @Test public void testZScore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 3d })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); super.testZScore(); } @Test public void testZUnionStoreAggWeightsBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZUnionStoreAggWeightsBytes(); } @Test public void testZUnionStoreAggWeights() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZUnionStoreAggWeights(); } @Test public void testZUnionStoreBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZUnionStoreBytes(); } @Test public void testZUnionStore() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testZUnionStore(); } @Test public void testPExpireBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testPExpireBytes(); } @Test public void testPExpire() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testPExpire(); } @Test public void testPExpireAtBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testPExpireAtBytes(); } @Test public void testPExpireAt() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + .closePipeline(); super.testPExpireAt(); } @Test public void testPTtlBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testPTtlBytes(); } @Test public void testPTtl() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 5l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); super.testPTtl(); } @Test public void testDump() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); super.testDump(); } @Test public void testScriptLoadBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testScriptLoadBytes(); } @Test public void testScriptLoad() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testScriptLoad(); } @Test public void testScriptExists() { List results = Collections.singletonList(true); - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { results })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { results }) })).when(nativeConnection) + .closePipeline(); super.testScriptExists(); } @Test public void testEvalBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testEvalBytes(); } @Test public void testEval() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testEval(); } @Test public void testEvalShaBytes() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testEvalShaBytes(); } @Test public void testEvalSha() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testEvalSha(); } @Test public void testExecute() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testExecute(); } @Test public void testExecuteByteArgs() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testExecuteByteArgs(); } @Test public void testExecuteStringArgs() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { "foo" })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + .closePipeline(); super.testExecuteStringArgs(); } @@ -1385,7 +1513,8 @@ public class DefaultStringRedisConnectionPipelineTxTests extends // Only call one method, but return 2 results from nativeConnection.exec() // Emulates scenario where user has called some methods directly on the native connection // while tx is open - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes, 3l })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes, 3l }) })).when(nativeConnection) + .closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); connection.get(foo); verifyResults(Arrays.asList(new Object[] { barBytes, 3l })); @@ -1393,15 +1522,17 @@ public class DefaultStringRedisConnectionPipelineTxTests extends @Test public void testTwoTxs() { - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes }), - Arrays.asList(new Object[] { fooBytes })})).when(nativeConnection).closePipeline(); + doReturn( + Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }), Arrays.asList(new Object[] { fooBytes }) })) + .when(nativeConnection).closePipeline(); connection.get(foo); connection.exec(); connection.get(bar); connection.exec(); - List results = connection.closePipeline(); - assertEquals(Arrays.asList(new Object[] {Arrays.asList(new Object[] { bar }), - Arrays.asList(new Object[] { foo })}), results); + List results = connection.closePipeline(); + assertEquals( + Arrays.asList(new Object[] { Arrays.asList(new Object[] { bar }), Arrays.asList(new Object[] { foo }) }), + results); } @SuppressWarnings("unchecked") diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java index 6a06131d7..47f5bfff6 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java @@ -43,16 +43,14 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; /** * Unit test of {@link DefaultStringRedisConnection} - * + * * @author Jennifer Hickey - * */ public class DefaultStringRedisConnectionTests { protected List actual = new ArrayList(); - @Mock - protected RedisConnection nativeConnection; + @Mock protected RedisConnection nativeConnection; protected DefaultStringRedisConnection connection; @@ -78,8 +76,7 @@ public class DefaultStringRedisConnectionTests { protected Map stringMap = new HashMap(); - protected Set tupleSet = new HashSet(Collections.singletonList(new DefaultTuple( - barBytes, 3d))); + protected Set tupleSet = new HashSet(Collections.singletonList(new DefaultTuple(barBytes, 3d))); protected Set stringTupleSet = new HashSet( Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar))); @@ -1254,16 +1251,14 @@ public class DefaultStringRedisConnectionTests { @Test public void testZInterStoreAggWeightsBytes() { - doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], - fooBytes); + doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes); actual.add(connection.zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes)); verifyResults(Arrays.asList(new Object[] { 5l })); } @Test public void testZInterStoreAggWeights() { - doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], - fooBytes); + doReturn(5l).when(nativeConnection).zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes); actual.add(connection.zInterStore(foo, Aggregate.MAX, new int[0], foo)); verifyResults(Arrays.asList(new Object[] { 5l })); } @@ -1396,16 +1391,14 @@ public class DefaultStringRedisConnectionTests { @Test public void testZRevRangeByScoreWithScoresOffsetCountBytes() { - doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, - 7l); + doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l); actual.add(connection.zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l)); verifyResults(Arrays.asList(new Object[] { tupleSet })); } @Test public void testZRevRangeByScoreWithScoresOffsetCount() { - doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, - 7l); + doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l); actual.add(connection.zRevRangeByScoreWithScores(foo, 1d, 3d, 5l, 7l)); verifyResults(Arrays.asList(new Object[] { stringTupleSet })); } @@ -1538,16 +1531,14 @@ public class DefaultStringRedisConnectionTests { @Test public void testZUnionStoreAggWeightsBytes() { - doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], - fooBytes); + doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes); actual.add(connection.zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes)); verifyResults(Arrays.asList(new Object[] { 5l })); } @Test public void testZUnionStoreAggWeights() { - doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], - fooBytes); + doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes); actual.add(connection.zUnionStore(foo, Aggregate.MAX, new int[0], foo)); verifyResults(Arrays.asList(new Object[] { 5l })); } diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java index 84f1cb6dc..de9b9b02a 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java @@ -940,15 +940,13 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testTypeBytes() { - doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection) - .exec(); + doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).exec(); super.testTypeBytes(); } @Test public void testType() { - doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection) - .exec(); + doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).exec(); super.testType(); } @@ -1383,7 +1381,8 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne public void testDisablePipelineAndTxDeserialize() { connection.setDeserializePipelineAndTxResults(false); doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).exec(); - doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { barBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + .closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); connection.get(foo); verifyResults(Arrays.asList(new Object[] { barBytes })); @@ -1403,7 +1402,8 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testDiscard() { doReturn(Arrays.asList(new Object[] { fooBytes })).when(nativeConnection).exec(); - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { fooBytes })})).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { fooBytes }) })).when(nativeConnection) + .closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); doReturn(fooBytes).when(nativeConnection).get(barBytes); connection.get(foo); 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 50b39bba8..d36193e1c 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 @@ -45,11 +45,10 @@ import static org.junit.Assert.assertNotNull; /** * Integration test of {@link JedisConnection} - * + * * @author Costin Leau * @author Jennifer Hickey * @author Thomas Darimont - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -66,11 +65,11 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati // error on sending QUIT to Redis } - try{ - connection.close(); - } catch (Exception e) { - //silently close connection - } + try { + connection.close(); + } catch (Exception e) { + // silently close connection + } connection = null; } @@ -85,7 +84,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati factory2.destroy(); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) public void testCreateConnectionWithDbFailure() { JedisConnectionFactory factory2 = new JedisConnectionFactory(); factory2.setDatabase(77); @@ -109,7 +108,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati factory2.destroy(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testZAddSameScores() { Set strTuples = new HashSet(); strTuples.add(new DefaultStringTuple("Bob".getBytes(), "Bob", 2.0)); @@ -117,114 +116,114 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati connection.zAdd("myset", strTuples); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnSingleError() { connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalArrayScriptError() { super.testEvalArrayScriptError(); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaNotFound() { connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2"); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayError() { super.testEvalShaArrayError(); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testRestoreBadData() { super.testRestoreBadData(); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testRestoreExistingKey() { super.testRestoreExistingKey(); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) public void testExecWithoutMulti() { super.testExecWithoutMulti(); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) public void testErrorInTx() { super.testErrorInTx(); } - /** - * Override pub/sub test methods to use a separate connection factory for - * subscribing threads, due to this issue: https://github.com/xetorthio/jedis/issues/445 - */ + /** + * Override pub/sub test methods to use a separate connection factory for subscribing threads, due to this issue: + * https://github.com/xetorthio/jedis/issues/445 + */ @Test public void testPubSubWithNamedChannels() throws Exception { - final String expectedChannel = "channel1"; + final String expectedChannel = "channel1"; final String expectedMessage = "msg"; final BlockingDeque messages = new LinkedBlockingDeque(); MessageListener listener = new MessageListener() { public void onMessage(Message message, byte[] pattern) { - messages.add(message); + messages.add(message); System.out.println("Received message '" + new String(message.getBody()) + "'"); } }; - Thread t = new Thread(){ - { - setDaemon(true); - } - public void run(){ + Thread t = new Thread() { + { + setDaemon(true); + } - RedisConnection con = connectionFactory.getConnection(); - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } + public void run() { - con.publish(expectedChannel.getBytes(),expectedMessage.getBytes()); + RedisConnection con = connectionFactory.getConnection(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } + con.publish(expectedChannel.getBytes(), expectedMessage.getBytes()); - /* - In some clients, unsubscribe happens async of message - receipt, so not all - messages may be received if unsubscribing now. - Connection.close in teardown - will take care of unsubscribing. - */ - if (!(ConnectionUtils.isAsync(connectionFactory))) { - connection.getSubscription().unsubscribe(); - } - con.close(); - } - }; - t.start(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } - connection.subscribe(listener, expectedChannel.getBytes()); + /* + In some clients, unsubscribe happens async of message + receipt, so not all + messages may be received if unsubscribing now. + Connection.close in teardown + will take care of unsubscribing. + */ + if (!(ConnectionUtils.isAsync(connectionFactory))) { + connection.getSubscription().unsubscribe(); + } + con.close(); + } + }; + t.start(); - Message message = messages.poll(5, TimeUnit.SECONDS); + connection.subscribe(listener, expectedChannel.getBytes()); + + Message message = messages.poll(5, TimeUnit.SECONDS); assertNotNull(message); assertEquals(expectedMessage, new String(message.getBody())); assertEquals(expectedChannel, new String(message.getChannel())); - } - + } @Test public void testPubSubWithPatterns() throws Exception { @@ -241,28 +240,29 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati } }; - Thread th = new Thread(){ - { - setDaemon(true); - } + Thread th = new Thread() { + { + setDaemon(true); + } + public void run() { - // open a new connection - RedisConnection con = connectionFactory.getConnection(); - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } + // open a new connection + RedisConnection con = connectionFactory.getConnection(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } con.publish("channel1".getBytes(), expectedMessage.getBytes()); con.publish("channel2".getBytes(), expectedMessage.getBytes()); - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } con.close(); // In some clients, unsubscribe happens async of message @@ -274,7 +274,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati connection.getSubscription().pUnsubscribe(expectedPattern.getBytes()); } } - }; + }; th.start(); connection.pSubscribe(listener, expectedPattern); @@ -300,11 +300,10 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati RedisConnection conn = factory2.getConnection(); try { conn.get(null); - }catch(Exception e) { - } + } catch (Exception e) {} conn.close(); // Make sure we don't end up with broken connection factory2.getConnection().dbSize(); - factory2.destroy(); + factory2.destroy(); } } 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 af32505cd..b5cc571d0 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 @@ -36,14 +36,12 @@ import redis.clients.jedis.JedisPoolConfig; /** * Integration test of {@link JedisConnection} pipeline functionality - * + * * @author Jennifer Hickey - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("JedisConnectionIntegrationTests-context.xml") -public class JedisConnectionPipelineIntegrationTests extends - AbstractConnectionPipelineIntegrationTests { +public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests { @After public void tearDown() { @@ -60,8 +58,7 @@ public class JedisConnectionPipelineIntegrationTests extends } @Ignore("Jedis issue: Pipeline tries to return String instead of List") - public void testGetConfig() { - } + public void testGetConfig() {} @Test public void testWatch() { @@ -69,8 +66,7 @@ public class JedisConnectionPipelineIntegrationTests extends connection.watch("testitnow".getBytes()); // Jedis doesn't actually send commands until you close the pipeline getResults(); - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.set("testitnow", "something"); conn2.close(); // Reopen the pipeline @@ -95,19 +91,18 @@ public class JedisConnectionPipelineIntegrationTests extends getResults(); initConnection(); connection.multi(); - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.set("testitnow", "something"); connection.set("testitnow", "somethingelse"); connection.get("testitnow"); actual.add(connection.exec()); List results = getResults(); List execResults = (List) results.get(0); - assertEquals(Arrays.asList(new Object[] {"somethingelse"}), execResults); + assertEquals(Arrays.asList(new Object[] { "somethingelse" }), execResults); } @Test - //DATAREDIS-213 - Verify connection returns to pool after select + // DATAREDIS-213 - Verify connection returns to pool after select public void testClosePoolPipelinedDbSelect() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(1); @@ -125,127 +120,127 @@ public class JedisConnectionPipelineIntegrationTests extends } // Unsupported Ops - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testScriptLoadEvalSha() { super.testScriptLoadEvalSha(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayStrings() { super.testEvalShaArrayStrings(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaNotFound() { super.testEvalShaNotFound(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayError() { super.testEvalShaArrayError(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalArrayScriptError() { super.testEvalArrayScriptError(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnString() { super.testEvalReturnString(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnNumber() { super.testEvalReturnNumber(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnSingleOK() { super.testEvalReturnSingleOK(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnSingleError() { super.testEvalReturnSingleError(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnFalse() { super.testEvalReturnFalse(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnTrue() { super.testEvalReturnTrue(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayStrings() { super.testEvalReturnArrayStrings(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayNumbers() { super.testEvalReturnArrayNumbers(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayOKs() { super.testEvalReturnArrayOKs(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayFalses() { super.testEvalReturnArrayFalses(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayTrues() { super.testEvalReturnArrayTrues(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testScriptExists() { super.testScriptExists(); } @IfProfileValue(name = "redisVersion", value = "2.6") - @Test(expected=UnsupportedOperationException.class) - public void testScriptKill() throws Exception{ + @Test(expected = UnsupportedOperationException.class) + public void testScriptKill() throws Exception { connection.scriptKill(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testScriptFlush() { connection.scriptFlush(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testInfoBySection() throws Exception { super.testInfoBySection(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testZAddMultiple() { super.testZAddMultiple(); } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineTxIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineTxIntegrationTests.java index 55f9316e3..792f2c81a 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineTxIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineTxIntegrationTests.java @@ -14,23 +14,22 @@ public class JedisConnectionPipelineTxIntegrationTests extends JedisConnectionTr @Ignore("Jedis issue: Pipeline tries to return String instead of List") @Test - public void testGetConfig() { - } + public void testGetConfig() {} - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) public void exceptionExecuteNative() throws Exception { connection.execute("set", "foo"); connection.execute("ZadD", getClass() + "#foo\t0.90\titem"); getResults(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testRestoreBadData() { super.testRestoreBadData(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testRestoreExistingKey() { super.testRestoreExistingKey(); @@ -46,8 +45,8 @@ public class JedisConnectionPipelineTxIntegrationTests extends JedisConnectionTr assertNull(connection.exec()); List pipelined = connection.closePipeline(); // We expect only the results of exec to be in the closed pipeline - assertEquals(1,pipelined.size()); - List txResults = (List)pipelined.get(0); + assertEquals(1, pipelined.size()); + List txResults = (List) pipelined.get(0); // Return exec results and this test should behave exactly like its superclass return txResults; } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java index ce5affc7e..fbbf8fe8e 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java @@ -28,17 +28,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Integration test of {@link JedisConnection} transaction functionality. *

- * Each method of {@link JedisConnection} behaves differently if executed with a - * transaction (i.e. between multi and exec or discard calls), so this test - * covers those branching points - * + * Each method of {@link JedisConnection} behaves differently if executed with a transaction (i.e. between multi and + * exec or discard calls), so this test covers those branching points + * * @author Jennifer Hickey - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("JedisConnectionIntegrationTests-context.xml") -public class JedisConnectionTransactionIntegrationTests extends - AbstractConnectionTransactionIntegrationTests { +public class JedisConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests { @After public void tearDown() { @@ -55,8 +52,7 @@ public class JedisConnectionTransactionIntegrationTests extends } @Ignore("Jedis issue: Transaction tries to return String instead of List") - public void testGetConfig() { - } + public void testGetConfig() {} // Unsupported Ops @Test(expected = UnsupportedOperationException.class) @@ -77,13 +73,13 @@ public class JedisConnectionTransactionIntegrationTests extends super.testEvalShaNotFound(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayError() { super.testEvalShaArrayError(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalArrayScriptError() { super.testEvalArrayScriptError(); @@ -179,18 +175,18 @@ public class JedisConnectionTransactionIntegrationTests extends super.testInfoBySection(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testZAddMultiple() { super.testZAddMultiple(); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testRestoreBadData() { super.testRestoreBadData(); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testRestoreExistingKey() { super.testRestoreExistingKey(); diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisSubscriptionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisSubscriptionTests.java index 6f6d214fe..b64b975e0 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisSubscriptionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisSubscriptionTests.java @@ -34,9 +34,8 @@ import redis.clients.jedis.BinaryJedisPubSub; /** * Unit test of {@link JedisSubscription} - * + * * @author Jennifer Hickey - * */ public class JedisSubscriptionTests { 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 5fa38011d..5ba4660ec 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 @@ -45,10 +45,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Integration test of {@link JredisConnection} - * + * * @author Costin Leau * @author Jennifer Hickey - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -69,32 +68,25 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat } @Ignore("Pub/Sub not supported") - public void testPubSubWithPatterns() { - } + public void testPubSubWithPatterns() {} @Ignore("Pub/Sub not supported") - public void testPubSubWithNamedChannels() { - } + public void testPubSubWithNamedChannels() {} @Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset") - public void testMSet() { - } + public void testMSet() {} @Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset") - public void testMSetNx() { - } + public void testMSetNx() {} @Ignore("https://github.com/alphazero/jredis/issues/64 Protocol error: expected '$' got '*' on mset") - public void testMSetNxFailure() { - } + public void testMSetNxFailure() {} @Ignore("JRedis casts to int") - public void testIncrDecrByLong() { - } + public void testIncrDecrByLong() {} @Ignore("Ping returns status response instead of value response") - public void testExecuteNoArgs() { - } + public void testExecuteNoArgs() {} @Test public void testConnectionClosesWhenNotPooled() { @@ -102,14 +94,13 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat try { connection.ping(); fail("Expected RedisConnectionFailureException trying to use a closed connection"); - } catch (RedisConnectionFailureException e) { - } + } catch (RedisConnectionFailureException e) {} } @Test public void testConnectionStaysOpenWhenPooled() { - JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool( - SettingsUtils.getHost(), SettingsUtils.getPort())); + JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(), + SettingsUtils.getPort())); RedisConnection conn2 = factory2.getConnection(); conn2.close(); conn2.ping(); @@ -120,15 +111,14 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat Config config = new Config(); config.maxActive = 1; config.maxWait = 1; - JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool( - SettingsUtils.getHost(), SettingsUtils.getPort(), config)); + JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(), + SettingsUtils.getPort(), config)); RedisConnection conn2 = factory2.getConnection(); ((JRedis) conn2.getNativeConnection()).quit(); try { conn2.ping(); fail("Expected RedisConnectionFailureException trying to use a closed connection"); - } catch (RedisConnectionFailureException e) { - } + } catch (RedisConnectionFailureException e) {} conn2.close(); // Verify we get a new connection from the pool and not the broken one RedisConnection conn3 = factory2.getConnection(); @@ -160,12 +150,12 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat super.testUnwatch(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testErrorInTx() { super.testErrorInTx(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testExecWithoutMulti() { super.testExecWithoutMulti(); } @@ -319,285 +309,285 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat public void testZRevRangeByScoreWithScoresOffsetCount() { super.testZRevRangeByScoreWithScoresOffsetCount(); } - + @Test(expected = UnsupportedOperationException.class) public void testSelect() { super.testSelect(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPExpire() { super.testPExpire(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPExpireKeyNotExists() { super.testPExpireKeyNotExists(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPExpireAt() { super.testPExpireAt(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPExpireAtKeyNotExists() { super.testPExpireAtKeyNotExists(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPTtl() { super.testPTtl(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testPTtlNoExpire() { super.testPTtlNoExpire(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testDumpAndRestore() { super.testDumpAndRestore(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testDumpNonExistentKey() { super.testDumpNonExistentKey(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRestoreBadData() { super.testRestoreBadData(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRestoreExistingKey() { super.testRestoreExistingKey(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRestoreTtl() { super.testRestoreTtl(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testBitCount() { super.testBitCount(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testBitCountInterval() { super.testBitCountInterval(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testBitCountNonExistentKey() { super.testBitCountNonExistentKey(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testBitOpAnd() { super.testBitOpAnd(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testBitOpOr() { super.testBitOpOr(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testBitOpXOr() { super.testBitOpXOr(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testBitOpNot() { super.testBitOpNot(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testHIncrByDouble() { super.testHIncrByDouble(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testHashIncrDecrByLong() { super.testHashIncrDecrByLong(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testIncrByDouble() { super.testIncrByDouble(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testScriptLoadEvalSha() { super.testScriptLoadEvalSha(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayStrings() { super.testEvalShaArrayStrings(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaNotFound() { super.testEvalShaNotFound(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayError() { super.testEvalShaArrayError(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalArrayScriptError() { super.testEvalArrayScriptError(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnString() { super.testEvalReturnString(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnNumber() { super.testEvalReturnNumber(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnSingleOK() { super.testEvalReturnSingleOK(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnSingleError() { super.testEvalReturnSingleError(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnFalse() { super.testEvalReturnFalse(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnTrue() { super.testEvalReturnTrue(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayStrings() { super.testEvalReturnArrayStrings(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayNumbers() { super.testEvalReturnArrayNumbers(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayOKs() { super.testEvalReturnArrayOKs(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayFalses() { super.testEvalReturnArrayFalses(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayTrues() { super.testEvalReturnArrayTrues(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testScriptExists() { super.testScriptExists(); } - @Test(expected=UnsupportedOperationException.class) - public void testScriptKill() throws Exception{ + @Test(expected = UnsupportedOperationException.class) + public void testScriptKill() throws Exception { connection.scriptKill(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testScriptFlush() { connection.scriptFlush(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testSRandMemberCount() { super.testSRandMemberCount(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testSRandMemberCountKeyNotExists() { super.testSRandMemberCountKeyNotExists(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testSRandMemberCountNegative() { super.testSRandMemberCountNegative(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testInfoBySection() throws Exception { super.testInfoBySection(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testHDelMultiple() { super.testHDelMultiple(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testLPushMultiple() { super.testLPushMultiple(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testRPushMultiple() { super.testRPushMultiple(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testSAddMultiple() { super.testSAddMultiple(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testSRemMultiple() { super.testSRemMultiple(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testZAddMultiple() { super.testZAddMultiple(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testZRemMultiple() { super.testZRemMultiple(); } @@ -674,8 +664,7 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat connection.rPush("PopList", "big"); connection.rPush("PopList", "world"); connection.lSet("PopList", 1, "cruel"); - assertEquals(Arrays.asList(new String[] { "hello", "cruel", "world" }), - connection.lRange("PopList", 0, -1)); + assertEquals(Arrays.asList(new String[] { "hello", "cruel", "world" }), connection.lRange("PopList", 0, -1)); } @Test @@ -732,8 +721,8 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat actual.add(connection.sDiffStore("thirdset", "myset", "otherset")); actual.add(connection.sMembers("thirdset")); // JRedis returns void for sDiffStore, so we always return -1 - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, -1l, - new HashSet(Collections.singletonList("foo")) })); + verifyResults(Arrays + .asList(new Object[] { 1l, 1l, 1l, -1l, new HashSet(Collections.singletonList("foo")) })); } @Test @@ -744,8 +733,8 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat actual.add(connection.sInterStore("thirdset", "myset", "otherset")); actual.add(connection.sMembers("thirdset")); // JRedis returns void for sInterStore, so we always return -1 - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, -1l, - new HashSet(Collections.singletonList("bar")) })); + verifyResults(Arrays + .asList(new Object[] { 1l, 1l, 1l, -1l, new HashSet(Collections.singletonList("bar")) })); } @Test @@ -758,27 +747,27 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat actual.add(connection.sMembers("thirdset")); // JRedis returns void for sUnionStore, so we always return -1 verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, -1l, - new HashSet(Arrays.asList(new String[] { "foo", "bar", "baz" })) })); + new HashSet(Arrays.asList(new String[] { "foo", "bar", "baz" })) })); } @Test public void testMove() { connection.set("foo", "bar"); actual.add(connection.move("foo", 1)); - verifyResults(Arrays.asList(new Object[] { true})); + verifyResults(Arrays.asList(new Object[] { true })); // JRedis does not support select() on existing conn, create new one JredisConnectionFactory factory2 = new JredisConnectionFactory(); factory2.setDatabase(1); factory2.afterPropertiesSet(); StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection()); try { - assertEquals("bar",conn2.get("foo")); + assertEquals("bar", conn2.get("foo")); } finally { - if(conn2.exists("foo")) { + if (conn2.exists("foo")) { conn2.del("foo"); } conn2.close(); } } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/connection/jredis/JredisPoolTests.java b/src/test/java/org/springframework/data/redis/connection/jredis/JredisPoolTests.java index ac69bcd69..18682d152 100644 --- a/src/test/java/org/springframework/data/redis/connection/jredis/JredisPoolTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jredis/JredisPoolTests.java @@ -34,7 +34,6 @@ import static org.junit.Assert.*; * * @author Jennifer Hickey * @author Thomas Darimont - * */ public class JredisPoolTests { @@ -44,8 +43,7 @@ public class JredisPoolTests { @Before public void setUp() { - this.connectionSpec = DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), SettingsUtils.getPort(), - 0, null); + this.connectionSpec = DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), SettingsUtils.getPort(), 0, null); } @After @@ -92,8 +90,7 @@ public class JredisPoolTests { public void testGetResourceCreationUnsuccessful() { // Config poolConfig = new Config(); // poolConfig.testOnBorrow = true; - this.pool = new JredisPool(DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), 3333, 0, - null)); + this.pool = new JredisPool(DefaultConnectionSpec.newSpec(SettingsUtils.getHost(), 3333, 0, null)); pool.getResource(); } @@ -123,8 +120,7 @@ public class JredisPoolTests { try { client.ping(); fail("Broken resouce connection should be closed"); - } catch (NotConnectedException e) { - } + } catch (NotConnectedException e) {} } @Test diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java index e7bf77884..4864b69ad 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java @@ -26,12 +26,10 @@ import org.junit.Ignore; import org.junit.Test; /** - * Integration test of {@link AuthenticatingRedisClient}. Enable requirepass and - * comment out the @Ignore to run. + * Integration test of {@link AuthenticatingRedisClient}. Enable requirepass and comment out the @Ignore to run. * * @author Jennifer Hickey * @author Thomas Darimont - * */ @Ignore("Redis must have requirepass set to run this test") public class AuthenticatingRedisClientTests { @@ -43,26 +41,26 @@ public class AuthenticatingRedisClientTests { client = new AuthenticatingRedisClient("localhost", "foo"); } - @After - public void tearDown(){ - if(client != null){ - client.shutdown(); - } - } + @After + public void tearDown() { + if (client != null) { + client.shutdown(); + } + } @Test public void connect() { RedisConnection conn = client.connect(); conn.ping(); - conn.close(); + conn.close(); } @Test(expected = RedisException.class) public void connectWithInvalidPassword() { - if(client != null){ - client.shutdown(); - } + if (client != null) { + client.shutdown(); + } RedisClient badClient = new AuthenticatingRedisClient("localhost", "notthepassword"); badClient.connect(); @@ -72,35 +70,35 @@ public class AuthenticatingRedisClientTests { public void codecConnect() { RedisConnection conn = client.connect(LettuceConnection.CODEC); conn.ping(); - conn.close(); + conn.close(); } @Test public void connectAsync() { RedisAsyncConnection conn = client.connectAsync(); conn.ping(); - conn.close(); + conn.close(); } @Test public void codecConnectAsync() { RedisAsyncConnection conn = client.connectAsync(LettuceConnection.CODEC); conn.ping(); - conn.close(); + conn.close(); } @Test public void connectPubSub() { RedisPubSubConnection conn = client.connectPubSub(); conn.ping(); - conn.close(); + conn.close(); } @Test public void codecConnectPubSub() { RedisPubSubConnection conn = client.connectPubSub(LettuceConnection.CODEC); conn.ping(); - conn.close(); + conn.close(); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java index 2e3092236..b084590a6 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java @@ -29,23 +29,21 @@ import static org.junit.Assert.*; /** * Unit test of {@link DefaultLettucePool} - * + * * @author Jennifer Hickey * @author Thomas Darimont - * */ -public class - DefaultLettucePoolTests { +public class DefaultLettucePoolTests { private DefaultLettucePool pool; @After public void tearDown() { - if(this.pool != null) { + if (this.pool != null) { - if(this.pool.getClient() != null){ - this.pool.getClient().shutdown(); - } + if (this.pool.getClient() != null) { + this.pool.getClient().shutdown(); + } this.pool.destroy(); } @@ -58,7 +56,7 @@ public class RedisAsyncConnection client = pool.getResource(); assertNotNull(client); client.ping(); - client.close(); + client.close(); } @Test @@ -73,10 +71,9 @@ public class try { pool.getResource(); fail("PoolException should be thrown when pool exhausted"); - } catch (PoolException e) { - }finally{ - client.close(); - } + } catch (PoolException e) {} finally { + client.close(); + } } @Test @@ -87,7 +84,7 @@ public class pool.afterPropertiesSet(); RedisAsyncConnection client = pool.getResource(); assertNotNull(client); - client.close(); + client.close(); } @Test(expected = PoolException.class) @@ -108,7 +105,7 @@ public class assertNotNull(client); pool.returnResource(client); assertNotNull(pool.getResource()); - client.close(); + client.close(); } @Test @@ -126,11 +123,10 @@ public class try { client.ping(); fail("Broken resouce connection should be closed"); - } catch (RedisException e) { - } finally{ - client.close(); - client2.close(); - } + } catch (RedisException e) {} finally { + client.close(); + client2.close(); + } } @Test @@ -165,7 +161,7 @@ public class pool.afterPropertiesSet(); RedisAsyncConnection conn = pool.getResource(); conn.ping(); - conn.close(); + conn.close(); } @Ignore("Redis must have requirepass set to run this test") diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java index cccb0bc25..e6759dff9 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java @@ -32,10 +32,9 @@ import static org.junit.Assert.*; /** * Integration test of {@link LettuceConnectionFactory} - * + * * @author Jennifer Hickey * @author Thomas Darimont - * */ public class LettuceConnectionFactoryTests { @@ -54,9 +53,9 @@ public class LettuceConnectionFactoryTests { public void tearDown() { factory.destroy(); - if(connection != null){ - connection.close(); - } + if (connection != null) { + connection.close(); + } } @SuppressWarnings("rawtypes") @@ -75,12 +74,11 @@ public class LettuceConnectionFactoryTests { } catch (RedisSystemException e) { // expected, shared conn is closed } - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - factory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection()); assertNotSame(nativeConn, conn2.getNativeConnection()); conn2.set("anotherkey", "anothervalue"); assertEquals("anothervalue", conn2.get("anotherkey")); - conn2.close(); + conn2.close(); } @SuppressWarnings("rawtypes") @@ -90,16 +88,15 @@ public class LettuceConnectionFactoryTests { ((RedisAsyncConnection) connection.getNativeConnection()).close(); // Give some time for async channel close Thread.sleep(500); - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - factory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection()); try { conn2.set("anotherkey", "anothervalue"); fail("Expected exception using natively closed conn"); } catch (RedisSystemException e) { // expected, as we are re-using the natively closed conn - }finally{ - conn2.close(); - } + } finally { + conn2.close(); + } } @Test @@ -111,12 +108,10 @@ public class LettuceConnectionFactoryTests { @Test public void testSelectDb() { - LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), - SettingsUtils.getPort()); + LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort()); factory2.setDatabase(1); factory2.afterPropertiesSet(); - StringRedisConnection connection2 = new DefaultStringRedisConnection( - factory2.getConnection()); + StringRedisConnection connection2 = new DefaultStringRedisConnection(factory2.getConnection()); connection2.flushDb(); // put an item in database 0 connection.set("sometestkey", "sometestvalue"); @@ -124,7 +119,7 @@ public class LettuceConnectionFactoryTests { // there should still be nothing in database 1 assertEquals(Long.valueOf(0), connection2.dbSize()); } finally { - connection2.close(); + connection2.close(); factory2.destroy(); } } @@ -156,7 +151,7 @@ public class LettuceConnectionFactoryTests { .getNativeConnection(); factory.resetConnection(); assertNotSame(nativeConn, factory.getConnection().getNativeConnection()); - nativeConn.close(); + nativeConn.close(); } @SuppressWarnings("unchecked") @@ -165,9 +160,9 @@ public class LettuceConnectionFactoryTests { RedisAsyncConnection nativeConn = (RedisAsyncConnection) connection .getNativeConnection(); factory.initConnection(); - RedisConnection newConnection = factory.getConnection(); - assertNotSame(nativeConn, newConnection.getNativeConnection()); - newConnection.close(); + RedisConnection newConnection = factory.getConnection(); + assertNotSame(nativeConn, newConnection.getNativeConnection()); + newConnection.close(); } @SuppressWarnings("unchecked") @@ -177,9 +172,9 @@ public class LettuceConnectionFactoryTests { .getNativeConnection(); factory.resetConnection(); factory.initConnection(); - RedisConnection newConnection = factory.getConnection(); - assertNotSame(nativeConn, newConnection.getNativeConnection()); - newConnection.close(); + RedisConnection newConnection = factory.getConnection(); + assertNotSame(nativeConn, newConnection.getNativeConnection()); + newConnection.close(); } public void testGetConnectionException() { @@ -188,8 +183,7 @@ public class LettuceConnectionFactoryTests { try { factory.getConnection(); fail("Expected connection failure exception"); - } catch(RedisConnectionFailureException e) { - } + } catch (RedisConnectionFailureException e) {} } @Test @@ -210,26 +204,26 @@ public class LettuceConnectionFactoryTests { @Test public void testCreateFactoryWithPool() { - DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), - SettingsUtils.getPort()); + DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort()); pool.afterPropertiesSet(); LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool); factory2.afterPropertiesSet(); - RedisConnection conn2 = factory2.getConnection(); - conn2.close(); - factory2.destroy(); - pool.destroy(); + RedisConnection conn2 = factory2.getConnection(); + conn2.close(); + factory2.destroy(); + pool.destroy(); } @Ignore("Uncomment this test to manually check connection reuse in a pool scenario") @Test public void testLotsOfConnections() throws InterruptedException { - // Running a netstat here should show only the 8 conns from the pool (plus 2 from setUp and 1 from factory2 afterPropertiesSet for shared conn) + // Running a netstat here should show only the 8 conns from the pool (plus 2 from setUp and 1 from factory2 + // afterPropertiesSet for shared conn) DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort()); pool.afterPropertiesSet(); final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool); factory2.afterPropertiesSet(); - for(int i=1;i< 1000;i++) { + for (int i = 1; i < 1000; i++) { Thread th = new Thread(new Runnable() { public void run() { factory2.getConnection().bRPop(50000, "foo".getBytes()); @@ -249,6 +243,6 @@ public class LettuceConnectionFactoryTests { // Test shared and dedicated conns conn.ping(); conn.bLPop(1, "key".getBytes()); - conn.close(); + conn.close(); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java index 7730e1e1c..ad8cf1c11 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java @@ -42,11 +42,10 @@ import static org.springframework.data.redis.SpinBarrier.waitFor; /** * Integration test of {@link LettuceConnection} - * + * * @author Costin Leau * @author Jennifer Hickey * @author Thomas Darimont - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -57,8 +56,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra public void testMultiThreadsOneBlocking() throws Exception { Thread th = new Thread(new Runnable() { public void run() { - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.openPipeline(); conn2.bLPop(3, "multilist"); conn2.closePipeline(); @@ -77,8 +75,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra connection.set("txs1", "rightnow"); connection.multi(); connection.set("txs1", "delay"); - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - connectionFactory.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); // We get immediate results executing command in separate conn (not part // of tx) @@ -91,8 +88,8 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra // Now it should be set assertEquals("delay", conn2.get("txs1")); - conn2.closePipeline(); - conn2.close(); + conn2.closePipeline(); + conn2.close(); } @Test @@ -120,14 +117,12 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra // can't do blocking ops after closing connection.bLPop(1, "what".getBytes()); fail("Expected exception using a closed conn for dedicated ops"); - }catch(RedisSystemException e) { - } + } catch (RedisSystemException e) {} } @Test public void testClosePooledConnectionWithShared() { - DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), - SettingsUtils.getPort()); + DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort()); pool.afterPropertiesSet(); LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool); factory2.afterPropertiesSet(); @@ -140,15 +135,14 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra // The dedicated connection should not be closed b/c it's part of a pool connection.multi(); - connection.close(); + connection.close(); factory2.destroy(); - pool.destroy(); + pool.destroy(); } @Test public void testClosePooledConnectionNotShared() { - DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), - SettingsUtils.getPort()); + DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort()); pool.afterPropertiesSet(); LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool); factory2.setShareNativeConnection(false); @@ -160,13 +154,13 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra // The dedicated connection should not be closed connection.ping(); - connection.close(); + connection.close(); factory2.destroy(); - pool.destroy(); + pool.destroy(); } @Test - public void testCloseNonPooledConnectionNotShared() { + public void testCloseNonPooledConnectionNotShared() { LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort()); factory2.setShareNativeConnection(false); factory2.afterPropertiesSet(); @@ -178,16 +172,14 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra try { connection.set("foo".getBytes(), "bar".getBytes()); fail("Exception should be thrown trying to use a closed connection"); - }catch(RedisSystemException e) { - } + } catch (RedisSystemException e) {} factory2.destroy(); } @SuppressWarnings("rawtypes") @Test public void testCloseReturnBrokenResourceToPool() { - DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), - SettingsUtils.getPort()); + DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort()); pool.afterPropertiesSet(); LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool); factory2.setShareNativeConnection(false); @@ -195,30 +187,28 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra RedisConnection connection = factory2.getConnection(); // Use the connection to make sure the channel is initialized, else nothing happens on close connection.ping(); - ((RedisAsyncConnection)connection.getNativeConnection()).close(); + ((RedisAsyncConnection) connection.getNativeConnection()).close(); try { connection.ping(); fail("Exception should be thrown trying to use a closed connection"); - }catch(RedisSystemException e) { - } + } catch (RedisSystemException e) {} connection.close(); factory2.destroy(); - pool.destroy(); + pool.destroy(); } @Test public void testSelectNotShared() { - DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), - SettingsUtils.getPort()); + DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort()); pool.afterPropertiesSet(); LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool); factory2.setShareNativeConnection(false); factory2.afterPropertiesSet(); RedisConnection connection = factory2.getConnection(); connection.select(2); - connection.close(); + connection.close(); factory2.destroy(); - pool.destroy(); + pool.destroy(); } @Test(expected = UnsupportedOperationException.class) @@ -226,7 +216,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra super.testSelect(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testSRandMemberCountNegative() { super.testSRandMemberCountNegative(); @@ -234,7 +224,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra @Test @IfProfileValue(name = "runLongTests", value = "true") - public void testScriptKill() throws Exception{ + public void testScriptKill() throws Exception { getResults(); assumeTrue(RedisVersionUtils.atLeast("2.6", byteConnection)); final AtomicBoolean scriptDead = new AtomicBoolean(false); @@ -244,15 +234,14 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort()); factory2.afterPropertiesSet(); - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - factory2.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection()); try { conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0); - }catch(DataAccessException e) { + } catch (DataAccessException e) { scriptDead.set(true); } conn2.close(); - factory2.destroy(); + factory2.destroy(); } }); th.start(); @@ -269,20 +258,20 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra public void testMove() { connection.set("foo", "bar"); actual.add(connection.move("foo", 1)); - verifyResults(Arrays.asList(new Object[] { true})); + verifyResults(Arrays.asList(new Object[] { true })); // Lettuce does not support select when using shared conn, use a new conn factory LettuceConnectionFactory factory2 = new LettuceConnectionFactory(); factory2.setDatabase(1); factory2.afterPropertiesSet(); StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection()); try { - assertEquals("bar",conn2.get("foo")); + assertEquals("bar", conn2.get("foo")); } finally { - if(conn2.exists("foo")) { + if (conn2.exists("foo")) { conn2.del("foo"); } conn2.close(); - factory2.destroy(); + factory2.destroy(); } } -} \ No newline at end of file +} 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 106f99cf4..0eddc1ae7 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 @@ -39,22 +39,20 @@ import static org.springframework.data.redis.SpinBarrier.waitFor; /** * Integration test of {@link LettuceConnection} pipeline functionality - * + * * @author Jennifer Hickey * @author Thomas Darimont - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("LettuceConnectionIntegrationTests-context.xml") -public class LettuceConnectionPipelineIntegrationTests extends - AbstractConnectionPipelineIntegrationTests { - - @Test(expected=UnsupportedOperationException.class) +public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests { + + @Test(expected = UnsupportedOperationException.class) public void testSelect() { super.testSelect(); } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testSRandMemberCountNegative() { super.testSRandMemberCountNegative(); @@ -62,7 +60,7 @@ public class LettuceConnectionPipelineIntegrationTests extends @Test @IfProfileValue(name = "runLongTests", value = "true") - public void testScriptKill() throws Exception{ + public void testScriptKill() throws Exception { getResults(); assumeTrue(RedisVersionUtils.atLeast("2.6", byteConnection)); initConnection(); @@ -73,15 +71,14 @@ public class LettuceConnectionPipelineIntegrationTests extends final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort()); factory2.afterPropertiesSet(); - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection( - factory2.getConnection()); + DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection()); try { conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0); - }catch(DataAccessException e) { + } catch (DataAccessException e) { scriptDead.set(true); } conn2.close(); - factory2.destroy(); + factory2.destroy(); } }); th.start(); @@ -99,20 +96,20 @@ public class LettuceConnectionPipelineIntegrationTests extends public void testMove() { connection.set("foo", "bar"); actual.add(connection.move("foo", 1)); - verifyResults(Arrays.asList(new Object[] { true})); + verifyResults(Arrays.asList(new Object[] { true })); // Lettuce does not support select when using shared conn, use a new conn factory LettuceConnectionFactory factory2 = new LettuceConnectionFactory(); factory2.setDatabase(1); factory2.afterPropertiesSet(); StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection()); try { - assertEquals("bar",conn2.get("foo")); + assertEquals("bar", conn2.get("foo")); } finally { - if(conn2.exists("foo")) { + if (conn2.exists("foo")) { conn2.del("foo"); } conn2.close(); - factory2.destroy(); + factory2.destroy(); } } } 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 53902ec78..8eb7b8672 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 @@ -11,12 +11,10 @@ import org.springframework.test.annotation.IfProfileValue; /** * Integration test of {@link LettuceConnection} transactions within a pipeline - * + * * @author Jennifer Hickey - * */ -public class LettuceConnectionPipelineTxIntegrationTests extends - LettuceConnectionTransactionIntegrationTests { +public class LettuceConnectionPipelineTxIntegrationTests extends LettuceConnectionTransactionIntegrationTests { @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") @@ -42,13 +40,13 @@ public class LettuceConnectionPipelineTxIntegrationTests extends super.testRestoreExistingKey(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalArrayScriptError() { super.testEvalArrayScriptError(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayError() { super.testEvalShaArrayError(); @@ -64,8 +62,8 @@ public class LettuceConnectionPipelineTxIntegrationTests extends assertNull(connection.exec()); List pipelined = connection.closePipeline(); // We expect only the results of exec to be in the closed pipeline - assertEquals(1,pipelined.size()); - List txResults = (List)pipelined.get(0); + assertEquals(1, pipelined.size()); + List txResults = (List) pipelined.get(0); // Return exec results and this test should behave exactly like its superclass return txResults; } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java index 18695ca43..d8842804d 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java @@ -30,22 +30,18 @@ import java.util.Arrays; import static org.junit.Assert.assertEquals; /** - * Integration test of {@link LettuceConnection} functionality within a - * transaction - * + * Integration test of {@link LettuceConnection} functionality within a transaction + * * @author Jennifer Hickey * @author Thomas Darimont - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("LettuceConnectionIntegrationTests-context.xml") -public class LettuceConnectionTransactionIntegrationTests extends - AbstractConnectionTransactionIntegrationTests { +public class LettuceConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests { @Test @Ignore("DATAREDIS-226 Exceptions on native execute are swallowed in tx") - public void exceptionExecuteNative() throws Exception { - } + public void exceptionExecuteNative() throws Exception {} @Test(expected = UnsupportedOperationException.class) @IfProfileValue(name = "redisVersion", value = "2.6") @@ -57,24 +53,24 @@ public class LettuceConnectionTransactionIntegrationTests extends public void testMove() { connection.set("foo", "bar"); actual.add(connection.move("foo", 1)); - verifyResults(Arrays.asList(new Object[] { true})); + verifyResults(Arrays.asList(new Object[] { true })); // Lettuce does not support select when using shared conn, use a new conn factory LettuceConnectionFactory factory2 = new LettuceConnectionFactory(); factory2.setDatabase(1); factory2.afterPropertiesSet(); StringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection()); try { - assertEquals("bar",conn2.get("foo")); + assertEquals("bar", conn2.get("foo")); } finally { - if(conn2.exists("foo")) { + if (conn2.exists("foo")) { conn2.del("foo"); } conn2.close(); - factory2.destroy(); + factory2.destroy(); } } - @Test(expected=UnsupportedOperationException.class) + @Test(expected = UnsupportedOperationException.class) public void testSelect() { super.testSelect(); } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionTests.java index f31b157d9..08e3f8615 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionTests.java @@ -35,9 +35,8 @@ import com.lambdaworks.redis.pubsub.RedisPubSubConnection; /** * Unit test of {@link LettuceSubscription} - * + * * @author Jennifer Hickey - * */ public class LettuceSubscriptionTests { diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java index 9c5837f7f..fc17d3b0e 100644 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionFactoryTests.java @@ -24,16 +24,14 @@ import static org.junit.Assert.fail; /** * Integration test of {@link SrpConnectionFactory} - * + * * @author Jennifer Hickey - * */ public class SrpConnectionFactoryTests { @Test public void testConnect() { - SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), - SettingsUtils.getPort()); + SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort()); factory.afterPropertiesSet(); RedisConnection connection = factory.getConnection(); connection.ping(); @@ -47,15 +45,13 @@ public class SrpConnectionFactoryTests { try { factory.getConnection(); fail("Expected a connection failure exception"); - } catch(RedisConnectionFailureException e) { - } + } catch (RedisConnectionFailureException e) {} } @Ignore("Redis must have requirepass set to run this test") @Test public void testConnectWithPassword() { - SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), - SettingsUtils.getPort()); + SrpConnectionFactory factory = new SrpConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort()); factory.setPassword("foob"); factory.afterPropertiesSet(); RedisConnection connection = factory.getConnection(); diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java index 59a193d04..497530ae7 100644 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java @@ -29,10 +29,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Integration test of {@link SrpConnection} - * + * * @author Costin Leau * @author Jennifer Hickey - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -74,6 +73,6 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration // SRP returns the Strings from individual StatusReplys in a MultiBulkReply, while other clients return as byte[] actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}", ReturnType.MULTI, 0)); - verifyResults(Arrays.asList(new Object[] {Arrays.asList(new Object[] {"OK", "OK"} )})); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) })); } } 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 d99c7f5e0..4ebba822b 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 @@ -28,27 +28,24 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Integration test of {@link SrpConnection} pipeline functionality - * + * * @author Jennifer Hickey - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("SrpConnectionIntegrationTests-context.xml") -public class SrpConnectionPipelineIntegrationTests extends - AbstractConnectionPipelineIntegrationTests { +public class SrpConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests { @Test @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnArrayOKs() { // SRP returns the Strings from individual StatusReplys in a // MultiBulkReply, while other clients return as byte[] - actual.add(connection.eval( - "return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}", + actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}", ReturnType.MULTI, 0)); verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) })); } - @Test(expected=RedisSystemException.class) + @Test(expected = RedisSystemException.class) public void testExecWithoutMulti() { connection.exec(); // SRP throws an Exception right away on exec instead of once pipeline is closed diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineTxIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineTxIntegrationTests.java index 02d30c801..514e150e9 100644 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineTxIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionPipelineTxIntegrationTests.java @@ -28,9 +28,8 @@ import org.springframework.test.annotation.IfProfileValue; /** * Integration test of {@link SrpConnection} transactions within a pipeline - * + * * @author Jennifer Hickey - * */ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransactionIntegrationTests { @@ -40,7 +39,7 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa assertNull(connection.exec()); assertNull(connection.get("foo")); List results = connection.closePipeline(); - assertEquals(Arrays.asList(new Object[] {Collections.emptyList(), "bar"}), results); + assertEquals(Arrays.asList(new Object[] { Collections.emptyList(), "bar" }), results); assertEquals("bar", connection.get("foo")); } @@ -55,17 +54,17 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa assertNull(connection.exec()); List results = connection.closePipeline(); assertEquals(2, results.size()); - assertEquals(Arrays.asList(new Object[] {"bar"}), results.get(0)); - assertEquals(Arrays.asList(new Object[] {"baz"}), results.get(1)); + assertEquals(Arrays.asList(new Object[] { "bar" }), results.get(0)); + assertEquals(Arrays.asList(new Object[] { "baz" }), results.get(1)); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaNotFound() { super.testEvalShaNotFound(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalReturnSingleError() { super.testEvalReturnSingleError(); @@ -83,13 +82,13 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa super.testRestoreBadData(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalArrayScriptError() { super.testEvalArrayScriptError(); } - @Test(expected=RedisPipelineException.class) + @Test(expected = RedisPipelineException.class) @IfProfileValue(name = "redisVersion", value = "2.6") public void testEvalShaArrayError() { super.testEvalShaArrayError(); @@ -105,8 +104,8 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa assertNull(connection.exec()); List pipelined = connection.closePipeline(); // We expect only the results of exec to be in the closed pipeline - assertEquals(1,pipelined.size()); - List txResults = (List)pipelined.get(0); + assertEquals(1, pipelined.size()); + List txResults = (List) pipelined.get(0); // Return exec results and this test should behave exactly like its superclass return txResults; } diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionTransactionIntegrationTests.java index d008f3cf1..d636c2261 100644 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionTransactionIntegrationTests.java @@ -25,13 +25,10 @@ import org.springframework.test.annotation.IfProfileValue; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - - /** * Integration test of {@link SrpConnection} functionality within a transaction - * + * * @author Jennifer Hickey - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("SrpConnectionIntegrationTests-context.xml") @@ -43,7 +40,7 @@ public class SrpConnectionTransactionIntegrationTests extends AbstractConnection // SRP returns the Strings from individual StatusReplys in a MultiBulkReply, while other clients return as byte[] actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}", ReturnType.MULTI, 0)); - verifyResults(Arrays.asList(new Object[] {Arrays.asList(new Object[] {"OK", "OK"} )})); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) })); } @Test diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpSubscriptionTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpSubscriptionTests.java index d49583994..0a03160a5 100644 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpSubscriptionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpSubscriptionTests.java @@ -36,9 +36,8 @@ import redis.client.ReplyListener; /** * Unit test of {@link SrpSubscription} - * + * * @author Jennifer Hickey - * */ public class SrpSubscriptionTests { diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpUtilsTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpUtilsTests.java index 501adf19e..bd8420d3c 100644 --- a/src/test/java/org/springframework/data/redis/connection/srp/SrpUtilsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpUtilsTests.java @@ -27,56 +27,47 @@ import static org.junit.Assert.assertEquals; /** * Unit test of {@link SrpUtils} - * + * * @author Jennifer Hickey - * @author Thomas Darimont - * - * Suppressed deprecation warnings since SrpUtils is deprecated. + * @author Thomas Darimont Suppressed deprecation warnings since SrpUtils is deprecated. */ @SuppressWarnings("deprecation") public class SrpUtilsTests { @Test public void testSortParamsWithAllParams() { - SortParameters sortParams = new DefaultSortParameters().alpha().asc() - .by("weight_*".getBytes()).get("object_*".getBytes()) - .limit(0, 5); + SortParameters sortParams = new DefaultSortParameters().alpha().asc().by("weight_*".getBytes()) + .get("object_*".getBytes()).limit(0, 5); Object[] sort = SrpUtils.sortParams(sortParams, "foo".getBytes()); - assertArrayEquals(new String[] { "BY", "weight_*", "LIMIT 0 5", "GET", - "object_*", "ASC", "ALPHA", "STORE", "foo" }, + assertArrayEquals( + new String[] { "BY", "weight_*", "LIMIT 0 5", "GET", "object_*", "ASC", "ALPHA", "STORE", "foo" }, convertByteArrays(sort)); } @Test public void testSortParamsOnlyBy() { - SortParameters sortParams = new DefaultSortParameters().numeric().by( - "weight_*".getBytes()); + SortParameters sortParams = new DefaultSortParameters().numeric().by("weight_*".getBytes()); Object[] sort = SrpUtils.sortParams(sortParams); - assertArrayEquals(new String[] { "BY", "weight_*" }, - convertByteArrays(sort)); + assertArrayEquals(new String[] { "BY", "weight_*" }, convertByteArrays(sort)); } @Test public void testSortParamsOnlyLimit() { - SortParameters sortParams = new DefaultSortParameters().numeric() - .limit(0, 5); + SortParameters sortParams = new DefaultSortParameters().numeric().limit(0, 5); Object[] sort = SrpUtils.sortParams(sortParams); assertArrayEquals(new String[] { "LIMIT 0 5" }, convertByteArrays(sort)); } @Test public void testSortParamsOnlyGetPatterns() { - SortParameters sortParams = new DefaultSortParameters().numeric() - .get("foo".getBytes()).get("bar".getBytes()); + SortParameters sortParams = new DefaultSortParameters().numeric().get("foo".getBytes()).get("bar".getBytes()); Object[] sort = SrpUtils.sortParams(sortParams); - assertArrayEquals(new String[] { "GET", "foo", "GET", "bar" }, - convertByteArrays(sort)); + assertArrayEquals(new String[] { "GET", "foo", "GET", "bar" }, convertByteArrays(sort)); } @Test public void testSortParamsOnlyOrder() { - SortParameters sortParams = new DefaultSortParameters().numeric() - .desc(); + SortParameters sortParams = new DefaultSortParameters().numeric().desc(); Object[] sort = SrpUtils.sortParams(sortParams); assertArrayEquals(new String[] { "DESC" }, convertByteArrays(sort)); } @@ -92,48 +83,41 @@ public class SrpUtilsTests { public void testSortParamsOnlyStore() { SortParameters sortParams = new DefaultSortParameters().numeric(); Object[] sort = SrpUtils.sortParams(sortParams, "storelist".getBytes()); - assertArrayEquals(new String[] { "STORE", "storelist" }, - convertByteArrays(sort)); + assertArrayEquals(new String[] { "STORE", "storelist" }, convertByteArrays(sort)); } @Test public void testSortWithAllParams() { - SortParameters sortParams = new DefaultSortParameters().alpha().asc() - .by("weight_*".getBytes()).get("object_*".getBytes()) - .limit(0, 5); + SortParameters sortParams = new DefaultSortParameters().alpha().asc().by("weight_*".getBytes()) + .get("object_*".getBytes()).limit(0, 5); byte[] sort = SrpUtils.sort(sortParams, "foo".getBytes()); - assertEquals("BY weight_* LIMIT 0 5 GET object_* ASC ALPHA STORE foo", - new String(sort)); + assertEquals("BY weight_* LIMIT 0 5 GET object_* ASC ALPHA STORE foo", new String(sort)); } @Test public void testSortOnlyBy() { - SortParameters sortParams = new DefaultSortParameters().numeric().by( - "weight_*".getBytes()); + SortParameters sortParams = new DefaultSortParameters().numeric().by("weight_*".getBytes()); byte[] sort = SrpUtils.sort(sortParams); assertEquals("BY weight_*", new String(sort)); } @Test public void testSortOnlyLimit() { - SortParameters sortParams = new DefaultSortParameters().numeric() - .limit(0, 5); + SortParameters sortParams = new DefaultSortParameters().numeric().limit(0, 5); byte[] sort = SrpUtils.sort(sortParams); assertEquals("LIMIT 0 5", new String(sort)); } @Test public void testSortOnlyGetPatterns() { - SortParameters sortParams = new DefaultSortParameters().numeric() - .get("foo".getBytes()).get("bar".getBytes()); + SortParameters sortParams = new DefaultSortParameters().numeric().get("foo".getBytes()).get("bar".getBytes()); byte[] sort = SrpUtils.sort(sortParams); assertEquals("GET foo GET bar", new String(sort)); } @Test public void testSortOnlyOrder() { - SortParameters sortParams = new DefaultSortParameters().numeric() - .desc(); + SortParameters sortParams = new DefaultSortParameters().numeric().desc(); byte[] sort = SrpUtils.sort(sortParams); assertEquals("DESC", new String(sort)); } diff --git a/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java index 6b7192bb3..8cf95d743 100644 --- a/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java +++ b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java @@ -46,7 +46,7 @@ abstract public class AbstractOperationsTestParams { * @see DATAREDIS-241 */ public static Collection testParams() { - + ObjectFactory stringFactory = new StringObjectFactory(); ObjectFactory longFactory = new LongObjectFactory(); ObjectFactory doubleFactory = new DoubleObjectFactory(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java index 50b8dbdeb..e1d4b8fff 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java @@ -39,16 +39,15 @@ import org.springframework.data.redis.connection.srp.SrpConnectionFactory; /** * Integration test of {@link DefaultHashOperations} - * + * * @author Jennifer Hickey - * * @param Key type * @param Hash key type * @param Hash value type */ @RunWith(Parameterized.class) -public class DefaultHashOperationsTests { - private RedisTemplate redisTemplate; +public class DefaultHashOperationsTests { + private RedisTemplate redisTemplate; private ObjectFactory keyFactory; @@ -56,9 +55,9 @@ public class DefaultHashOperationsTests { private ObjectFactory hashValueFactory; - private HashOperations hashOps; + private HashOperations hashOps; - public DefaultHashOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultHashOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory hashKeyFactory, ObjectFactory hashValueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; @@ -76,17 +75,17 @@ public class DefaultHashOperationsTests { srConnFactory.setHostName(SettingsUtils.getHost()); srConnFactory.afterPropertiesSet(); - RedisTemplate stringTemplate = new StringRedisTemplate(); + RedisTemplate stringTemplate = new StringRedisTemplate(); stringTemplate.setConnectionFactory(srConnFactory); stringTemplate.afterPropertiesSet(); - RedisTemplate rawTemplate = new RedisTemplate(); + RedisTemplate rawTemplate = new RedisTemplate(); rawTemplate.setConnectionFactory(srConnFactory); rawTemplate.setEnableDefaultSerializer(false); rawTemplate.afterPropertiesSet(); return Arrays.asList(new Object[][] { { stringTemplate, stringFactory, stringFactory, stringFactory }, - { rawTemplate, rawFactory, rawFactory, rawFactory }}); + { rawTemplate, rawFactory, rawFactory, rawFactory } }); } @Before @@ -113,7 +112,7 @@ public class DefaultHashOperationsTests { HV val2 = hashValueFactory.instance(); hashOps.put(key, key1, val1); hashOps.put(key, key2, val2); - Map expected = new LinkedHashMap(); + Map expected = new LinkedHashMap(); expected.put(key1, val1); expected.put(key2, val2); assertThat(hashOps.entries(key), isEqual(expected)); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java index 0d55da8c5..e2a69c867 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java @@ -37,23 +37,23 @@ import org.springframework.data.redis.connection.RedisConnection; /** * Integration test of {@link DefaultListOperations} + * * @author Jennifer Hickey - * * @param Key test * @param Value test */ @RunWith(Parameterized.class) -public class DefaultListOperationsTests { +public class DefaultListOperationsTests { - private RedisTemplate redisTemplate; + private RedisTemplate redisTemplate; private ObjectFactory keyFactory; private ObjectFactory valueFactory; - private ListOperations listOps; + private ListOperations listOps; - public DefaultListOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultListOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; @@ -89,10 +89,10 @@ public class DefaultListOperationsTests { System.out.println("Value1" + v1); System.out.println("Value2" + v2); System.out.println("Value3" + v3); - assertEquals(Long.valueOf(1),listOps.leftPush(key, v1)); - assertEquals(Long.valueOf(2),listOps.leftPush(key, v2)); + assertEquals(Long.valueOf(1), listOps.leftPush(key, v1)); + assertEquals(Long.valueOf(2), listOps.leftPush(key, v2)); assertEquals(Long.valueOf(3), listOps.leftPush(key, v1, v3)); - assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] {v2, v3, v1}))); + assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v2, v3, v1 }))); } @Test @@ -101,9 +101,9 @@ public class DefaultListOperationsTests { V v1 = valueFactory.instance(); V v2 = valueFactory.instance(); assertEquals(Long.valueOf(0), listOps.leftPushIfPresent(key, v1)); - assertEquals(Long.valueOf(1),listOps.leftPush(key, v1)); - assertEquals(Long.valueOf(2),listOps.leftPushIfPresent(key, v2)); - assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] {v2, v1}))); + assertEquals(Long.valueOf(1), listOps.leftPush(key, v1)); + assertEquals(Long.valueOf(2), listOps.leftPushIfPresent(key, v2)); + assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v2, v1 }))); } @SuppressWarnings("unchecked") @@ -113,9 +113,9 @@ public class DefaultListOperationsTests { V v1 = valueFactory.instance(); V v2 = valueFactory.instance(); V v3 = valueFactory.instance(); - assertEquals(Long.valueOf(2),listOps.leftPushAll(key, v1, v2)); + assertEquals(Long.valueOf(2), listOps.leftPushAll(key, v1, v2)); assertEquals(Long.valueOf(3), listOps.leftPush(key, v3)); - assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] {v3, v2, v1}))); + assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v3, v2, v1 }))); } @Test @@ -146,11 +146,10 @@ public class DefaultListOperationsTests { V v1 = valueFactory.instance(); V v2 = valueFactory.instance(); V v3 = valueFactory.instance(); - assertEquals(Long.valueOf(1),listOps.rightPush(key, v1)); - assertEquals(Long.valueOf(2),listOps.rightPush(key, v2)); + assertEquals(Long.valueOf(1), listOps.rightPush(key, v1)); + assertEquals(Long.valueOf(2), listOps.rightPush(key, v2)); assertEquals(Long.valueOf(3), listOps.rightPush(key, v1, v3)); - assertThat(listOps.range(key, 0, -1), - isEqual(Arrays.asList(new Object[] {v1, v3, v2}))); + assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v3, v2 }))); } @Test @@ -159,10 +158,9 @@ public class DefaultListOperationsTests { V v1 = valueFactory.instance(); V v2 = valueFactory.instance(); assertEquals(Long.valueOf(0), listOps.rightPushIfPresent(key, v1)); - assertEquals(Long.valueOf(1),listOps.rightPush(key, v1)); - assertEquals(Long.valueOf(2),listOps.rightPushIfPresent(key, v2)); - assertThat(listOps.range(key, 0, -1), - isEqual(Arrays.asList(new Object[] {v1, v2}))); + assertEquals(Long.valueOf(1), listOps.rightPush(key, v1)); + assertEquals(Long.valueOf(2), listOps.rightPushIfPresent(key, v2)); + assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v2 }))); } @SuppressWarnings("unchecked") @@ -172,9 +170,8 @@ public class DefaultListOperationsTests { V v1 = valueFactory.instance(); V v2 = valueFactory.instance(); V v3 = valueFactory.instance(); - assertEquals(Long.valueOf(2),listOps.rightPushAll(key, v1, v2)); - assertEquals(Long.valueOf(3),listOps.rightPush(key, v3)); - assertThat(listOps.range(key, 0, -1), - isEqual(Arrays.asList(new Object[] {v1, v2, v3}))); + assertEquals(Long.valueOf(2), listOps.rightPushAll(key, v1, v2)); + assertEquals(Long.valueOf(3), listOps.rightPush(key, v3)); + assertThat(listOps.range(key, 0, -1), isEqual(Arrays.asList(new Object[] { v1, v2, v3 }))); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java index 56a2c2218..6b44edfd7 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java @@ -45,20 +45,19 @@ import org.springframework.data.redis.connection.RedisConnection; * Integration test of {@link DefaultSetOperations} * * @author Jennifer Hickey - * */ @RunWith(Parameterized.class) -public class DefaultSetOperationsTests { - - private RedisTemplate redisTemplate; +public class DefaultSetOperationsTests { + + private RedisTemplate redisTemplate; private ObjectFactory keyFactory; private ObjectFactory valueFactory; - private SetOperations setOps; + private SetOperations setOps; - public DefaultSetOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultSetOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; @@ -69,7 +68,7 @@ public class DefaultSetOperationsTests { public static Collection testParams() { return AbstractOperationsTestParams.testParams(); } - + @Before public void setUp() { setOps = redisTemplate.opsForSet(); @@ -84,7 +83,7 @@ public class DefaultSetOperationsTests { } }); } - + @SuppressWarnings("unchecked") @Test public void testDistinctRandomMembers() { @@ -102,7 +101,7 @@ public class DefaultSetOperationsTests { expected.add(v1); expected.add(v2); expected.add(v3); - assertThat(expected, hasItems((V[])members.toArray())); + assertThat(expected, hasItems((V[]) members.toArray())); } @SuppressWarnings("unchecked") @@ -115,7 +114,7 @@ public class DefaultSetOperationsTests { setOps.add(setKey, v1); setOps.add(setKey, v2); List members = setOps.randomMembers(setKey, 2); - assertEquals(2,members.size()); + assertEquals(2, members.size()); assertThat(members, either(hasItem(v1)).or(hasItem(v2))); } @@ -125,8 +124,7 @@ public class DefaultSetOperationsTests { try { setOps.randomMembers(keyFactory.instance(), -1); fail("IllegalArgumentException should be thrown"); - }catch(IllegalArgumentException e) { - } + } catch (IllegalArgumentException e) {} } @Test @@ -135,8 +133,7 @@ public class DefaultSetOperationsTests { try { setOps.distinctRandomMembers(keyFactory.instance(), -2); fail("IllegalArgumentException should be thrown"); - }catch(IllegalArgumentException e) { - } + } catch (IllegalArgumentException e) {} } @SuppressWarnings("unchecked") @@ -149,10 +146,8 @@ public class DefaultSetOperationsTests { setOps.add(key1, v1); setOps.add(key1, v2); setOps.move(key1, v1, key2); - assertThat(setOps.members(key1), - isEqual(new HashSet(Collections.singletonList(v2)))); - assertThat(setOps.members(key2), - isEqual(new HashSet(Collections.singletonList(v1)))); + assertThat(setOps.members(key1), isEqual(new HashSet(Collections.singletonList(v2)))); + assertThat(setOps.members(key2), isEqual(new HashSet(Collections.singletonList(v1)))); } @SuppressWarnings("unchecked") @@ -195,7 +190,7 @@ public class DefaultSetOperationsTests { V v2 = valueFactory.instance(); V v3 = valueFactory.instance(); V v4 = valueFactory.instance(); - setOps.add(key,v1, v2, v3); + setOps.add(key, v1, v2, v3); assertEquals(Long.valueOf(2), setOps.remove(key, v1, v2, v4)); assertThat(setOps.members(key), isEqual(Collections.singleton(v3))); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java index e4edc087c..ce25f621a 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java @@ -44,12 +44,11 @@ import org.springframework.data.redis.connection.RedisConnection; * Integration test of {@link DefaultValueOperations} * * @author Jennifer Hickey - * */ @RunWith(Parameterized.class) -public class DefaultValueOperationsTests { +public class DefaultValueOperationsTests { - private RedisTemplate redisTemplate; + private RedisTemplate redisTemplate; private ObjectFactory keyFactory; @@ -57,7 +56,7 @@ public class DefaultValueOperationsTests { private ValueOperations valueOps; - public DefaultValueOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultValueOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; @@ -90,13 +89,12 @@ public class DefaultValueOperationsTests { V v1 = valueFactory.instance(); assumeTrue(v1 instanceof Long); valueOps.set(key, v1); - assertEquals(Long.valueOf((Long)v1 - 10), valueOps.increment(key, -10)); - assertEquals(Long.valueOf((Long)v1 - 10), (Long)valueOps.get(key)); + assertEquals(Long.valueOf((Long) v1 - 10), valueOps.increment(key, -10)); + assertEquals(Long.valueOf((Long) v1 - 10), (Long) valueOps.get(key)); valueOps.increment(key, -10); - assertEquals(Long.valueOf((Long)v1 - 20), (Long)valueOps.get(key)); + assertEquals(Long.valueOf((Long) v1 - 20), (Long) valueOps.get(key)); } - /** * @see DATAREDIS-247 */ @@ -110,15 +108,15 @@ public class DefaultValueOperationsTests { valueOps.set(key, v1); DecimalFormat twoDForm = (DecimalFormat) DecimalFormat.getInstance(Locale.US); - assertEquals(Double.valueOf(twoDForm.format((Double)v1 + 1.4)), valueOps.increment(key, 1.4)); - assertEquals(Double.valueOf(twoDForm.format((Double)v1 + 1.4)), valueOps.get(key)); + assertEquals(Double.valueOf(twoDForm.format((Double) v1 + 1.4)), valueOps.increment(key, 1.4)); + assertEquals(Double.valueOf(twoDForm.format((Double) v1 + 1.4)), valueOps.get(key)); valueOps.increment(key, -10d); - assertEquals(Double.valueOf(twoDForm.format((Double)v1 + 1.4 - 10d)), valueOps.get(key)); + assertEquals(Double.valueOf(twoDForm.format((Double) v1 + 1.4 - 10d)), valueOps.get(key)); } @Test public void testMultiSetIfAbsent() { - Map keysAndValues = new HashMap(); + Map keysAndValues = new HashMap(); K key1 = keyFactory.instance(); K key2 = keyFactory.instance(); V value1 = valueFactory.instance(); @@ -126,8 +124,7 @@ public class DefaultValueOperationsTests { keysAndValues.put(key1, value1); keysAndValues.put(key2, value2); assertTrue(valueOps.multiSetIfAbsent(keysAndValues)); - assertThat(valueOps.multiGet(keysAndValues.keySet()), - isEqual(new ArrayList(keysAndValues.values()))); + assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList(keysAndValues.values()))); } @Test @@ -138,7 +135,7 @@ public class DefaultValueOperationsTests { V value2 = valueFactory.instance(); V value3 = valueFactory.instance(); valueOps.set(key1, value1); - Map keysAndValues = new HashMap(); + Map keysAndValues = new HashMap(); keysAndValues.put(key1, value2); keysAndValues.put(key2, value3); assertFalse(valueOps.multiSetIfAbsent(keysAndValues)); @@ -146,7 +143,7 @@ public class DefaultValueOperationsTests { @Test public void testMultiSet() { - Map keysAndValues = new HashMap(); + Map keysAndValues = new HashMap(); K key1 = keyFactory.instance(); K key2 = keyFactory.instance(); V value1 = valueFactory.instance(); @@ -154,15 +151,14 @@ public class DefaultValueOperationsTests { keysAndValues.put(key1, value1); keysAndValues.put(key2, value2); valueOps.multiSet(keysAndValues); - assertThat(valueOps.multiGet(keysAndValues.keySet()), - isEqual(new ArrayList(keysAndValues.values()))); + assertThat(valueOps.multiGet(keysAndValues.keySet()), isEqual(new ArrayList(keysAndValues.values()))); } @Test public void testGetSet() { K key1 = keyFactory.instance(); V value1 = valueFactory.instance(); - valueOps.set(key1,value1); + valueOps.set(key1, value1); assertThat(valueOps.get(key1), isEqual(value1)); } @@ -195,8 +191,8 @@ public class DefaultValueOperationsTests { V value1 = valueFactory.instance(); assumeTrue(redisTemplate instanceof StringRedisTemplate); valueOps.set(key1, value1); - assertEquals(Integer.valueOf(((String)value1).length() + 3), valueOps.append(key1, "aaa")); - assertEquals((String)value1 + "aaa",valueOps.get(key1)); + assertEquals(Integer.valueOf(((String) value1).length() + 3), valueOps.append(key1, "aaa")); + assertEquals((String) value1 + "aaa", valueOps.get(key1)); } @Test @@ -205,7 +201,7 @@ public class DefaultValueOperationsTests { V value1 = valueFactory.instance(); assumeTrue(value1 instanceof String); valueOps.set(key1, value1); - assertEquals(2,valueOps.get(key1, 0, 1).length()); + assertEquals(2, valueOps.get(key1, 0, 1).length()); } @Test @@ -241,7 +237,7 @@ public class DefaultValueOperationsTests { public void testRawKeys() { K key1 = keyFactory.instance(); K key2 = keyFactory.instance(); - byte[][] rawKeys = ((DefaultValueOperations)valueOps).rawKeys(key1, key2); + byte[][] rawKeys = ((DefaultValueOperations) valueOps).rawKeys(key1, key2); assertEquals(2, rawKeys.length); } @@ -250,7 +246,7 @@ public class DefaultValueOperationsTests { public void testRawKeysCollection() { K key1 = keyFactory.instance(); K key2 = keyFactory.instance(); - byte[][] rawKeys = ((DefaultValueOperations)valueOps).rawKeys(Arrays.asList(new Object[] {key1, key2})); + byte[][] rawKeys = ((DefaultValueOperations) valueOps).rawKeys(Arrays.asList(new Object[] { key1, key2 })); assertEquals(2, rawKeys.length); } @@ -259,6 +255,6 @@ public class DefaultValueOperationsTests { public void testDeserializeKey() { K key1 = keyFactory.instance(); assumeTrue(key1 instanceof byte[]); - assertNotNull(((DefaultValueOperations)valueOps).deserializeKey((byte[])key1)); + assertNotNull(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key1)); } } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java index aa0e16c51..bf83a4eb0 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java @@ -37,15 +37,15 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple; /** * Integration test of {@link DefaultZSetOperations} + * * @author Jennifer Hickey - * * @param Key type * @param Value type */ @RunWith(Parameterized.class) -public class DefaultZSetOperationsTests { +public class DefaultZSetOperationsTests { - private RedisTemplate redisTemplate; + private RedisTemplate redisTemplate; private ObjectFactory keyFactory; @@ -53,7 +53,7 @@ public class DefaultZSetOperationsTests { private ZSetOperations zSetOps; - public DefaultZSetOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultZSetOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; @@ -97,7 +97,7 @@ public class DefaultZSetOperationsTests { zSetOps.add(key1, value1, 2.5); assertEquals(Double.valueOf(5.7), zSetOps.incrementScore(key1, value1, 3.2)); Set> values = zSetOps.rangeWithScores(key1, 0, -1); - assertEquals(1,values.size()); + assertEquals(1, values.size()); TypedTuple tuple = values.iterator().next(); assertEquals(new DefaultTypedTuple(value1, 5.7), tuple); } @@ -112,8 +112,7 @@ public class DefaultZSetOperationsTests { zSetOps.add(key, value1, 1.9); zSetOps.add(key, value2, 3.7); zSetOps.add(key, value3, 5.8); - assertThat(zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1), - isEqual(Collections.singleton(value1))); + assertThat(zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1), isEqual(Collections.singleton(value1))); } @Test @@ -140,8 +139,7 @@ public class DefaultZSetOperationsTests { zSetOps.add(key, value1, 1.9); zSetOps.add(key, value2, 3.7); zSetOps.add(key, value3, 5.8); - assertThat(zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1), - isEqual(Collections.singleton(value2))); + assertThat(zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1), isEqual(Collections.singleton(value2))); } @Test diff --git a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java b/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java index 59460670e..57f4e8b73 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java @@ -64,18 +64,15 @@ import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; /** - * * Integration test of {@link RedisTemplate} - * + * * @author Jennifer Hickey - * */ @RunWith(Parameterized.class) -public class RedisTemplateTests { +public class RedisTemplateTests { + + @Autowired private RedisTemplate redisTemplate; - @Autowired - private RedisTemplate redisTemplate; - private ObjectFactory keyFactory; private ObjectFactory valueFactory; @@ -140,7 +137,7 @@ public class RedisTemplateTests { V value1 = valueFactory.instance(); assumeTrue(key1 instanceof String || key1 instanceof byte[]); redisTemplate.opsForValue().set(key1, value1); - K keyPattern = key1 instanceof String ? (K) "*" : (K)"*".getBytes(); + K keyPattern = key1 instanceof String ? (K) "*" : (K) "*".getBytes(); assertNotNull(redisTemplate.keys(keyPattern)); } @@ -162,7 +159,7 @@ public class RedisTemplateTests { return stringConn.get("test"); } }); - assertEquals(value,"it"); + assertEquals(value, "it"); } @Test @@ -192,9 +189,9 @@ public class RedisTemplateTests { }); List list = Collections.singletonList(listValue); Set set = new HashSet(Collections.singletonList(setValue)); - Set> tupleSet = new LinkedHashSet>( - Collections.singletonList(new DefaultTypedTuple(zsetValue, 1d))); - assertThat(results, isEqual(Arrays.asList(new Object[] {value1, 1l, list, 1l, set, true, tupleSet}))); + Set> tupleSet = new LinkedHashSet>(Collections.singletonList(new DefaultTypedTuple( + zsetValue, 1d))); + assertThat(results, isEqual(Arrays.asList(new Object[] { value1, 1l, list, 1l, set, true, tupleSet }))); } @Test @@ -242,10 +239,10 @@ public class RedisTemplateTests { Set> tupleSet = new LinkedHashSet>( Collections.singletonList(new DefaultTypedTuple(9l, 1d))); Set zSet = new LinkedHashSet(Collections.singletonList(9l)); - Map map = new LinkedHashMap(); + Map map = new LinkedHashMap(); map.put(10l, 11l); assertThat(results, - isEqual(Arrays.asList(new Object[] {5l, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map}))); + isEqual(Arrays.asList(new Object[] { 5l, 1l, list, 1l, longSet, true, tupleSet, zSet, true, map }))); } @Test @@ -259,13 +256,13 @@ public class RedisTemplateTests { @SuppressWarnings({ "rawtypes", "unchecked" }) public List execute(RedisOperations operations) throws DataAccessException { operations.multi(); - operations.opsForValue().set("foo","bar"); + operations.opsForValue().set("foo", "bar"); operations.opsForValue().get("foo"); return operations.exec(); } }); // first value is "OK" from set call, results should still be in byte[] - assertEquals("bar", new String((byte[])results.get(1))); + assertEquals("bar", new String((byte[]) results.get(1))); } @SuppressWarnings("rawtypes") @@ -289,7 +286,7 @@ public class RedisTemplateTests { } }); assertThat(results, - isEqual(Arrays.asList(new Object[] {value1, 1l, 2l, Arrays.asList(new Object[] {listValue, listValue2})}))); + isEqual(Arrays.asList(new Object[] { value1, 1l, 2l, Arrays.asList(new Object[] { listValue, listValue2 }) }))); } @SuppressWarnings("rawtypes") @@ -307,10 +304,10 @@ public class RedisTemplateTests { return null; } }, new GenericToStringSerializer(Long.class)); - assertEquals(Arrays.asList(new Object[] {5l, 1l, 2l, Arrays.asList(new Long[] {10l, 11l})}), results); + assertEquals(Arrays.asList(new Object[] { 5l, 1l, 2l, Arrays.asList(new Long[] { 10l, 11l }) }), results); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) public void testExecutePipelinedNonNullRedisCallback() { redisTemplate.executePipelined(new RedisCallback() { public String doInRedis(RedisConnection connection) throws DataAccessException { @@ -319,7 +316,7 @@ public class RedisTemplateTests { }); } - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testExecutePipelinedTx() { final K key1 = keyFactory.instance(); @@ -337,10 +334,11 @@ public class RedisTemplateTests { } }); // Should contain the List of deserialized exec results and the result of the last call to get() - assertThat(pipelinedResults, isEqual(Arrays.asList(new Object[] {Arrays.asList(new Object[] {1l, value1, 0l}), value1}))); + assertThat(pipelinedResults, + isEqual(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, value1, 0l }), value1 }))); } - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testExecutePipelinedTxCustomSerializer() { assumeTrue(redisTemplate instanceof StringRedisTemplate); @@ -355,12 +353,12 @@ public class RedisTemplateTests { operations.opsForValue().get("foo"); return null; } - },new GenericToStringSerializer(Long.class)); + }, new GenericToStringSerializer(Long.class)); // Should contain the List of deserialized exec results and the result of the last call to get() - assertEquals(Arrays.asList(new Object[] {Arrays.asList(new Object[] {1l, 5l, 0l}), 2l}), pipelinedResults); + assertEquals(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, 5l, 0l }), 2l }), pipelinedResults); } - @Test(expected=InvalidDataAccessApiUsageException.class) + @Test(expected = InvalidDataAccessApiUsageException.class) public void testExecutePipelinedNonNullSessionCallback() { redisTemplate.executePipelined(new SessionCallback() { @SuppressWarnings("rawtypes") @@ -423,12 +421,13 @@ public class RedisTemplateTests { V value1 = valueFactory.instance(); assumeTrue(value1 instanceof Number); redisTemplate.opsForList().rightPush(key1, value1); - List results = redisTemplate.sort(SortQueryBuilder.sort(key1).get("#").build(), new BulkMapper() { - public String mapBulk(List tuple) { - return "FOO"; - } - }); - assertEquals(Collections.singletonList("FOO"),results); + List results = redisTemplate.sort(SortQueryBuilder.sort(key1).get("#").build(), + new BulkMapper() { + public String mapBulk(List tuple) { + return "FOO"; + } + }); + assertEquals(Collections.singletonList("FOO"), results); } @Test @@ -458,14 +457,14 @@ public class RedisTemplateTests { factory.setPort(SettingsUtils.getPort()); factory.afterPropertiesSet(); final StringRedisTemplate template2 = new StringRedisTemplate(factory); - template2.boundValueOps((String)key1).set((String)value1); - template2.expire((String)key1, 10, TimeUnit.MILLISECONDS); + template2.boundValueOps((String) key1).set((String) value1); + template2.expire((String) key1, 10, TimeUnit.MILLISECONDS); Thread.sleep(15); // 10 millis should get rounded up to 1 sec if pExpire not supported - assertTrue(template2.hasKey((String)key1)); + assertTrue(template2.hasKey((String) key1)); waitFor(new TestCondition() { public boolean passes() { - return (!template2.hasKey((String)key1)); + return (!template2.hasKey((String) key1)); } }, 1000l); } @@ -501,9 +500,9 @@ public class RedisTemplateTests { factory.setPort(SettingsUtils.getPort()); factory.afterPropertiesSet(); final StringRedisTemplate template2 = new StringRedisTemplate(factory); - template2.boundValueOps((String)key1).set((String)value1); - template2.expire((String)key1, 5, TimeUnit.SECONDS); - long expire = template2.getExpire((String)key1, TimeUnit.MILLISECONDS); + template2.boundValueOps((String) key1).set((String) value1); + template2.expire((String) key1, 5, TimeUnit.SECONDS); + long expire = template2.getExpire((String) key1, TimeUnit.MILLISECONDS); // we should still get expire in milliseconds if requested assertTrue(expire > 1000 && expire <= 5000); } @@ -533,12 +532,12 @@ public class RedisTemplateTests { factory.setPort(SettingsUtils.getPort()); factory.afterPropertiesSet(); final StringRedisTemplate template2 = new StringRedisTemplate(factory); - template2.boundValueOps((String)key1).set((String)value1); - template2.expireAt((String)key1, new Date(System.currentTimeMillis() + 5l)); + template2.boundValueOps((String) key1).set((String) value1); + template2.expireAt((String) key1, new Date(System.currentTimeMillis() + 5l)); // Just ensure this works as expected, pExpireAt just adds some precision over expireAt waitFor(new TestCondition() { public boolean passes() { - return (!template2.hasKey((String)key1)); + return (!template2.hasKey((String) key1)); } }, 5l); } @@ -589,7 +588,7 @@ public class RedisTemplateTests { K key1 = keyFactory.instance(); V value1 = valueFactory.instance(); redisTemplate.opsForValue().set(key1, value1); - assertEquals(DataType.STRING,redisTemplate.type(key1)); + assertEquals(DataType.STRING, redisTemplate.type(key1)); } @Test @@ -611,8 +610,7 @@ public class RedisTemplateTests { th.start(); try { th.join(); - } catch (InterruptedException e) { - } + } catch (InterruptedException e) {} operations.multi(); operations.opsForValue().set(key1, value3); return operations.exec(); @@ -641,8 +639,7 @@ public class RedisTemplateTests { th.start(); try { th.join(); - } catch (InterruptedException e) { - } + } catch (InterruptedException e) {} operations.unwatch(); operations.multi(); operations.opsForValue().set(key1, value3); @@ -676,8 +673,7 @@ public class RedisTemplateTests { th.start(); try { th.join(); - } catch (InterruptedException e) { - } + } catch (InterruptedException e) {} operations.multi(); operations.opsForValue().set(key1, value3); return operations.exec(); @@ -698,17 +694,19 @@ public class RedisTemplateTests { public void testExecuteScriptCustomSerializers() { assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6")); K key1 = keyFactory.instance(); - final DefaultRedisScript script = new DefaultRedisScript(); + final DefaultRedisScript script = new DefaultRedisScript(); script.setScriptText("return 'Hey'"); script.setResultType(String.class); - assertEquals("Hey", redisTemplate.execute(script, redisTemplate.getValueSerializer(), new StringRedisSerializer(), - Collections.singletonList(key1))); + assertEquals( + "Hey", + redisTemplate.execute(script, redisTemplate.getValueSerializer(), new StringRedisSerializer(), + Collections.singletonList(key1))); } @SuppressWarnings({ "unchecked", "rawtypes" }) private byte[] serialize(Object value, RedisSerializer serializer) { - if(serializer == null && value instanceof byte[]) { - return (byte[])value; + if (serializer == null && value instanceof byte[]) { + return (byte[]) value; } return serializer.serialize(value); } diff --git a/src/test/java/org/springframework/data/redis/core/SessionTest.java b/src/test/java/org/springframework/data/redis/core/SessionTest.java index 76cae91b4..0e699480f 100644 --- a/src/test/java/org/springframework/data/redis/core/SessionTest.java +++ b/src/test/java/org/springframework/data/redis/core/SessionTest.java @@ -63,4 +63,4 @@ public class SessionTest { } }, true); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/core/SortTest.java b/src/test/java/org/springframework/data/redis/core/SortTest.java index 2ba16d1c6..30372d1c8 100644 --- a/src/test/java/org/springframework/data/redis/core/SortTest.java +++ b/src/test/java/org/springframework/data/redis/core/SortTest.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.core; - import org.junit.After; import org.junit.Before; import org.springframework.data.redis.core.query.SortQueryBuilder; @@ -23,12 +22,10 @@ import org.springframework.data.redis.core.query.SortQueryBuilder; public class SortTest { @Before - public void setUp() throws Exception { - } + public void setUp() throws Exception {} @After - public void tearDown() throws Exception { - } + public void tearDown() throws Exception {} public void testBasicDSL() throws Exception { SortQueryBuilder.sort("list").build(); diff --git a/src/test/java/org/springframework/data/redis/core/TimeoutUtilsTests.java b/src/test/java/org/springframework/data/redis/core/TimeoutUtilsTests.java index b76c76fe6..626549dbf 100644 --- a/src/test/java/org/springframework/data/redis/core/TimeoutUtilsTests.java +++ b/src/test/java/org/springframework/data/redis/core/TimeoutUtilsTests.java @@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals; * Unit test of {@link TimeoutUtils} * * @author Jennifer Hickey - * */ public class TimeoutUtilsTests { @@ -43,21 +42,21 @@ public class TimeoutUtilsTests { public void testConvertZeroSeconds() { assertEquals(0, TimeoutUtils.toSeconds(0, TimeUnit.MINUTES)); } - + @Test public void testConvertNegativeSecondsGreaterThanNegativeOne() { // Ensure we convert this to 0 as before, though ideally we wouldn't accept negative values - assertEquals(0,TimeoutUtils.toSeconds(-123, TimeUnit.MILLISECONDS)); + assertEquals(0, TimeoutUtils.toSeconds(-123, TimeUnit.MILLISECONDS)); } - + @Test public void testConvertNegativeSecondsEqualNegativeOne() { - assertEquals(-1,TimeoutUtils.toSeconds(-1111, TimeUnit.MILLISECONDS)); + assertEquals(-1, TimeoutUtils.toSeconds(-1111, TimeUnit.MILLISECONDS)); } - + @Test public void testConvertNegativeSecondsLessThanNegativeOne() { - assertEquals(-2,TimeoutUtils.toSeconds(-2344, TimeUnit.MILLISECONDS)); + assertEquals(-2, TimeoutUtils.toSeconds(-2344, TimeUnit.MILLISECONDS)); } @Test @@ -78,16 +77,16 @@ public class TimeoutUtilsTests { @Test public void testConvertNegativeMillisGreaterThanNegativeOne() { // Ensure we convert this to 0 as before, though ideally we wouldn't accept negative values - assertEquals(0,TimeoutUtils.toMillis(-123, TimeUnit.MICROSECONDS)); + assertEquals(0, TimeoutUtils.toMillis(-123, TimeUnit.MICROSECONDS)); } @Test public void testConvertNegativeMillisEqualNegativeOne() { - assertEquals(-1,TimeoutUtils.toMillis(-1111, TimeUnit.MICROSECONDS)); + assertEquals(-1, TimeoutUtils.toMillis(-1111, TimeUnit.MICROSECONDS)); } @Test public void testConvertNegativeMillisLessThanNegativeOne() { - assertEquals(-2,TimeoutUtils.toMillis(-2344, TimeUnit.MICROSECONDS)); + assertEquals(-2, TimeoutUtils.toMillis(-2344, TimeUnit.MICROSECONDS)); } } diff --git a/src/test/java/org/springframework/data/redis/core/script/DefaultRedisScriptTests.java b/src/test/java/org/springframework/data/redis/core/script/DefaultRedisScriptTests.java index 79cb43128..e40dc9c8d 100644 --- a/src/test/java/org/springframework/data/redis/core/script/DefaultRedisScriptTests.java +++ b/src/test/java/org/springframework/data/redis/core/script/DefaultRedisScriptTests.java @@ -25,9 +25,8 @@ import org.springframework.scripting.support.StaticScriptSource; /** * Test of {@link DefaultRedisScript} - * + * * @author Jennifer Hickey - * */ public class DefaultRedisScriptTests { diff --git a/src/test/java/org/springframework/data/redis/core/script/DefaultScriptExecutorTests.java b/src/test/java/org/springframework/data/redis/core/script/DefaultScriptExecutorTests.java index a857d0db7..7ee76c8c7 100644 --- a/src/test/java/org/springframework/data/redis/core/script/DefaultScriptExecutorTests.java +++ b/src/test/java/org/springframework/data/redis/core/script/DefaultScriptExecutorTests.java @@ -52,7 +52,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * Integration test of {@link DefaultScriptExecutor} * * @author Jennifer Hickey - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -60,11 +59,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @IfProfileValue(name = "redisVersion", value = "2.6") public class DefaultScriptExecutorTests { - @Autowired - private RedisConnectionFactory connFactory; + @Autowired private RedisConnectionFactory connFactory; - @SuppressWarnings("rawtypes") - private RedisTemplate template; + @SuppressWarnings("rawtypes") private RedisTemplate template; @SuppressWarnings("unchecked") @After @@ -85,15 +82,13 @@ public class DefaultScriptExecutorTests { template.setConnectionFactory(connFactory); template.afterPropertiesSet(); DefaultRedisScript script = new DefaultRedisScript(); - script.setLocation(new ClassPathResource( - "org/springframework/data/redis/core/script/increment.lua")); + script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/increment.lua")); script.setResultType(Long.class); ScriptExecutor scriptExecutor = new DefaultScriptExecutor(template); Long result = scriptExecutor.execute(script, Collections.singletonList("mykey")); assertNull(result); template.boundValueOps("mykey").set("2"); - assertEquals(Long.valueOf(3), - scriptExecutor.execute(script, Collections.singletonList("mykey"))); + assertEquals(Long.valueOf(3), scriptExecutor.execute(script, Collections.singletonList("mykey"))); } @SuppressWarnings("unchecked") @@ -105,13 +100,11 @@ public class DefaultScriptExecutorTests { template.setConnectionFactory(connFactory); template.afterPropertiesSet(); DefaultRedisScript script = new DefaultRedisScript(); - script.setLocation(new ClassPathResource( - "org/springframework/data/redis/core/script/cas.lua")); + script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/cas.lua")); script.setResultType(Boolean.class); ScriptExecutor scriptExecutor = new DefaultScriptExecutor(template); template.boundValueOps("counter").set(0l); - Boolean valueSet = scriptExecutor.execute(script, Collections.singletonList("counter"), 0, - 3); + Boolean valueSet = scriptExecutor.execute(script, Collections.singletonList("counter"), 0, 3); assertTrue(valueSet); assertFalse(scriptExecutor.execute(script, Collections.singletonList("counter"), 0, 3)); } @@ -124,13 +117,11 @@ public class DefaultScriptExecutorTests { template.afterPropertiesSet(); template.boundListOps("mylist").leftPushAll("a", "b", "c", "d"); DefaultRedisScript script = new DefaultRedisScript(); - script.setLocation(new ClassPathResource( - "org/springframework/data/redis/core/script/bulkpop.lua")); + script.setLocation(new ClassPathResource("org/springframework/data/redis/core/script/bulkpop.lua")); script.setResultType(List.class); ScriptExecutor scriptExecutor = new DefaultScriptExecutor(template); - List result = scriptExecutor - .execute(script, new GenericToStringSerializer(Long.class), - template.getValueSerializer(), Collections.singletonList("mylist"), 1l); + List result = scriptExecutor.execute(script, new GenericToStringSerializer(Long.class), + template.getValueSerializer(), Collections.singletonList("mylist"), 1l); assertEquals(Collections.singletonList("a"), result); } @@ -183,21 +174,19 @@ public class DefaultScriptExecutorTests { @SuppressWarnings("unchecked") @Test public void testExecuteCustomResultSerializer() { - JacksonJsonRedisSerializer personSerializer = new JacksonJsonRedisSerializer( - Person.class); + JacksonJsonRedisSerializer personSerializer = new JacksonJsonRedisSerializer(Person.class); this.template = new RedisTemplate(); template.setKeySerializer(new StringRedisSerializer()); template.setValueSerializer(personSerializer); template.setConnectionFactory(connFactory); template.afterPropertiesSet(); DefaultRedisScript script = new DefaultRedisScript(); - script.setScriptSource(new StaticScriptSource( - "redis.call('SET',KEYS[1], ARGV[1])\nreturn 'FOO'")); + script.setScriptSource(new StaticScriptSource("redis.call('SET',KEYS[1], ARGV[1])\nreturn 'FOO'")); script.setResultType(String.class); ScriptExecutor scriptExecutor = new DefaultScriptExecutor(template); Person joe = new Person("Joe", "Schmoe", 23); - String result = scriptExecutor.execute(script, personSerializer, - new StringRedisSerializer(), Collections.singletonList("bar"), joe); + String result = scriptExecutor.execute(script, personSerializer, new StringRedisSerializer(), + Collections.singletonList("bar"), joe); assertEquals("FOO", result); assertEquals(joe, template.boundValueOps("bar").get()); } diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java index e2f56fdad..a7c4c7fac 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java @@ -61,8 +61,7 @@ public class PubSubResubscribeTests { protected RedisMessageListenerContainer container; protected RedisConnectionFactory factory; - @SuppressWarnings("rawtypes") - protected RedisTemplate template; + @SuppressWarnings("rawtypes") protected RedisTemplate template; private final BlockingDeque bag = new LinkedBlockingDeque(99); @@ -118,7 +117,6 @@ public class PubSubResubscribeTests { Thread.sleep(1000); } - @Test public void testContainerPatternResubscribe() throws Exception { String payload1 = "do"; @@ -160,10 +158,10 @@ public class PubSubResubscribeTests { template.convertAndSend(ANOTHER_CHANNEL, payload2); // original listener received only one message on another channel - assertEquals(payload2,bag.poll(1, TimeUnit.SECONDS)); + assertEquals(payload2, bag.poll(1, TimeUnit.SECONDS)); assertNull(bag.poll(1, TimeUnit.SECONDS)); - //another listener receives messages on both channels + // another listener receives messages on both channels msgs.add(bag2.poll(1, TimeUnit.SECONDS)); msgs.add(bag2.poll(1, TimeUnit.SECONDS)); assertEquals(2, msgs.size()); @@ -187,11 +185,11 @@ public class PubSubResubscribeTests { // Listener removed from channel template.convertAndSend(CHANNEL, payload1); - template.convertAndSend(CHANNEL, payload2); + template.convertAndSend(CHANNEL, payload2); - // Listener receives messages on another channel + // Listener receives messages on another channel template.convertAndSend(ANOTHER_CHANNEL, anotherPayload1); - template.convertAndSend(ANOTHER_CHANNEL, anotherPayload2); + template.convertAndSend(ANOTHER_CHANNEL, anotherPayload2); Set set = new LinkedHashSet(); set.add(bag.poll(1, TimeUnit.SECONDS)); @@ -205,8 +203,9 @@ public class PubSubResubscribeTests { } /** - * Validates the behavior of {@link RedisMessageListenerContainer} when it needs to spin up - * a thread executing its PatternSubscriptionTask + * Validates the behavior of {@link RedisMessageListenerContainer} when it needs to spin up a thread executing its + * PatternSubscriptionTask + * * @throws Exception */ @Ignore("DATAREDIS-166 Intermittent corrupted input/output streams subscribing to both patterns and channels in RMLC") @@ -245,4 +244,4 @@ public class PubSubResubscribeTests { bag.add(message); } } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java b/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java index 32aad4d91..51b6f586f 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java @@ -92,9 +92,8 @@ public class PubSubTestParams { // JRedis does not support pub/sub return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate }, - {rawFactory, rawTemplate}, { stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc }, - {rawFactory, rawTemplateLtc}, { stringFactory, stringTemplateSrp }, { personFactory, personTemplateSrp }, - {rawFactory, rawTemplateSrp} - }); + { rawFactory, rawTemplate }, { stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc }, + { rawFactory, rawTemplateLtc }, { stringFactory, stringTemplateSrp }, { personFactory, personTemplateSrp }, + { rawFactory, rawTemplateSrp } }); } } diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java index 1c646e725..01b904f36 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java @@ -58,8 +58,7 @@ public class PubSubTests { protected RedisMessageListenerContainer container; protected ObjectFactory factory; - @SuppressWarnings("rawtypes") - protected RedisTemplate template; + @SuppressWarnings("rawtypes") protected RedisTemplate template; private final BlockingDeque bag = new LinkedBlockingDeque(99); @@ -120,6 +119,7 @@ public class PubSubTests { /** * Return a new instance of T + * * @return */ protected T getT() { @@ -172,8 +172,7 @@ public class PubSubTests { // DATREDIS-207 This test previously took 5 seconds on start due to monitor wait container.start(); } - - + /** * @see DATAREDIS-251 */ @@ -183,16 +182,16 @@ public class PubSubTests { container.removeMessageListener(adapter, new ChannelTopic(CHANNEL)); container.addMessageListener(adapter, Arrays.asList(new PatternTopic("*"))); container.start(); - - Thread.sleep(1000); //give the container a little time to recover - + + Thread.sleep(1000); // give the container a little time to recover + T payload = getT(); - + template.convertAndSend(CHANNEL, payload); - + Set set = new LinkedHashSet(); set.add((T) bag.poll(3, TimeUnit.SECONDS)); assertThat(set, hasItems(payload)); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java b/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java index 5222bfdea..51dd5b256 100644 --- a/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java @@ -39,12 +39,10 @@ import java.util.Collection; import java.util.List; /** - * Integration tests confirming that {@link RedisMessageListenerContainer} - * closes connections after unsubscribing - * + * Integration tests confirming that {@link RedisMessageListenerContainer} closes connections after unsubscribing + * * @author Jennifer Hickey * @author Thomas Darimont - * */ @RunWith(Parameterized.class) public class SubscriptionConnectionTests { @@ -104,8 +102,7 @@ public class SubscriptionConnectionTests { srpConnFactory.setHostName(SettingsUtils.getHost()); srpConnFactory.afterPropertiesSet(); - return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory }, - { srpConnFactory } }); + return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory }, { srpConnFactory } }); } @Test @@ -116,8 +113,7 @@ public class SubscriptionConnectionTests { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setBeanName("container" + i); - container.addMessageListener(new MessageListenerAdapter(handler), - Arrays.asList(new ChannelTopic(CHANNEL))); + container.addMessageListener(new MessageListenerAdapter(handler), Arrays.asList(new ChannelTopic(CHANNEL))); container.setTaskExecutor(new SyncTaskExecutor()); container.setSubscriptionExecutor(new SimpleAsyncTaskExecutor()); container.afterPropertiesSet(); diff --git a/src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupTest.java b/src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupTest.java index 592917848..dca5844a6 100644 --- a/src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupTest.java +++ b/src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupTest.java @@ -32,15 +32,14 @@ public class ContainerXmlSetupTest { @After public void tearDown() { - if(ctx != null) { + if (ctx != null) { ctx.destroy(); } } @Test public void testContainerSetup() throws Exception { - ctx = new GenericXmlApplicationContext( - "/org/springframework/data/redis/listener/container.xml"); + ctx = new GenericXmlApplicationContext("/org/springframework/data/redis/listener/container.xml"); RedisMessageListenerContainer container = ctx.getBean("redisContainer", RedisMessageListenerContainer.class); assertTrue(container.isRunning()); } diff --git a/src/test/java/org/springframework/data/redis/listener/adapter/MessageListenerTest.java b/src/test/java/org/springframework/data/redis/listener/adapter/MessageListenerTest.java index 19ef0cb76..47f49d1f4 100644 --- a/src/test/java/org/springframework/data/redis/listener/adapter/MessageListenerTest.java +++ b/src/test/java/org/springframework/data/redis/listener/adapter/MessageListenerTest.java @@ -54,8 +54,7 @@ public class MessageListenerTest { void customMethodWithChannel(String arg, String channel); } - @Mock - private Delegate target; + @Mock private Delegate target; @Before public void setUp() { diff --git a/src/test/java/org/springframework/data/redis/listener/adapter/RedisMDP.java b/src/test/java/org/springframework/data/redis/listener/adapter/RedisMDP.java index 336faace5..36cf37112 100644 --- a/src/test/java/org/springframework/data/redis/listener/adapter/RedisMDP.java +++ b/src/test/java/org/springframework/data/redis/listener/adapter/RedisMDP.java @@ -27,4 +27,4 @@ public class RedisMDP { public void anotherHandle(String message) { System.out.println("[*] Received message " + message); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/listener/adapter/ThrowableMessageListener.java b/src/test/java/org/springframework/data/redis/listener/adapter/ThrowableMessageListener.java index ec08f8f56..43e9823af 100644 --- a/src/test/java/org/springframework/data/redis/listener/adapter/ThrowableMessageListener.java +++ b/src/test/java/org/springframework/data/redis/listener/adapter/ThrowableMessageListener.java @@ -19,7 +19,6 @@ import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.connection.MessageListener; /** - * * @author Costin Leau */ public class ThrowableMessageListener implements MessageListener { diff --git a/src/test/java/org/springframework/data/redis/mapping/AbstractHashMapperTest.java b/src/test/java/org/springframework/data/redis/mapping/AbstractHashMapperTest.java index 18c1f73cf..26f89a27d 100644 --- a/src/test/java/org/springframework/data/redis/mapping/AbstractHashMapperTest.java +++ b/src/test/java/org/springframework/data/redis/mapping/AbstractHashMapperTest.java @@ -46,4 +46,4 @@ public abstract class AbstractHashMapperTest { public void testNestedBean() throws Exception { test(new Person("George", "Enescu", 74, new Address("liveni", 19))); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/mapping/BeanUtilsHashMapperTest.java b/src/test/java/org/springframework/data/redis/mapping/BeanUtilsHashMapperTest.java index 96afaadfb..2dcf4e9ac 100644 --- a/src/test/java/org/springframework/data/redis/mapping/BeanUtilsHashMapperTest.java +++ b/src/test/java/org/springframework/data/redis/mapping/BeanUtilsHashMapperTest.java @@ -24,7 +24,6 @@ import org.springframework.data.redis.hash.HashMapper; */ public class BeanUtilsHashMapperTest extends AbstractHashMapperTest { - protected HashMapper mapperFor(Class t) { return new BeanUtilsHashMapper(t); } diff --git a/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperTest.java b/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperTest.java index 5a0c52e3d..6cfeca159 100644 --- a/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperTest.java +++ b/src/test/java/org/springframework/data/redis/mapping/JacksonHashMapperTest.java @@ -20,7 +20,6 @@ import org.springframework.data.redis.hash.JacksonHashMapper; public class JacksonHashMapperTest extends AbstractHashMapperTest { - protected HashMapper mapperFor(Class t) { return new JacksonHashMapper(t); } diff --git a/src/test/java/org/springframework/data/redis/matcher/Equals.java b/src/test/java/org/springframework/data/redis/matcher/Equals.java index e181269ad..84790c01b 100644 --- a/src/test/java/org/springframework/data/redis/matcher/Equals.java +++ b/src/test/java/org/springframework/data/redis/matcher/Equals.java @@ -30,16 +30,13 @@ import org.hamcrest.Matcher; import static org.junit.matchers.JUnitMatchers.hasItems; /** - * Custom JUnit {@link Matcher} that exists to properly compare byte arrays, either as individual - * results or members of a {@link Collection} or {@link LinkedHashMap}. Works the same as - * assertEquals for all other types of Objects. - * - * Make some assumptions about structure of data based on what we typically get back from Redis - * commands, i.e that Sets or Maps don't contain Collections, but a List might contain a bit of - * everything (when it comes back from exec() or closePipeline()) + * Custom JUnit {@link Matcher} that exists to properly compare byte arrays, either as individual results or members of + * a {@link Collection} or {@link LinkedHashMap}. Works the same as assertEquals for all other types of Objects. Make + * some assumptions about structure of data based on what we typically get back from Redis commands, i.e that Sets or + * Maps don't contain Collections, but a List might contain a bit of everything (when it comes back from exec() or + * closePipeline()) * * @author Jennifer Hickey - * */ public class Equals extends BaseMatcher { diff --git a/src/test/java/org/springframework/data/redis/matcher/RedisTestMatchers.java b/src/test/java/org/springframework/data/redis/matcher/RedisTestMatchers.java index 28fc13e1a..2a865e7db 100644 --- a/src/test/java/org/springframework/data/redis/matcher/RedisTestMatchers.java +++ b/src/test/java/org/springframework/data/redis/matcher/RedisTestMatchers.java @@ -21,14 +21,11 @@ import org.hamcrest.Matcher; * Customs {@link Matcher}s for Redis tests * * @author Jennifer Hickey - * */ abstract public class RedisTestMatchers { /** - * - * @param expected - * The expected results + * @param expected The expected results * @return The {@link Equals} matcher */ public static Matcher isEqual(Object expected) { diff --git a/src/test/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializerTests.java b/src/test/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializerTests.java index 5d691f0ac..a2c3c339a 100644 --- a/src/test/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializerTests.java +++ b/src/test/java/org/springframework/data/redis/serializer/Jackson2JsonRedisSerializerTests.java @@ -31,24 +31,24 @@ import org.springframework.data.redis.PersonObjectFactory; * @author Christoph Strobl */ public class Jackson2JsonRedisSerializerTests { - + private Jackson2JsonRedisSerializer serializer; - + @Before public void setUp() { this.serializer = new Jackson2JsonRedisSerializer(Person.class); } - + /** - * @see DATAREDIS-241 + * @see DATAREDIS-241 */ @Test public void testJackson2JsonSerializer() throws Exception { - + Person person = new PersonObjectFactory().instance(); assertEquals(person, serializer.deserialize(serializer.serialize(person))); } - + /** * @see DATAREDIS-241 */ @@ -56,7 +56,7 @@ public class Jackson2JsonRedisSerializerTests { public void testJackson2JsonSerializerShouldReturnEmptyByteArrayWhenSerializingNull() { assertThat(serializer.serialize(null), Is.is(new byte[0])); } - + /** * @see DTATREDIS-241 */ @@ -64,24 +64,24 @@ public class Jackson2JsonRedisSerializerTests { public void testJackson2JsonSerializerShouldReturnNullWhenDerserializingEmtyByteArray() { assertThat(serializer.deserialize(new byte[0]), IsNull.nullValue()); } - + /** * @see DTATREDIS-241 */ - @Test(expected=SerializationException.class) + @Test(expected = SerializationException.class) public void testJackson2JsonSerilizerShouldThrowExceptionWhenDeserializingInvalidByteArray() { - + Person person = new PersonObjectFactory().instance(); - byte [] serializedValue = serializer.serialize(person); - Arrays.sort(serializedValue); //corrupt serialization result - + byte[] serializedValue = serializer.serialize(person); + Arrays.sort(serializedValue); // corrupt serialization result + serializer.deserialize(serializedValue); } - + /** * @see DTATREDIS-241 */ - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testJackson2JsonSerilizerThrowsExceptionWhenSettingNullObjectMapper() { serializer.setObjectMapper(null); } diff --git a/src/test/java/org/springframework/data/redis/serializer/SimpleRedisSerializerTests.java b/src/test/java/org/springframework/data/redis/serializer/SimpleRedisSerializerTests.java index 6d4dbdf45..8b80cc7cf 100644 --- a/src/test/java/org/springframework/data/redis/serializer/SimpleRedisSerializerTests.java +++ b/src/test/java/org/springframework/data/redis/serializer/SimpleRedisSerializerTests.java @@ -33,6 +33,7 @@ import org.springframework.oxm.xstream.XStreamMarshaller; public class SimpleRedisSerializerTests { private static class A implements Serializable { + private Integer value = Integer.valueOf(30); public int hashCode() { @@ -60,6 +61,7 @@ public class SimpleRedisSerializerTests { } private static class B implements Serializable { + private String name = getClass().getName(); private A a = new A(); @@ -107,7 +109,6 @@ public class SimpleRedisSerializerTests { @Test public void testBasicSerializationRoundtrip() throws Exception { - Integer integer = new Integer(300); verifySerializedObjects(new Integer(300), new Double(200), new B()); } diff --git a/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java b/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java index 7c13e4cab..3a00fbc88 100644 --- a/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java +++ b/src/test/java/org/springframework/data/redis/support/BoundKeyParams.java @@ -82,21 +82,19 @@ public class BoundKeyParams { DefaultRedisSet setSRP = new DefaultRedisSet("bound:key:setSRP", templateSRP); RedisList listSRP = new DefaultRedisList("bound:key:listSRP", templateSRP); - StringObjectFactory sof = new StringObjectFactory(); return Arrays.asList(new Object[][] { { new RedisAtomicInteger("bound:key:int", jedisConnFactory), sof, templateJS }, - { new RedisAtomicLong("bound:key:long", jedisConnFactory), sof, templateJS }, - { list, sof, templateJS }, { setJS, sof, templateJS }, { mapJS, sof, templateJS }, + { new RedisAtomicLong("bound:key:long", jedisConnFactory), sof, templateJS }, { list, sof, templateJS }, + { setJS, sof, templateJS }, { mapJS, sof, templateJS }, { new RedisAtomicInteger("bound:key:intJR", jredisConnFactory), sof, templateJR }, - { new RedisAtomicLong("bound:key:longJR", jredisConnFactory), sof, templateJR }, - { mapJR, sof, templateJR }, + { new RedisAtomicLong("bound:key:longJR", jredisConnFactory), sof, templateJR }, { mapJR, sof, templateJR }, { new RedisAtomicInteger("bound:key:intLT", lettuceConnFactory), sof, templateLT }, - { new RedisAtomicLong("bound:key:longLT", lettuceConnFactory), sof, templateLT }, - { listLT, sof, templateLT }, { setLT, sof, templateLT }, { mapLT, sof, templateLT }, + { new RedisAtomicLong("bound:key:longLT", lettuceConnFactory), sof, templateLT }, { listLT, sof, templateLT }, + { setLT, sof, templateLT }, { mapLT, sof, templateLT }, { new RedisAtomicInteger("bound:key:intSrp", srpConnFactory), sof, templateSRP }, - { new RedisAtomicLong("bound:key:longSrp", srpConnFactory), sof, templateSRP }, - { listSRP, sof, templateSRP }, { setSRP, sof, templateSRP }, { mapSRP, sof, templateSRP }}); + { new RedisAtomicLong("bound:key:longSrp", srpConnFactory), sof, templateSRP }, { listSRP, sof, templateSRP }, + { setSRP, sof, templateSRP }, { mapSRP, sof, templateSRP } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/atomic/AtomicCountersParam.java b/src/test/java/org/springframework/data/redis/support/atomic/AtomicCountersParam.java index 9c3b260c0..18df9d420 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/AtomicCountersParam.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/AtomicCountersParam.java @@ -40,8 +40,8 @@ public abstract class AtomicCountersParam { jedisConnFactory.afterPropertiesSet(); // JRedis - JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool( - SettingsUtils.getHost(), SettingsUtils.getPort())); + JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(), + SettingsUtils.getPort())); jredisConnFactory.afterPropertiesSet(); // Lettuce @@ -56,8 +56,7 @@ public abstract class AtomicCountersParam { srpConnFactory.setHostName(SettingsUtils.getHost()); srpConnFactory.afterPropertiesSet(); - return Arrays.asList(new Object[][] { { jedisConnFactory }, - { jredisConnFactory}, { lettuceConnFactory }, - { srpConnFactory} }); + return Arrays.asList(new Object[][] { { jedisConnFactory }, { jredisConnFactory }, { lettuceConnFactory }, + { srpConnFactory } }); } } diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java index 1b3448bfa..126ce30ec 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java @@ -40,7 +40,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; /** * Integration test of {@link RedisAtomicDouble} - * + * * @author Jennifer Hickey */ @RunWith(Parameterized.class) diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java index a07809dd0..788f79be0 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java @@ -38,7 +38,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; /** * Integration test of {@link RedisAtomicInteger} - * + * * @author Costin Leau * @author Jennifer Hickey */ diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java index 2335a9881..9fc0a7170 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java @@ -35,7 +35,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; /** * Integration test of {@link RedisAtomicLong} - * + * * @author Costin Leau * @author Jennifer Hickey */ diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java index 14d3504dd..d27c35181 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.support.collections; - import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; @@ -48,10 +47,9 @@ import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.RedisTemplate; - /** * Base test for Redis collections. - * + * * @author Costin Leau */ @RunWith(Parameterized.class) @@ -59,8 +57,7 @@ public abstract class AbstractRedisCollectionTests { protected AbstractRedisCollection collection; protected ObjectFactory factory; - @SuppressWarnings("rawtypes") - protected RedisTemplate template; + @SuppressWarnings("rawtypes") protected RedisTemplate template; @Before public void setUp() throws Exception { @@ -71,7 +68,6 @@ public abstract class AbstractRedisCollectionTests { abstract RedisStore copyStore(RedisStore store); - @SuppressWarnings("rawtypes") public AbstractRedisCollectionTests(ObjectFactory factory, RedisTemplate template) { this.factory = factory; @@ -91,6 +87,7 @@ public abstract class AbstractRedisCollectionTests { /** * Return a new instance of T + * * @return */ protected T getT() { @@ -104,7 +101,6 @@ public abstract class AbstractRedisCollectionTests { collection.getOperations().delete(Collections.singleton(collection.getKey())); template.execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { connection.flushDb(); return null; @@ -164,13 +160,13 @@ public abstract class AbstractRedisCollectionTests { List list = Arrays.asList(t1, t2, t3); assertThat(collection.addAll(list), is(true)); - assertThat(collection, hasItems((T[])list.toArray())); + assertThat(collection, hasItems((T[]) list.toArray())); assertThat(collection, hasItems(t1, t2, t3)); } @Test public void testEquals() { - //assertEquals(collection, copyStore(collection)); + // assertEquals(collection, copyStore(collection)); } @Test @@ -237,7 +233,7 @@ public abstract class AbstractRedisCollectionTests { List list = Arrays.asList(t1, t2, t3); assertThat(collection.addAll(list), is(true)); - assertThat(collection, hasItems((T[])list.toArray())); + assertThat(collection, hasItems((T[]) list.toArray())); assertThat(collection, hasItems(t1, t2, t3)); List newList = Arrays.asList(getT(), getT()); @@ -251,7 +247,7 @@ public abstract class AbstractRedisCollectionTests { assertThat(collection, not(hasItems(t2, t3))); } - //@Test(expected = UnsupportedOperationException.class) + // @Test(expected = UnsupportedOperationException.class) @SuppressWarnings("unchecked") public void testRetainAll() { T t1 = getT(); @@ -314,4 +310,4 @@ public abstract class AbstractRedisCollectionTests { public void testGetKey() throws Exception { assertNotNull(collection.getKey()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java index 4e24a2e0b..9b79758e6 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java @@ -50,7 +50,7 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT /** * Constructs a new AbstractRedisListTests instance. - * + * * @param factory * @param template */ @@ -546,4 +546,4 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT public void testTakeLast() { testPollLast(); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java index 3e6f0117a..42572eaf3 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java @@ -69,8 +69,7 @@ public abstract class AbstractRedisMapTests { protected RedisMap map; protected ObjectFactory keyFactory; protected ObjectFactory valueFactory; - @SuppressWarnings("rawtypes") - protected RedisTemplate template; + @SuppressWarnings("rawtypes") protected RedisTemplate template; abstract RedisMap createMap(); @@ -112,7 +111,6 @@ public abstract class AbstractRedisMapTests { map.getOperations().delete(Collections.singleton(map.getKey())); template.execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { connection.flushDb(); return null; @@ -204,8 +202,8 @@ public abstract class AbstractRedisMapTests { @Test public void testIncrementNotNumber() { - assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()) && - !(valueFactory instanceof LongAsStringObjectFactory)); + assumeTrue(!ConnectionUtils.isJredis(template.getConnectionFactory()) + && !(valueFactory instanceof LongAsStringObjectFactory)); K k1 = getKey(); V v1 = getValue(); @@ -226,18 +224,18 @@ public abstract class AbstractRedisMapTests { K k1 = getKey(); V v1 = getValue(); map.put(k1, v1); - assertEquals(Long.valueOf(Long.valueOf((String)v1) + 10), map.increment(k1, 10)); + assertEquals(Long.valueOf(Long.valueOf((String) v1) + 10), map.increment(k1, 10)); } @Test public void testIncrementDouble() { - assumeTrue(RedisVersionUtils.atLeast("2.6", template.getConnectionFactory().getConnection()) && - valueFactory instanceof DoubleAsStringObjectFactory); + assumeTrue(RedisVersionUtils.atLeast("2.6", template.getConnectionFactory().getConnection()) + && valueFactory instanceof DoubleAsStringObjectFactory); K k1 = getKey(); V v1 = getValue(); map.put(k1, v1); DecimalFormat twoDForm = new DecimalFormat("#.##"); - assertEquals(twoDForm.format(Double.valueOf((String)v1) + 3.4), twoDForm.format(map.increment(k1, 3.4))); + assertEquals(twoDForm.format(Double.valueOf((String) v1) + 3.4), twoDForm.format(map.increment(k1, 3.4))); } @Test @@ -430,7 +428,7 @@ public abstract class AbstractRedisMapTests { assertNull(map.get(k1)); } - @Test(expected=NullPointerException.class) + @Test(expected = NullPointerException.class) public void testRemoveNullValue() { map.remove(getKey(), null); } @@ -452,12 +450,12 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k1), isEqual(v2)); } - @Test(expected=NullPointerException.class) + @Test(expected = NullPointerException.class) public void testReplaceNullOldValue() { map.replace(getKey(), null, getValue()); } - @Test(expected=NullPointerException.class) + @Test(expected = NullPointerException.class) public void testReplaceNullNewValue() { map.replace(getKey(), getValue(), null); } @@ -476,8 +474,8 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k1), isEqual(v2)); } - @Test(expected=NullPointerException.class) + @Test(expected = NullPointerException.class) public void testReplaceNullValue() { map.replace(getKey(), null); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java index 681dcf39e..724314526 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java @@ -43,10 +43,9 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe protected RedisSet set; - /** * Constructs a new AbstractRedisSetTests instance. - * + * * @param factory * @param template */ @@ -55,7 +54,6 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe super(factory, template); } - @SuppressWarnings("unchecked") @Before public void setUp() throws Exception { @@ -142,7 +140,6 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe assertThat(inter, hasItem(t2)); } - @SuppressWarnings("unchecked") public void testIntersectAndStore() { RedisSet intSet1 = createSetFor("test:set:int1"); @@ -230,15 +227,14 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe assertThat(collection.addAll(list), is(true)); Iterator iterator = collection.iterator(); - List result = new ArrayList(list); while (iterator.hasNext()) { T expected = iterator.next(); Iterator resultItr = result.iterator(); - while(resultItr.hasNext()) { + while (resultItr.hasNext()) { T obj = resultItr.next(); - if(isEqual(expected).matches(obj)) { + if (isEqual(expected).matches(obj)) { resultItr.remove(); } } @@ -261,9 +257,9 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe for (int i = 0; i < array.length; i++) { Iterator resultItr = result.iterator(); - while(resultItr.hasNext()) { + while (resultItr.hasNext()) { T obj = resultItr.next(); - if(isEqual(array[i]).matches(obj)) { + if (isEqual(array[i]).matches(obj)) { resultItr.remove(); } } @@ -285,9 +281,9 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe for (int i = 0; i < array.length; i++) { Iterator resultItr = result.iterator(); - while(resultItr.hasNext()) { + while (resultItr.hasNext()) { T obj = resultItr.next(); - if(isEqual(array[i]).matches(obj)) { + if (isEqual(array[i]).matches(obj)) { resultItr.remove(); } } @@ -295,4 +291,4 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe assertEquals(0, result.size()); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java index 08ecf18dc..654df2729 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java @@ -50,7 +50,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe /** * Constructs a new AbstractRedisZSetTest instance. - * + * * @param factory * @param template */ @@ -100,7 +100,6 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertEquals(d, zSet.score(t3)); } - @Test public void testFirst() { T t1 = getT(); @@ -153,7 +152,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertEquals(Long.valueOf(1), zSet.rank(t2)); assertEquals(Long.valueOf(2), zSet.rank(t3)); assertNull(zSet.rank(getT())); - //assertNull(); + // assertNull(); } @Test @@ -520,4 +519,4 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe Object[] array = collection.toArray(new Object[zSet.size()]); assertArrayEquals(new Object[] { t1, t2, t3, t4 }, array); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java index 86f008987..4836b0dfa 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java @@ -69,7 +69,6 @@ public class RedisCollectionFactoryBeanTests { // clean up the whole db template.execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { connection.flushDb(); return null; @@ -109,7 +108,6 @@ public class RedisCollectionFactoryBeanTests { assertThat(store, instanceOf(DefaultRedisList.class)); } - @Test public void testExistingCol() throws Exception { String key = "set"; @@ -128,4 +126,4 @@ public class RedisCollectionFactoryBeanTests { assertThat(col, is(RedisProperties.class)); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java index 02432099b..71048731a 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java @@ -22,7 +22,7 @@ import org.springframework.data.redis.support.collections.DefaultRedisList; import org.springframework.data.redis.support.collections.RedisStore; /** - * Parameterized instance of Redis tests. + * Parameterized instance of Redis tests. * * @author Costin Leau */ @@ -30,7 +30,7 @@ public class RedisListTests extends AbstractRedisListTests { /** * Constructs a new RedisListTests instance. - * + * * @param factory * @param connFactory */ @@ -38,14 +38,12 @@ public class RedisListTests extends AbstractRedisListTests { super(factory, template); } - RedisStore copyStore(RedisStore store) { return new DefaultRedisList(store.getKey().toString(), store.getOperations()); } - AbstractRedisCollection createCollection() { String redisName = getClass().getName(); return new DefaultRedisList(redisName, template); } -} \ No newline at end of file +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java index 37901f138..f57603b38 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java @@ -67,7 +67,7 @@ public class RedisMapTests extends AbstractRedisMapTests { @SuppressWarnings("rawtypes") @Parameters public static Collection testParams() { - + // XStream serializer XStreamMarshaller xstream = new XStreamMarshaller(); try { diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java index 64ab31322..a6702d1fb 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java @@ -225,7 +225,7 @@ public class RedisPropertiesTests extends RedisMapTests { */ @Parameters public static Collection testParams() { - + // XStream serializer XStreamMarshaller xstream = new XStreamMarshaller(); try { diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java index 0b2ced9c1..24a12f45c 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java @@ -30,7 +30,7 @@ public class RedisSetTests extends AbstractRedisSetTests { /** * Constructs a new RedisSetTests instance. - * + * * @param factory * @param template */ @@ -38,12 +38,10 @@ public class RedisSetTests extends AbstractRedisSetTests { super(factory, template); } - RedisStore copyStore(RedisStore store) { return new DefaultRedisSet(store.getKey().toString(), store.getOperations()); } - AbstractRedisCollection createCollection() { String redisName = getClass().getName(); return new DefaultRedisSet(redisName, template); diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java index 57071e286..b2cc59fe3 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java @@ -30,7 +30,7 @@ public class RedisZSetTests extends AbstractRedisZSetTest { /** * Constructs a new RedisZSetTests instance. - * + * * @param factory * @param template */ @@ -38,12 +38,10 @@ public class RedisZSetTests extends AbstractRedisZSetTest { super(factory, template); } - RedisStore copyStore(RedisStore store) { return new DefaultRedisZSet(store.getKey().toString(), store.getOperations()); } - AbstractRedisCollection createCollection() { String redisName = getClass().getName(); return new DefaultRedisZSet(redisName, template);