From cc5dc5aa80de9670541d9a87866c7c2d8e7b2a9d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 11:31:17 +0200 Subject: [PATCH 01/68] DATAKV-40 + add option to select db on each connection factory --- .../connection/jedis/JedisConnection.java | 12 +++++-- .../jedis/JedisConnectionFactory.java | 33 +++++++++++++++++-- .../jredis/JredisConnectionFactory.java | 28 ++++++++++++++-- .../redis/listener/PubSubTestParams.java | 3 +- .../keyvalue/redis/listener/PubSubTests.java | 1 - 5 files changed, 68 insertions(+), 9 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 3187f0370..a24e1cc8e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -72,6 +72,7 @@ public class JedisConnection implements RedisConnection { private volatile JedisSubscription subscription; private volatile Pipeline pipeline; + private final int dbIndex; /** * Constructs a new JedisConnection instance. @@ -79,7 +80,7 @@ public class JedisConnection implements RedisConnection { * @param jedis Jedis entity */ public JedisConnection(Jedis jedis) { - this(jedis, null); + this(jedis, null, 0); } /** @@ -89,13 +90,20 @@ public class JedisConnection implements RedisConnection { * @param jedis * @param pool can be null, if no pool is used */ - public JedisConnection(Jedis jedis, Pool pool) { + public JedisConnection(Jedis jedis, Pool pool, int dbIndex) { this.jedis = jedis; // extract underlying connection for batch operations client = (Client) ReflectionUtils.getField(CLIENT_FIELD, jedis); transaction = new Transaction(client); this.pool = pool; + + this.dbIndex = dbIndex; + + // select the db + if (dbIndex > 0) { + select(dbIndex); + } } protected DataAccessException convertJedisAccessException(Exception ex) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java index 20cdfba51..c5e01ab7a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java @@ -24,6 +24,7 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; +import org.springframework.util.Assert; import org.springframework.util.StringUtils; import redis.clients.jedis.Jedis; @@ -51,6 +52,8 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, private JedisPool pool = null; private JedisPoolConfig poolConfig = new JedisPoolConfig(); + private int dbIndex = 0; + /** * Constructs a new JedisConnectionFactory instance * with default settings (default connection pooling, no shard information). @@ -99,6 +102,18 @@ 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. + * + * @param connection + * @return processed connection + */ + protected JedisConnection postProcessConnection(JedisConnection connection) { + return connection; + } + public void afterPropertiesSet() { if (shardInfo == null) { shardInfo = new JedisShardInfo(hostName, port); @@ -113,8 +128,8 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, } if (usePool) { - pool = new JedisPool(poolConfig, shardInfo.getHost(), shardInfo.getPort(), - shardInfo.getTimeout(), shardInfo.getPassword()); + pool = new JedisPool(poolConfig, shardInfo.getHost(), shardInfo.getPort(), shardInfo.getTimeout(), + shardInfo.getPassword()); } } @@ -131,7 +146,8 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, public JedisConnection getConnection() { Jedis jedis = fetchJedisConnector(); - return (usePool ? new JedisConnection(jedis, pool) : new JedisConnection(jedis)); + return postProcessConnection((usePool ? new JedisConnection(jedis, pool, dbIndex) : new JedisConnection(jedis, + null, dbIndex))); } @Override @@ -263,4 +279,15 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, public void setPoolConfig(JedisPoolConfig poolConfig) { this.poolConfig = poolConfig; } + + /** + * Sets the index of the database used by this connection factory. + * Can be between 0 (default) and 15. + * + * @param index database index + */ + public void setDatabase(int index) { + Assert.isTrue(index >= 0 && index < 16, "invalid DB index (needs to be between 0 and 15)"); + this.dbIndex = index; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java index 832ca8f87..b833e78da 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java @@ -45,6 +45,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean private int timeout; private boolean usePool = true; + private int dbIndex = DEFAULT_REDIS_DB; private JRedisService pool = null; // taken from JRedis code @@ -75,7 +76,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean public void afterPropertiesSet() { if (connectionSpec == null) { Assert.hasText(hostName); - connectionSpec = DefaultConnectionSpec.newSpec(hostName, port, DEFAULT_REDIS_DB, DEFAULT_REDIS_PASSWORD); + connectionSpec = DefaultConnectionSpec.newSpec(hostName, port, dbIndex, DEFAULT_REDIS_PASSWORD); connectionSpec.setConnectionFlag(Connection.Flag.RELIABLE, false); if (StringUtils.hasLength(password)) { @@ -105,10 +106,22 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean @Override public RedisConnection getConnection() { - return new JredisConnection((usePool ? pool : new JRedisClient(connectionSpec))); + return postProcessConnection(new JredisConnection((usePool ? pool : new JRedisClient(connectionSpec)))); } + /** + * 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 + */ + protected RedisConnection postProcessConnection(JredisConnection connection) { + return connection; + } + @Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof ClientRuntimeException) { @@ -210,4 +223,15 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean this.poolSize = poolSize; usePool = true; } + + /** + * Sets the index of the database used by this connection factory. + * Can be between 0 (default) and 15. + * + * @param index database index + */ + public void setDatabase(int index) { + Assert.isTrue(index >= 0 && index < 16, "invalid DB index (needs to be between 0 and 15)"); + this.dbIndex = index; + } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java index ee7dd80bb..78dd27889 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java @@ -38,9 +38,10 @@ public class PubSubTestParams { ObjectFactory personFactory = new PersonObjectFactory(); JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); - jedisConnFactory.setUsePool(false); + jedisConnFactory.setUsePool(true); jedisConnFactory.setPort(SettingsUtils.getPort()); jedisConnFactory.setHostName(SettingsUtils.getHost()); + jedisConnFactory.setDatabase(2); jedisConnFactory.afterPropertiesSet(); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java index daad32b5d..3f9f5a59d 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java @@ -57,7 +57,6 @@ public class PubSubTests { private final Object handler = new Object() { void handleMessage(String message) { - System.out.println("Received message " + message); bag.add(message); } }; From 146257b1f855768ff2915ff85bef6ca9534e8f1e Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 12:26:13 +0200 Subject: [PATCH 02/68] DATAKV-38 + eliminate BasicNumberToStringSerializer + enhance GenericToString serializer by adding a default GenericService --- .../BasicNumberToStringSerializer.java | 68 ------------------- .../serializer/GenericToStringSerializer.java | 3 +- .../support/atomic/RedisAtomicInteger.java | 4 +- .../redis/support/atomic/RedisAtomicLong.java | 4 +- 4 files changed, 6 insertions(+), 73 deletions(-) delete mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/BasicNumberToStringSerializer.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/BasicNumberToStringSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/BasicNumberToStringSerializer.java deleted file mode 100644 index e7a493879..000000000 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/BasicNumberToStringSerializer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.keyvalue.redis.serializer; - -import java.lang.reflect.Constructor; -import java.nio.charset.Charset; - -import org.springframework.beans.BeanUtils; -import org.springframework.util.Assert; - -/** - * Simple toString() serializer for the core (lang) numberic JDK types. - * - * @see String#valueOf(Object) - * @see Long#valueOf(String) - * @author Costin Leau - */ -public class BasicNumberToStringSerializer implements RedisSerializer { - - private final Charset charset; - private final Constructor ctor; - - public BasicNumberToStringSerializer(Class type) { - this(type, Charset.forName("UTF8")); - } - - public BasicNumberToStringSerializer(Class type, Charset charset) { - Assert.notNull(type); - this.charset = charset; - - if (!(Byte.class.isAssignableFrom(type) || Short.class.isAssignableFrom(type) - || Long.class.isAssignableFrom(type) || Integer.class.isAssignableFrom(type) - || Float.class.isAssignableFrom(type) || Double.class.isAssignableFrom(type))) { - throw new IllegalArgumentException("Type " + type + " not supported"); - } - - try { - ctor = type.getConstructor(String.class); - } catch (Exception ex) { - throw new IllegalArgumentException("Cannot find suitable constructor for " + type); - } - } - - @Override - public T deserialize(byte[] bytes) { - String string = new String(bytes, charset); - return BeanUtils.instantiateClass(ctor, string); - } - - @Override - public byte[] serialize(T object) { - String string = String.valueOf(object); - return string.getBytes(charset); - } -} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java index 8daafa1b9..2da22f808 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.ConversionServiceFactory; import org.springframework.util.Assert; /** @@ -40,7 +41,7 @@ import org.springframework.util.Assert; public class GenericToStringSerializer implements RedisSerializer, BeanFactoryAware { private final Charset charset; - private Converter converter; + private Converter converter = new Converter(ConversionServiceFactory.createDefaultConversionService()); private Class type; public GenericToStringSerializer(Class type) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index cae600c76..16830923e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -24,7 +24,7 @@ import org.springframework.data.keyvalue.redis.core.RedisOperations; import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.core.SessionCallback; import org.springframework.data.keyvalue.redis.core.ValueOperations; -import org.springframework.data.keyvalue.redis.serializer.BasicNumberToStringSerializer; +import org.springframework.data.keyvalue.redis.serializer.GenericToStringSerializer; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; /** @@ -50,7 +50,7 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound public RedisAtomicInteger(String redisCounter, RedisConnectionFactory factory) { RedisTemplate redisTemplate = new RedisTemplate(factory); redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new BasicNumberToStringSerializer(Integer.class)); + redisTemplate.setValueSerializer(new GenericToStringSerializer(Integer.class)); redisTemplate.setExposeConnection(true); this.key = redisCounter; this.generalOps = redisTemplate; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 001ee19ba..10275074a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -24,7 +24,7 @@ import org.springframework.data.keyvalue.redis.core.RedisOperations; import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.core.SessionCallback; import org.springframework.data.keyvalue.redis.core.ValueOperations; -import org.springframework.data.keyvalue.redis.serializer.BasicNumberToStringSerializer; +import org.springframework.data.keyvalue.redis.serializer.GenericToStringSerializer; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; /** @@ -50,7 +50,7 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound redisTemplate = new RedisTemplate(factory); redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new BasicNumberToStringSerializer(Long.class)); + redisTemplate.setValueSerializer(new GenericToStringSerializer(Long.class)); redisTemplate.setExposeConnection(true); this.key = redisCounter; this.generalOps = redisTemplate; From aef3cdece0f833d4e86f4141baeb249136bcc754 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 12:37:31 +0200 Subject: [PATCH 03/68] + fix return signature for closePipeline method --- .../DefaultStringRedisConnection.java | 2 +- .../redis/connection/RedisConnection.java | 2 +- .../connection/jedis/JedisConnection.java | 33 +++++++++++-------- .../connection/jredis/JredisConnection.java | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index 57e9fb804..c30385625 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -1119,7 +1119,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } @Override - public List closePipeline() { + public List closePipeline() { return delegate.closePipeline(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnection.java index 6f9f0a2fd..d61fe1287 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnection.java @@ -95,5 +95,5 @@ public interface RedisConnection extends RedisCommands { * * @return the result of the executed commands. */ - List closePipeline(); + List closePipeline(); } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index a24e1cc8e..f1e6eebf6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -186,10 +186,14 @@ public class JedisConnection implements RedisConnection { } } + @SuppressWarnings("unchecked") @Override - public List closePipeline() { + public List closePipeline() { if (pipeline != null) { - return pipeline.execute(); + List execute = pipeline.execute(); + if (execute != null && !execute.isEmpty()) { + return (List) execute; + } } return Collections.emptyList(); } @@ -217,7 +221,7 @@ public class JedisConnection implements RedisConnection { else { pipeline.sort(key); } - + return null; } return (sortParams != null ? jedis.sort(key, sortParams) : jedis.sort(key)); @@ -741,7 +745,8 @@ public class JedisConnection implements RedisConnection { for (byte[] key : keys) { if (isPipelined()) { pipeline.watch(key); - } else { + } + else { jedis.watch(key); } } @@ -1096,11 +1101,11 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { final List args = new ArrayList(); for (final byte[] arg : keys) { - args.add(arg); - } - args.add(Protocol.toByteArray(timeout)); - pipeline.blpop(args.toArray(new byte[args.size()][])); - return null; + args.add(arg); + } + args.add(Protocol.toByteArray(timeout)); + pipeline.blpop(args.toArray(new byte[args.size()][])); + return null; } return jedis.blpop(timeout, keys); } catch (Exception ex) { @@ -1117,11 +1122,11 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { final List args = new ArrayList(); for (final byte[] arg : keys) { - args.add(arg); - } - args.add(Protocol.toByteArray(timeout)); - pipeline.brpop(args.toArray(new byte[args.size()][])); - return null; + args.add(arg); + } + args.add(Protocol.toByteArray(timeout)); + pipeline.brpop(args.toArray(new byte[args.size()][])); + return null; } return jedis.brpop(timeout, keys); } catch (Exception ex) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index e8360b1b4..bbdb1e18c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -112,7 +112,7 @@ public class JredisConnection implements RedisConnection { } @Override - public List closePipeline() { + public List closePipeline() { return Collections.emptyList(); } From 3f77af1df3f1394535f9a95cf451cac6728d49ef Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 14:31:31 +0200 Subject: [PATCH 04/68] + refactored RedisTemplate by breaking it into multiple classes --- .../redis/core/AbstractOperations.java | 182 +++ .../CloseSuppressingInvocationHandler.java | 64 + .../redis/core/DefaultHashOperations.java | 228 +++ .../redis/core/DefaultListOperations.java | 246 +++ .../redis/core/DefaultSetOperations.java | 241 +++ .../redis/core/DefaultValueOperations.java | 243 +++ .../redis/core/DefaultZSetOperations.java | 243 +++ .../keyvalue/redis/core/RedisTemplate.java | 1447 +---------------- .../redis/core/SerializationUtils.java | 80 + 9 files changed, 1617 insertions(+), 1357 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/CloseSuppressingInvocationHandler.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java new file mode 100644 index 000000000..49c767178 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java @@ -0,0 +1,182 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.springframework.data.keyvalue.redis.connection.RedisConnection; +import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; +import org.springframework.util.Assert; + +/** + * Internal base class used by various RedisTemplate XXXOperations implementations. + * + * @author Costin Leau + */ +abstract class AbstractOperations { + + // utility methods for the template internal methods + abstract class ValueDeserializingRedisCallback implements RedisCallback { + private Object key; + + public ValueDeserializingRedisCallback(Object key) { + this.key = key; + } + + @Override + public final V doInRedis(RedisConnection connection) { + byte[] result = inRedis(rawKey(key), connection); + return deserializeValue(result); + } + + protected abstract byte[] inRedis(byte[] rawKey, RedisConnection connection); + } + + RedisSerializer keySerializer = null; + RedisSerializer valueSerializer = null; + RedisSerializer hashKeySerializer = null; + RedisSerializer hashValueSerializer = null; + RedisSerializer stringSerializer = null; + RedisTemplate template; + + AbstractOperations(RedisTemplate template) { + keySerializer = template.getKeySerializer(); + valueSerializer = template.getValueSerializer(); + hashKeySerializer = template.getHashKeySerializer(); + hashValueSerializer = template.getHashValueSerializer(); + stringSerializer = template.getStringSerializer(); + + this.template = template; + } + + + T execute(RedisCallback callback, boolean b) { + return template.execute(callback, b); + } + + public RedisOperations getOperations() { + return template; + } + + @SuppressWarnings("unchecked") + byte[] rawKey(Object key) { + Assert.notNull(key, "non null key required"); + return keySerializer.serialize(key); + } + + byte[] rawString(String key) { + return stringSerializer.serialize(key); + } + + @SuppressWarnings("unchecked") + byte[] rawValue(Object value) { + return valueSerializer.serialize(value); + } + + @SuppressWarnings("unchecked") + byte[] rawHashKey(HK hashKey) { + Assert.notNull(hashKey, "non null hash key required"); + return hashKeySerializer.serialize(hashKey); + } + + @SuppressWarnings("unchecked") + byte[] rawHashValue(HV value) { + return hashValueSerializer.serialize(value); + } + + byte[][] rawKeys(K key, K otherKey) { + final byte[][] rawKeys = new byte[2][]; + + + rawKeys[0] = rawKey(key); + rawKeys[1] = rawKey(key); + return rawKeys; + } + + byte[][] rawKeys(Collection keys) { + return rawKeys(null, keys); + } + + byte[][] rawKeys(K key, Collection keys) { + final byte[][] rawKeys = new byte[keys.size() + (key != null ? 1 : 0)][]; + + int i = 0; + + if (key != null) { + rawKeys[i++] = rawKey(key); + } + + for (K k : keys) { + rawKeys[i++] = rawKey(k); + } + + return rawKeys; + } + + > T deserializeValues(Collection rawValues, Class type) { + return SerializationUtils.deserializeValues(rawValues, type, valueSerializer); + } + + @SuppressWarnings("unchecked") + Set deserializeHashKeys(Collection rawKeys) { + return SerializationUtils.deserializeValues(rawKeys, Set.class, hashKeySerializer); + } + + @SuppressWarnings("unchecked") + List deserializeHashValues(Collection rawValues) { + return SerializationUtils.deserializeValues(rawValues, List.class, hashValueSerializer); + } + + @SuppressWarnings("unchecked") + Map deserializeHashMap(Map entries) { + Map map = new LinkedHashMap(entries.size()); + + for (Map.Entry entry : entries.entrySet()) { + map.put((HK) deserializeHashKey(entry.getKey()), (HV) deserializeHashValue(entry.getValue())); + } + + return map; + } + + @SuppressWarnings("unchecked") + K deserializeKey(byte[] value) { + return (K) SerializationUtils.deserialize(value, keySerializer); + } + + @SuppressWarnings("unchecked") + V deserializeValue(byte[] value) { + return (V) SerializationUtils.deserialize(value, valueSerializer); + } + + @SuppressWarnings("unchecked") + String deserializeString(byte[] value) { + return (String) SerializationUtils.deserialize(value, stringSerializer); + } + + @SuppressWarnings( { "unchecked" }) + HK deserializeHashKey(byte[] value) { + return (HK) SerializationUtils.deserialize(value, hashKeySerializer); + } + + @SuppressWarnings("unchecked") + HV deserializeHashValue(byte[] value) { + return (HV) SerializationUtils.deserialize(value, hashValueSerializer); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/CloseSuppressingInvocationHandler.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/CloseSuppressingInvocationHandler.java new file mode 100644 index 000000000..a44527cb4 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/CloseSuppressingInvocationHandler.java @@ -0,0 +1,64 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.springframework.data.keyvalue.redis.connection.RedisConnection; + +/** +* 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"; + private static final String HASH_CODE = "hashCode"; + private static final String EQUALS = "equals"; + + private final RedisConnection target; + + public CloseSuppressingInvocationHandler(RedisConnection target) { + this.target = target; + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + + if (method.getName().equals(EQUALS)) { + // Only consider equal when proxies are identical. + return (proxy == args[0]); + } + else if (method.getName().equals(HASH_CODE)) { + // Use hashCode of PersistenceManager proxy. + return System.identityHashCode(proxy); + } + else if (method.getName().equals(CLOSE)) { + // Handle close method: suppress, not valid. + return null; + } + + // Invoke method on target RedisConnection. + try { + Object retVal = method.invoke(this.target, args); + return retVal; + } catch (InvocationTargetException ex) { + throw ex.getTargetException(); + } + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java new file mode 100644 index 000000000..afe1def4f --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java @@ -0,0 +1,228 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.springframework.data.keyvalue.redis.connection.RedisConnection; + +/** + * Default implementation of {@link HashOperations}. + * + * @author Costin Leau + */ +class DefaultHashOperations extends AbstractOperations implements HashOperations { + + @SuppressWarnings("unchecked") + DefaultHashOperations(RedisTemplate template) { + super((RedisTemplate) template); + } + + @SuppressWarnings("unchecked") + @Override + public HV get(K key, Object hashKey) { + final byte[] rawKey = rawKey(key); + final byte[] rawHashKey = rawHashKey(hashKey); + + byte[] rawHashValue = execute(new RedisCallback() { + @Override + public byte[] doInRedis(RedisConnection connection) { + return connection.hGet(rawKey, rawHashKey); + } + }, true); + + return (HV) deserializeHashValue(rawHashValue); + } + + @Override + public Boolean hasKey(K key, Object hashKey) { + final byte[] rawKey = rawKey(key); + final byte[] rawHashKey = rawHashKey(hashKey); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.hExists(rawKey, rawHashKey); + } + }, true); + } + + @Override + public Long increment(K key, HK hashKey, final long delta) { + final byte[] rawKey = rawKey(key); + final byte[] rawHashKey = rawHashKey(hashKey); + + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.hIncrBy(rawKey, rawHashKey, delta); + } + }, true); + + } + + @Override + public Set keys(K key) { + final byte[] rawKey = rawKey(key); + + Set rawValues = execute(new RedisCallback>() { + @Override + public Set doInRedis(RedisConnection connection) { + return connection.hKeys(rawKey); + } + }, true); + + return deserializeHashKeys(rawValues); + } + + @Override + public Long size(K key) { + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.hLen(rawKey); + } + }, true); + } + + @Override + public void putAll(K key, Map m) { + if (m.isEmpty()) { + return; + } + + final byte[] rawKey = rawKey(key); + + final Map hashes = new LinkedHashMap(m.size()); + + for (Map.Entry entry : m.entrySet()) { + hashes.put(rawHashKey(entry.getKey()), rawHashValue(entry.getValue())); + } + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.hMSet(rawKey, hashes); + return null; + } + }, true); + } + + + @Override + public Collection multiGet(K key, Collection fields) { + if (fields.isEmpty()) { + return Collections.emptyList(); + } + + final byte[] rawKey = rawKey(key); + + final byte[][] rawHashKeys = new byte[fields.size()][]; + + int counter = 0; + for (HK hashKey : fields) { + rawHashKeys[counter++] = rawHashKey(hashKey); + } + + List rawValues = execute(new RedisCallback>() { + @Override + public List doInRedis(RedisConnection connection) { + return connection.hMGet(rawKey, rawHashKeys); + } + }, true); + + return deserializeHashValues(rawValues); + } + + @Override + 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() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.hSet(rawKey, rawHashKey, rawHashValue); + return null; + } + }, true); + } + + @Override + 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() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.hSetNX(rawKey, rawHashKey, rawHashValue); + } + }, true); + } + + + @Override + public List values(K key) { + final byte[] rawKey = rawKey(key); + + List rawValues = execute(new RedisCallback>() { + @Override + public List doInRedis(RedisConnection connection) { + return connection.hVals(rawKey); + } + }, true); + + return deserializeHashValues(rawValues); + } + + @Override + public void delete(K key, Object hashKey) { + final byte[] rawKey = rawKey(key); + final byte[] rawHashKey = rawHashKey(hashKey); + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.hDel(rawKey, rawHashKey); + return null; + } + }, true); + } + + @Override + public Map entries(K key) { + final byte[] rawKey = rawKey(key); + + Map entries = execute(new RedisCallback>() { + @Override + public Map doInRedis(RedisConnection connection) { + return connection.hGetAll(rawKey); + } + }, true); + + return deserializeHashMap(entries); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java new file mode 100644 index 000000000..3ea644d2a --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java @@ -0,0 +1,246 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.springframework.data.keyvalue.redis.connection.RedisConnection; +import org.springframework.data.keyvalue.redis.connection.RedisListCommands.Position; + +/** + * Default implementation of {@link ListOperations}. + * + * @author Costin Leau + */ +class DefaultListOperations extends AbstractOperations implements ListOperations { + + DefaultListOperations(RedisTemplate template) { + super(template); + } + + @Override + public V index(K key, final long index) { + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.lIndex(rawKey, index); + } + }, true); + } + + @Override + public V leftPop(K key) { + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.lPop(rawKey); + } + }, true); + } + + @Override + public V leftPop(K key, long timeout, TimeUnit unit) { + final int tm = (int) unit.toSeconds(timeout); + + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.bLPop(tm, rawKey).get(0); + } + }, true); + } + + @Override + public Long leftPush(K key, V value) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.lPush(rawKey, rawValue); + } + }, true); + } + + @Override + public Long leftPushIfPresent(K key, V value) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.lPushX(rawKey, rawValue); + } + }, true); + } + + @Override + 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() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.lInsert(rawKey, Position.BEFORE, rawPivot, rawValue); + } + }, true); + } + + @Override + public Long size(K key) { + final byte[] rawKey = rawKey(key); + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.lLen(rawKey); + } + }, true); + } + + @Override + public List range(K key, final long start, final long end) { + final byte[] rawKey = rawKey(key); + return execute(new RedisCallback>() { + @SuppressWarnings("unchecked") + @Override + public List doInRedis(RedisConnection connection) { + return deserializeValues(connection.lRange(rawKey, start, end), List.class); + } + }, true); + } + + @Override + public Long remove(K key, final long count, Object value) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.lRem(rawKey, count, rawValue); + } + }, true); + } + + @Override + public V rightPop(K key) { + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.rPop(rawKey); + } + }, true); + } + + @Override + public V rightPop(K key, long timeout, TimeUnit unit) { + final int tm = (int) unit.toSeconds(timeout); + + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.bRPop(tm, rawKey).get(0); + } + }, true); + } + + @Override + public Long rightPush(K key, V value) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.rPush(rawKey, rawValue); + } + }, true); + } + + @Override + public Long rightPushIfPresent(K key, V value) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.rPushX(rawKey, rawValue); + } + }, true); + } + + @Override + 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() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.lInsert(rawKey, Position.AFTER, rawPivot, rawValue); + } + }, true); + } + + @Override + public V rightPopAndLeftPush(K sourceKey, K destinationKey) { + final byte[] rawDestKey = rawKey(destinationKey); + + return execute(new ValueDeserializingRedisCallback(sourceKey) { + @Override + protected byte[] inRedis(byte[] rawSourceKey, RedisConnection connection) { + return connection.rPopLPush(rawSourceKey, rawDestKey); + } + }, true); + } + + @Override + public V rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit) { + final int tm = (int) unit.toSeconds(timeout); + final byte[] rawDestKey = rawKey(destinationKey); + + return execute(new ValueDeserializingRedisCallback(sourceKey) { + @Override + protected byte[] inRedis(byte[] rawSourceKey, RedisConnection connection) { + return connection.bRPopLPush(tm, rawSourceKey, rawDestKey); + } + }, true); + } + + @Override + public void set(K key, final long index, V value) { + final byte[] rawValue = rawValue(value); + execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + connection.lSet(rawKey, index, rawValue); + return null; + } + }, true); + } + + @Override + public void trim(K key, final long start, final long end) { + execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + connection.lTrim(rawKey, start, end); + return null; + } + }, true); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java new file mode 100644 index 000000000..7ebce6f32 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java @@ -0,0 +1,241 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import org.springframework.data.keyvalue.redis.connection.RedisConnection; + +/** + * Default implementation of {@link SetOperations}. + * + * @author Costin Leau + */ +class DefaultSetOperations extends AbstractOperations implements SetOperations { + + public DefaultSetOperations(RedisTemplate template) { + super(template); + } + + @Override + public Boolean add(K key, V value) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.sAdd(rawKey, rawValue); + } + }, true); + } + + @Override + public Set difference(K key, K otherKey) { + return difference(key, Collections.singleton(otherKey)); + } + + @SuppressWarnings("unchecked") + @Override + public Set difference(final K key, final Collection otherKeys) { + final byte[][] rawKeys = rawKeys(key, otherKeys); + Set rawValues = execute(new RedisCallback>() { + @Override + public Set doInRedis(RedisConnection connection) { + return connection.sDiff(rawKeys); + } + }, true); + + return deserializeValues(rawValues, Set.class); + } + + @Override + public void differenceAndStore(K key, K otherKey, K destKey) { + differenceAndStore(key, Collections.singleton(otherKey), destKey); + } + + @Override + public void differenceAndStore(final K key, final Collection otherKeys, K destKey) { + final byte[][] rawKeys = rawKeys(key, otherKeys); + final byte[] rawDestKey = rawKey(destKey); + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.sDiffStore(rawDestKey, rawKeys); + return null; + } + }, true); + } + + @Override + public Set intersect(K key, K otherKey) { + return intersect(key, Collections.singleton(otherKey)); + } + + @SuppressWarnings("unchecked") + @Override + public Set intersect(K key, Collection otherKeys) { + final byte[][] rawKeys = rawKeys(key, otherKeys); + Set rawValues = execute(new RedisCallback>() { + @Override + public Set doInRedis(RedisConnection connection) { + return connection.sInter(rawKeys); + } + }, true); + + return deserializeValues(rawValues, Set.class); + } + + @Override + public void intersectAndStore(K key, K otherKey, K destKey) { + intersectAndStore(key, Collections.singleton(otherKey), destKey); + } + + @Override + public void intersectAndStore(K key, Collection otherKeys, K destKey) { + final byte[][] rawKeys = rawKeys(key, otherKeys); + final byte[] rawDestKey = rawKey(destKey); + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.sInterStore(rawDestKey, rawKeys); + return null; + } + }, true); + } + + @Override + public Boolean isMember(K key, Object o) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(o); + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.sIsMember(rawKey, rawValue); + } + }, true); + } + + @SuppressWarnings("unchecked") + @Override + public Set members(K key) { + final byte[] rawKey = rawKey(key); + Set rawValues = execute(new RedisCallback>() { + @Override + public Set doInRedis(RedisConnection connection) { + return connection.sMembers(rawKey); + } + }, true); + + return deserializeValues(rawValues, Set.class); + } + + @Override + 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() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.sMove(rawKey, rawDestKey, rawValue); + } + }, true); + } + + @Override + public V randomMember(K key) { + + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.randomKey(); + } + }, true); + } + + @Override + public Boolean remove(K key, Object o) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(o); + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.sRem(rawKey, rawValue); + } + }, true); + } + + @Override + public V pop(K key) { + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.sPop(rawKey); + } + }, true); + } + + @Override + public Long size(K key) { + final byte[] rawKey = rawKey(key); + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.sCard(rawKey); + } + }, true); + } + + @Override + public Set union(K key, K otherKey) { + return union(key, Collections.singleton(otherKey)); + } + + @SuppressWarnings("unchecked") + @Override + public Set union(K key, Collection otherKeys) { + final byte[][] rawKeys = rawKeys(key, otherKeys); + Set rawValues = execute(new RedisCallback>() { + @Override + public Set doInRedis(RedisConnection connection) { + return connection.sUnion(rawKeys); + } + }, true); + + return deserializeValues(rawValues, Set.class); + } + + @Override + public void unionAndStore(K key, K otherKey, K destKey) { + unionAndStore(key, Collections.singleton(otherKey), destKey); + } + + @Override + public void unionAndStore(K key, Collection otherKeys, K destKey) { + final byte[][] rawKeys = rawKeys(key, otherKeys); + final byte[] rawDestKey = rawKey(destKey); + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.sUnionStore(rawDestKey, rawKeys); + return null; + } + }, true); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java new file mode 100644 index 000000000..73bf9a8c9 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java @@ -0,0 +1,243 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.springframework.dao.DataAccessException; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; + +/** + * Default implementation of {@link ValueOperations}. + * + * @author Costin Leau + */ +class DefaultValueOperations extends AbstractOperations implements ValueOperations { + + DefaultValueOperations(RedisTemplate template) { + super(template); + } + + @Override + public V get(final Object key) { + + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.get(rawKey); + } + }, true); + } + + @Override + public V getAndSet(K key, V newValue) { + final byte[] rawValue = rawValue(newValue); + return execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + return connection.getSet(rawKey, rawValue); + } + }, true); + } + + @Override + public Long increment(K key, final long delta) { + final byte[] rawKey = rawKey(key); + // TODO add conversion service in here ? + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + if (delta == 1) { + return connection.incr(rawKey); + } + + if (delta == -1) { + return connection.decr(rawKey); + } + + if (delta < 0) { + return connection.decrBy(rawKey, delta); + } + + return connection.incrBy(rawKey, delta); + } + }, true); + } + + @Override + public Integer append(K key, String value) { + final byte[] rawKey = rawKey(key); + final byte[] rawString = rawString(value); + + return execute(new RedisCallback() { + @Override + public Integer doInRedis(RedisConnection connection) { + return connection.append(rawKey, rawString).intValue(); + } + }, true); + } + + @Override + public String get(K key, final int start, final int end) { + final byte[] rawKey = rawKey(key); + + byte[] rawReturn = execute(new RedisCallback() { + @Override + public byte[] doInRedis(RedisConnection connection) { + return connection.getRange(rawKey, start, end); + } + }, true); + + return deserializeString(rawReturn); + } + + @SuppressWarnings("unchecked") + @Override + public Collection multiGet(Collection keys) { + if (keys.isEmpty()) { + return Collections.emptyList(); + } + + final byte[][] rawKeys = new byte[keys.size()][]; + + int counter = 0; + for (K hashKey : keys) { + rawKeys[counter++] = rawKey(hashKey); + } + + List rawValues = execute(new RedisCallback>() { + @Override + public List doInRedis(RedisConnection connection) { + return connection.mGet(rawKeys); + } + }, true); + + return deserializeValues(rawValues, List.class); + } + + @Override + public void multiSet(Map m) { + if (m.isEmpty()) { + return; + } + + final Map rawKeys = new LinkedHashMap(m.size()); + + for (Map.Entry entry : m.entrySet()) { + rawKeys.put(rawKey(entry.getKey()), rawValue(entry.getValue())); + } + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.mSet(rawKeys); + return null; + } + }, true); + } + + @Override + public void multiSetIfAbsent(Map m) { + if (m.isEmpty()) { + return; + } + + final Map rawKeys = new LinkedHashMap(m.size()); + + for (Map.Entry entry : m.entrySet()) { + rawKeys.put(rawKey(entry.getKey()), rawValue(entry.getValue())); + } + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.mSetNX(rawKeys); + return null; + } + }, true); + } + + @Override + public void set(K key, V value) { + final byte[] rawValue = rawValue(value); + execute(new ValueDeserializingRedisCallback(key) { + @Override + protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { + connection.set(rawKey, rawValue); + return null; + } + }, true); + } + + @Override + public void set(K key, V value, long timeout, TimeUnit unit) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + final long rawTimeout = unit.toSeconds(timeout); + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) throws DataAccessException { + connection.setEx(rawKey, (int) rawTimeout, rawValue); + return null; + } + }, true); + } + + @Override + public Boolean setIfAbsent(K key, V value) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) throws DataAccessException { + return connection.setNX(rawKey, rawValue); + } + }, true); + } + + + @Override + public void set(K key, final int start, final int end) { + final byte[] rawKey = rawKey(key); + + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.setRange(rawKey, start, end); + return null; + } + }, true); + } + + @Override + public Long size(K key) { + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.strLen(rawKey); + } + }, true); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java new file mode 100644 index 000000000..03a785029 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java @@ -0,0 +1,243 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import org.springframework.data.keyvalue.redis.connection.RedisConnection; + +/** + * Default implementation of {@link ZSetOperations}. + * + * @author Costin Leau + */ +class DefaultZSetOperations extends AbstractOperations implements ZSetOperations { + + DefaultZSetOperations(RedisTemplate template) { + super(template); + } + + @Override + public Boolean add(final K key, final V value, final double score) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.zAdd(rawKey, score, rawValue); + } + }, true); + } + + @Override + public Double incrementScore(K key, V value, final double delta) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); + + return execute(new RedisCallback() { + @Override + public Double doInRedis(RedisConnection connection) { + return connection.zIncrBy(rawKey, delta, rawValue); + } + }, true); + } + + @Override + public void intersectAndStore(K key, K otherKey, K destKey) { + intersectAndStore(key, Collections.singleton(otherKey), destKey); + } + + @Override + public void intersectAndStore(K key, Collection otherKeys, K destKey) { + final byte[][] rawKeys = rawKeys(key, otherKeys); + final byte[] rawDestKey = rawKey(destKey); + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.zInterStore(rawDestKey, rawKeys); + return null; + } + }, true); + } + + @SuppressWarnings("unchecked") + @Override + public Set range(K key, final long start, final long end) { + final byte[] rawKey = rawKey(key); + + Set rawValues = execute(new RedisCallback>() { + @Override + public Set doInRedis(RedisConnection connection) { + return connection.zRange(rawKey, start, end); + } + }, true); + + return deserializeValues(rawValues, Set.class); + } + + @SuppressWarnings("unchecked") + @Override + public Set rangeByScore(K key, final double min, final double max) { + final byte[] rawKey = rawKey(key); + + Set rawValues = execute(new RedisCallback>() { + @Override + public Set doInRedis(RedisConnection connection) { + return connection.zRangeByScore(rawKey, min, max); + } + }, true); + + return deserializeValues(rawValues, Set.class); + } + + @Override + public Long rank(K key, Object o) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(o); + + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + Long zRank = connection.zRank(rawKey, rawValue); + return (zRank != null && zRank.longValue() >= 0 ? zRank : null); + } + }, true); + } + + @Override + public Long reverseRank(K key, Object o) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(o); + + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + Long zRank = connection.zRevRank(rawKey, rawValue); + return (zRank != null && zRank.longValue() >= 0 ? zRank : null); + } + }, true); + } + + @Override + public Boolean remove(K key, Object o) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(o); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.zRem(rawKey, rawValue); + } + }, true); + } + + @Override + public void removeRange(K key, final long start, final long end) { + final byte[] rawKey = rawKey(key); + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.zRemRange(rawKey, start, end); + return null; + } + }, true); + } + + @Override + public void removeRangeByScore(K key, final double min, final double max) { + final byte[] rawKey = rawKey(key); + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.zRemRangeByScore(rawKey, min, max); + return null; + } + }, true); + } + + @SuppressWarnings("unchecked") + @Override + public Set reverseRange(K key, final long start, final long end) { + final byte[] rawKey = rawKey(key); + + Set rawValues = execute(new RedisCallback>() { + @Override + public Set doInRedis(RedisConnection connection) { + return connection.zRevRange(rawKey, start, end); + } + }, true); + + return deserializeValues(rawValues, Set.class); + } + + @Override + public Double score(K key, Object o) { + final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(o); + + return execute(new RedisCallback() { + @Override + public Double doInRedis(RedisConnection connection) { + return connection.zScore(rawKey, rawValue); + } + }, true); + } + + @Override + public Long count(K key, final double min, final double max) { + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.zCount(rawKey, min, max); + } + }, true); + } + + @Override + public Long size(K key) { + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback() { + @Override + public Long doInRedis(RedisConnection connection) { + return connection.zCard(rawKey); + } + }, true); + } + + @Override + public void unionAndStore(K key, K otherKey, K destKey) { + unionAndStore(key, Collections.singleton(otherKey), destKey); + } + + @Override + public void unionAndStore(K key, Collection otherKeys, K destKey) { + final byte[][] rawKeys = rawKeys(key, otherKeys); + final byte[] rawDestKey = rawKey(destKey); + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.zUnionStore(rawDestKey, rawKeys); + return null; + } + }, true); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 52bded364..e16cf1291 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -15,28 +15,20 @@ */ package org.springframework.data.keyvalue.redis.core; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.redis.connection.DataType; -import org.springframework.data.keyvalue.redis.connection.DefaultSortParameters; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.data.keyvalue.redis.connection.SortParameters; -import org.springframework.data.keyvalue.redis.connection.RedisListCommands.Position; import org.springframework.data.keyvalue.redis.core.query.SortQuery; import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; @@ -81,10 +73,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation private RedisSerializer stringSerializer = new StringRedisSerializer(); // cache singleton objects (where possible) - private final ValueOperations valueOps = new DefaultValueOperations(); - private final ListOperations listOps = new DefaultListOperations(); - private final SetOperations setOps = new DefaultSetOperations(); - private final ZSetOperations zSetOps = new DefaultZSetOperations(); + private ValueOperations valueOps; + private ListOperations listOps; + private SetOperations setOps; + private ZSetOperations zSetOps; /** * Constructs a new RedisTemplate instance. @@ -94,7 +86,8 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Constructs a new RedisTemplate instance. + * Constructs a new RedisTemplate instance and automatically initializes the template. + * If other parameters need to be set, it is recommended to use {@link #setConnectionFactory(RedisConnectionFactory)} instead. * * @param connectionFactory connection factory for creating new connections */ @@ -131,6 +124,11 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation if (defaultUsed) { Assert.notNull(defaultSerializer, "default serializer null and not all serializers initialized"); } + + valueOps = new DefaultValueOperations(this); + listOps = new DefaultListOperations(this); + setOps = new DefaultSetOperations(this); + zSetOps = new DefaultZSetOperations(this); } @Override @@ -295,6 +293,15 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return valueSerializer; } + /** + * Returns the hashKeySerializer. + * + * @return Returns the hashKeySerializer + */ + public RedisSerializer getHashKeySerializer() { + return hashKeySerializer; + } + /** * Sets the hash key (or field) serializer to be used by this template. Defaults to {@link #getDefaultSerializer()}. * @@ -304,6 +311,15 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation this.hashKeySerializer = hashKeySerializer; } + /** + * Returns the hashValueSerializer. + * + * @return Returns the hashValueSerializer + */ + public RedisSerializer getHashValueSerializer() { + return hashValueSerializer; + } + /** * Sets the hash value serializer to be used by this template. Defaults to {@link #getDefaultSerializer()}. * @@ -313,6 +329,15 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation this.hashValueSerializer = hashValueSerializer; } + /** + * Returns the stringSerializer. + * + * @return Returns the stringSerializer + */ + public RedisSerializer getStringSerializer() { + return stringSerializer; + } + /** * Sets the string value serializer to be used by this template (when the arguments or return types * are always strings). Defaults to {@link StringRedisSerializer}. @@ -324,44 +349,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation this.stringSerializer = stringSerializer; } - /** - * Invocation handler that suppresses close calls on {@link RedisConnection}. - * @see RedisConnection#close() - */ - private class CloseSuppressingInvocationHandler implements InvocationHandler { - - private final RedisConnection target; - - public CloseSuppressingInvocationHandler(RedisConnection target) { - this.target = target; - } - - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - // Invocation on PersistenceManager interface (or provider-specific extension) coming in... - - if (method.getName().equals("equals")) { - // Only consider equal when proxies are identical. - return (proxy == args[0]); - } - else if (method.getName().equals("hashCode")) { - // Use hashCode of PersistenceManager proxy. - return System.identityHashCode(proxy); - } - else if (method.getName().equals("close")) { - // Handle close method: suppress, not valid. - return null; - } - - // Invoke method on target RedisConnection. - try { - Object retVal = method.invoke(this.target, args); - return retVal; - } catch (InvocationTargetException ex) { - throw ex.getTargetException(); - } - } - } - @SuppressWarnings("unchecked") private byte[] rawKey(Object key) { Assert.notNull(key, "non null key required"); @@ -377,17 +364,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return valueSerializer.serialize(value); } - @SuppressWarnings("unchecked") - private byte[] rawHashKey(HK hashKey) { - Assert.notNull(hashKey, "non null hash key required"); - return hashKeySerializer.serialize(hashKey); - } - - @SuppressWarnings("unchecked") - private byte[] rawHashValue(HV value) { - return hashValueSerializer.serialize(value); - } - private byte[][] rawKeys(Collection keys) { final byte[][] rawKeys = new byte[keys.size()][]; @@ -399,158 +375,14 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return rawKeys; } - private byte[][] rawKeys(K key, K otherKey) { - final byte[][] rawKeys = new byte[2][]; - - - rawKeys[0] = rawKey(key); - rawKeys[1] = rawKey(key); - return rawKeys; - } - - private byte[][] rawKeys(K key, Collection keys) { - final byte[][] rawKeys = new byte[keys.size() + 1][]; - - - rawKeys[0] = rawKey(key); - int i = 1; - for (K k : keys) { - rawKeys[i++] = rawKey(k); - } - - return rawKeys; - } - - @SuppressWarnings("unchecked") - private > T deserializeValues(Collection rawValues, Class type) { - return (T) deserializeValues(rawValues, type, valueSerializer); - } - - @SuppressWarnings("unchecked") - private > T deserializeValues(Collection rawValues, Class type, RedisSerializer redisSerializer) { - Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawValues.size()) - : new LinkedHashSet(rawValues.size())); - for (byte[] bs : rawValues) { - if (bs != null) { - values.add(redisSerializer.deserialize(bs)); - } - } - - return (T) values; - } - - @SuppressWarnings("unchecked") - private Collection deserializeHashKeys(Collection rawKeys, Class type) { - Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawKeys.size()) - : new LinkedHashSet(rawKeys.size())); - for (byte[] bs : rawKeys) { - if (bs != null) { - values.add((H) hashKeySerializer.deserialize(bs)); - } - } - - return values; - } - - @SuppressWarnings("unchecked") - private Collection deserializeHashValues(Collection rawValues, Class type) { - Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawValues.size()) - : new LinkedHashSet(rawValues.size())); - for (byte[] bs : rawValues) { - if (bs != null) { - values.add((H) hashValueSerializer.deserialize(bs)); - } - } - - return values; - } - - - @SuppressWarnings("unchecked") - private Map deserializeHashMap(Map entries) { - Map map = new LinkedHashMap(entries.size()); - - for (Map.Entry entry : entries.entrySet()) { - map.put((HK) deserializeHashKey(entry.getKey()), (HV) deserializeHashValue(entry.getValue())); - } - - return map; - } - - - @SuppressWarnings("unchecked") - private Collection deserializeKeys(Collection rawKeys, Class type) { - Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawKeys.size()) - : new LinkedHashSet(rawKeys.size())); - for (byte[] bs : rawKeys) { - if (bs != null) { - values.add((K) hashValueSerializer.deserialize(bs)); - } - } - - return values; - } - @SuppressWarnings("unchecked") private K deserializeKey(byte[] value) { - return (K) deserialize(value, keySerializer); + return (K) SerializationUtils.deserialize(value, keySerializer); } - @SuppressWarnings("unchecked") - private V deserializeValue(byte[] value) { - return (V) deserialize(value, valueSerializer); - } - - @SuppressWarnings("unchecked") - private String deserializeString(byte[] value) { - return deserialize(value, stringSerializer); - } - - @SuppressWarnings( { "unchecked" }) - private HK deserializeHashKey(byte[] value) { - return (HK) deserialize(value, hashKeySerializer); - } - - @SuppressWarnings("unchecked") - private HV deserializeHashValue(byte[] value) { - return (HV) deserialize(value, hashValueSerializer); - } - - private T deserialize(byte[] value, RedisSerializer serializer) { - if (isEmpty(value)) { - return null; - } - return serializer.deserialize(value); - } - - - private static boolean isEmpty(byte[] data) { - return (data == null || data.length == 0); - } - - // utility methods for the template internal methods - private abstract class ValueDeserializingRedisCallback implements RedisCallback { - private Object key; - - public ValueDeserializingRedisCallback(Object key) { - this.key = key; - } - - @Override - public final V doInRedis(RedisConnection connection) { - byte[] result = inRedis(rawKey(key), connection); - return deserializeValue(result); - } - - protected abstract byte[] inRedis(byte[] rawKey, RedisConnection connection); - } - - // // RedisOperations // - - @Override public Object exec() { return execute(new RedisCallback() { @@ -659,6 +491,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @SuppressWarnings("unchecked") @Override public Set keys(K pattern) { final byte[] rawKey = rawKey(pattern); @@ -670,7 +503,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } }, true); - return (Set) deserializeKeys(rawKeys, Set.class); + return (Set) SerializationUtils.deserializeValues(rawKeys, Set.class, keySerializer); } @Override @@ -797,1137 +630,8 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - // - // Value Ops - // - - @Override - public BoundValueOperations boundValueOps(K key) { - return new DefaultBoundValueOperations(key, this); - } - - @Override - public ValueOperations opsForValue() { - return valueOps; - } - - private class DefaultValueOperations implements ValueOperations { - - @Override - public V get(final Object key) { - - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.get(rawKey); - } - }, true); - } - - @Override - public V getAndSet(K key, V newValue) { - final byte[] rawValue = rawValue(newValue); - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.getSet(rawKey, rawValue); - } - }, true); - } - - @Override - public Long increment(K key, final long delta) { - final byte[] rawKey = rawKey(key); - // TODO add conversion service in here ? - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - if (delta == 1) { - return connection.incr(rawKey); - } - - if (delta == -1) { - return connection.decr(rawKey); - } - - if (delta < 0) { - return connection.decrBy(rawKey, delta); - } - - return connection.incrBy(rawKey, delta); - } - }, true); - } - - @Override - public Integer append(K key, String value) { - final byte[] rawKey = rawKey(key); - final byte[] rawString = rawString(value); - - return execute(new RedisCallback() { - @Override - public Integer doInRedis(RedisConnection connection) { - return connection.append(rawKey, rawString).intValue(); - } - }, true); - } - - @Override - public String get(K key, final int start, final int end) { - final byte[] rawKey = rawKey(key); - - byte[] rawReturn = execute(new RedisCallback() { - @Override - public byte[] doInRedis(RedisConnection connection) { - return connection.getRange(rawKey, start, end); - } - }, true); - - return deserializeString(rawReturn); - } - - @Override - public Collection multiGet(Collection keys) { - if (keys.isEmpty()) { - return Collections.emptyList(); - } - - final byte[][] rawKeys = new byte[keys.size()][]; - - int counter = 0; - for (K hashKey : keys) { - rawKeys[counter++] = rawKey(hashKey); - } - - List rawValues = execute(new RedisCallback>() { - @Override - public List doInRedis(RedisConnection connection) { - return connection.mGet(rawKeys); - } - }, true); - - return (List) deserializeValues(rawValues, List.class); - } - - @Override - public void multiSet(Map m) { - if (m.isEmpty()) { - return; - } - - final Map rawKeys = new LinkedHashMap(m.size()); - - for (Map.Entry entry : m.entrySet()) { - rawKeys.put(rawKey(entry.getKey()), rawValue(entry.getValue())); - } - - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.mSet(rawKeys); - return null; - } - }, true); - } - - @Override - public void multiSetIfAbsent(Map m) { - if (m.isEmpty()) { - return; - } - - final Map rawKeys = new LinkedHashMap(m.size()); - - for (Map.Entry entry : m.entrySet()) { - rawKeys.put(rawKey(entry.getKey()), rawValue(entry.getValue())); - } - - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.mSetNX(rawKeys); - return null; - } - }, true); - } - - @Override - public void set(K key, V value) { - final byte[] rawValue = rawValue(value); - execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - connection.set(rawKey, rawValue); - return null; - } - }, true); - } - - @Override - public void set(K key, V value, long timeout, TimeUnit unit) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - final long rawTimeout = unit.toSeconds(timeout); - - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) throws DataAccessException { - connection.setEx(rawKey, (int) rawTimeout, rawValue); - return null; - } - }, true); - } - - @Override - public Boolean setIfAbsent(K key, V value) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - - return execute(new RedisCallback() { - @Override - public Boolean doInRedis(RedisConnection connection) throws DataAccessException { - return connection.setNX(rawKey, rawValue); - } - }, true); - } - - - @Override - public void set(K key, final int start, final int end) { - final byte[] rawKey = rawKey(key); - - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.setRange(rawKey, start, end); - return null; - } - }, true); - } - - @Override - public Long size(K key) { - final byte[] rawKey = rawKey(key); - - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.strLen(rawKey); - } - }, true); - } - - @Override - public RedisOperations getOperations() { - return RedisTemplate.this; - } - } - - @Override - public ListOperations opsForList() { - return listOps; - } - - @Override - public BoundListOperations boundListOps(K key) { - return new DefaultBoundListOperations(key, this); - } - - - - // - // List operations - // - - private class DefaultListOperations implements ListOperations { - - @Override - public V index(K key, final long index) { - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.lIndex(rawKey, index); - } - }, true); - } - - @Override - public V leftPop(K key) { - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.lPop(rawKey); - } - }, true); - } - - @Override - public V leftPop(K key, long timeout, TimeUnit unit) { - final int tm = (int) unit.toSeconds(timeout); - - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.bLPop(tm, rawKey).get(0); - } - }, true); - } - - @Override - public Long leftPush(K key, V value) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.lPush(rawKey, rawValue); - } - }, true); - } - - @Override - public Long leftPushIfPresent(K key, V value) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.lPushX(rawKey, rawValue); - } - }, true); - } - - @Override - 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() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.lInsert(rawKey, Position.BEFORE, rawPivot, rawValue); - } - }, true); - } - - @Override - public Long size(K key) { - final byte[] rawKey = rawKey(key); - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.lLen(rawKey); - } - }, true); - } - - @Override - public List range(K key, final long start, final long end) { - final byte[] rawKey = rawKey(key); - return execute(new RedisCallback>() { - @Override - public List doInRedis(RedisConnection connection) { - return deserializeValues(connection.lRange(rawKey, start, end), List.class); - } - }, true); - } - - @Override - public Long remove(K key, final long count, Object value) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.lRem(rawKey, count, rawValue); - } - }, true); - } - - @Override - public V rightPop(K key) { - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.rPop(rawKey); - } - }, true); - } - - @Override - public V rightPop(K key, long timeout, TimeUnit unit) { - final int tm = (int) unit.toSeconds(timeout); - - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.bRPop(tm, rawKey).get(0); - } - }, true); - } - - @Override - public Long rightPush(K key, V value) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.rPush(rawKey, rawValue); - } - }, true); - } - - @Override - public Long rightPushIfPresent(K key, V value) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.rPushX(rawKey, rawValue); - } - }, true); - } - - @Override - 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() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.lInsert(rawKey, Position.AFTER, rawPivot, rawValue); - } - }, true); - } - - @Override - public V rightPopAndLeftPush(K sourceKey, K destinationKey) { - final byte[] rawDestKey = rawKey(destinationKey); - - return execute(new ValueDeserializingRedisCallback(sourceKey) { - @Override - protected byte[] inRedis(byte[] rawSourceKey, RedisConnection connection) { - return connection.rPopLPush(rawSourceKey, rawDestKey); - } - }, true); - } - - @Override - public V rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit) { - final int tm = (int) unit.toSeconds(timeout); - final byte[] rawDestKey = rawKey(destinationKey); - - return execute(new ValueDeserializingRedisCallback(sourceKey) { - @Override - protected byte[] inRedis(byte[] rawSourceKey, RedisConnection connection) { - return connection.bRPopLPush(tm, rawSourceKey, rawDestKey); - } - }, true); - } - - @Override - public void set(K key, final long index, V value) { - final byte[] rawValue = rawValue(value); - execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - connection.lSet(rawKey, index, rawValue); - return null; - } - }, true); - } - - @Override - public void trim(K key, final long start, final long end) { - execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - connection.lTrim(rawKey, start, end); - return null; - } - }, true); - } - - @Override - public RedisOperations getOperations() { - return RedisTemplate.this; - } - } - - // - // Set operations - // - - @Override - public BoundSetOperations boundSetOps(K key) { - return new DefaultBoundSetOperations(key, this); - } - - @Override - public SetOperations opsForSet() { - return setOps; - } - - private class DefaultSetOperations implements SetOperations { - - @Override - public Boolean add(K key, V value) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - return execute(new RedisCallback() { - @Override - public Boolean doInRedis(RedisConnection connection) { - return connection.sAdd(rawKey, rawValue); - } - }, true); - } - - @Override - public Set difference(K key, K otherKey) { - return difference(key, Collections.singleton(otherKey)); - } - - @Override - public Set difference(final K key, final Collection otherKeys) { - final byte[][] rawKeys = rawKeys(key, otherKeys); - Set rawValues = execute(new RedisCallback>() { - @Override - public Set doInRedis(RedisConnection connection) { - return connection.sDiff(rawKeys); - } - }, true); - - return deserializeValues(rawValues, Set.class); - } - - @Override - public void differenceAndStore(K key, K otherKey, K destKey) { - differenceAndStore(key, Collections.singleton(otherKey), destKey); - } - - @Override - public void differenceAndStore(final K key, final Collection otherKeys, K destKey) { - final byte[][] rawKeys = rawKeys(key, otherKeys); - final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.sDiffStore(rawDestKey, rawKeys); - return null; - } - }, true); - } - - @Override - public RedisOperations getOperations() { - return RedisTemplate.this; - } - - @Override - public Set intersect(K key, K otherKey) { - return intersect(key, Collections.singleton(otherKey)); - } - - @Override - public Set intersect(K key, Collection otherKeys) { - final byte[][] rawKeys = rawKeys(key, otherKeys); - Set rawValues = execute(new RedisCallback>() { - @Override - public Set doInRedis(RedisConnection connection) { - return connection.sInter(rawKeys); - } - }, true); - - return deserializeValues(rawValues, Set.class); - } - - @Override - public void intersectAndStore(K key, K otherKey, K destKey) { - intersectAndStore(key, Collections.singleton(otherKey), destKey); - } - - @Override - public void intersectAndStore(K key, Collection otherKeys, K destKey) { - final byte[][] rawKeys = rawKeys(key, otherKeys); - final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.sInterStore(rawDestKey, rawKeys); - return null; - } - }, true); - } - - @Override - public Boolean isMember(K key, Object o) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(o); - return execute(new RedisCallback() { - @Override - public Boolean doInRedis(RedisConnection connection) { - return connection.sIsMember(rawKey, rawValue); - } - }, true); - } - - @Override - public Set members(K key) { - final byte[] rawKey = rawKey(key); - Set rawValues = execute(new RedisCallback>() { - @Override - public Set doInRedis(RedisConnection connection) { - return connection.sMembers(rawKey); - } - }, true); - - return deserializeValues(rawValues, Set.class); - } - - @Override - 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() { - @Override - public Boolean doInRedis(RedisConnection connection) { - return connection.sMove(rawKey, rawDestKey, rawValue); - } - }, true); - } - - @Override - public V randomMember(K key) { - - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.randomKey(); - } - }, true); - } - - @Override - public Boolean remove(K key, Object o) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(o); - return execute(new RedisCallback() { - @Override - public Boolean doInRedis(RedisConnection connection) { - return connection.sRem(rawKey, rawValue); - } - }, true); - } - - @Override - public V pop(K key) { - return execute(new ValueDeserializingRedisCallback(key) { - @Override - protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { - return connection.sPop(rawKey); - } - }, true); - } - - @Override - public Long size(K key) { - final byte[] rawKey = rawKey(key); - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.sCard(rawKey); - } - }, true); - } - - @Override - public Set union(K key, K otherKey) { - return union(key, Collections.singleton(otherKey)); - } - - @Override - public Set union(K key, Collection otherKeys) { - final byte[][] rawKeys = rawKeys(key, otherKeys); - Set rawValues = execute(new RedisCallback>() { - @Override - public Set doInRedis(RedisConnection connection) { - return connection.sUnion(rawKeys); - } - }, true); - - return deserializeValues(rawValues, Set.class); - } - - @Override - public void unionAndStore(K key, K otherKey, K destKey) { - unionAndStore(key, Collections.singleton(otherKey), destKey); - } - - @Override - public void unionAndStore(K key, Collection otherKeys, K destKey) { - final byte[][] rawKeys = rawKeys(key, otherKeys); - final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.sUnionStore(rawDestKey, rawKeys); - return null; - } - }, true); - } - } - - // - // ZSet operations - // - - @Override - public BoundZSetOperations boundZSetOps(K key) { - return new DefaultBoundZSetOperations(key, this); - } - - @Override - public ZSetOperations opsForZSet() { - return zSetOps; - } - - private class DefaultZSetOperations implements ZSetOperations { - - @Override - public Boolean add(final K key, final V value, final double score) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - - return execute(new RedisCallback() { - @Override - public Boolean doInRedis(RedisConnection connection) { - return connection.zAdd(rawKey, score, rawValue); - } - }, true); - } - - @Override - public Double incrementScore(K key, V value, final double delta) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(value); - - return execute(new RedisCallback() { - @Override - public Double doInRedis(RedisConnection connection) { - return connection.zIncrBy(rawKey, delta, rawValue); - } - }, true); - } - - @Override - public RedisOperations getOperations() { - return RedisTemplate.this; - } - - - @Override - public void intersectAndStore(K key, K otherKey, K destKey) { - intersectAndStore(key, Collections.singleton(otherKey), destKey); - } - - @Override - public void intersectAndStore(K key, Collection otherKeys, K destKey) { - final byte[][] rawKeys = rawKeys(key, otherKeys); - final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.zInterStore(rawDestKey, rawKeys); - return null; - } - }, true); - } - - @Override - public Set range(K key, final long start, final long end) { - final byte[] rawKey = rawKey(key); - - Set rawValues = execute(new RedisCallback>() { - @Override - public Set doInRedis(RedisConnection connection) { - return connection.zRange(rawKey, start, end); - } - }, true); - - return deserializeValues(rawValues, Set.class); - } - - @Override - public Set rangeByScore(K key, final double min, final double max) { - final byte[] rawKey = rawKey(key); - - Set rawValues = execute(new RedisCallback>() { - @Override - public Set doInRedis(RedisConnection connection) { - return connection.zRangeByScore(rawKey, min, max); - } - }, true); - - return deserializeValues(rawValues, Set.class); - } - - @Override - public Long rank(K key, Object o) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(o); - - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - Long zRank = connection.zRank(rawKey, rawValue); - return (zRank != null && zRank.longValue() >= 0 ? zRank : null); - } - }, true); - } - - @Override - public Long reverseRank(K key, Object o) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(o); - - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - Long zRank = connection.zRevRank(rawKey, rawValue); - return (zRank != null && zRank.longValue() >= 0 ? zRank : null); - } - }, true); - } - - @Override - public Boolean remove(K key, Object o) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(o); - - return execute(new RedisCallback() { - @Override - public Boolean doInRedis(RedisConnection connection) { - return connection.zRem(rawKey, rawValue); - } - }, true); - } - - @Override - public void removeRange(K key, final long start, final long end) { - final byte[] rawKey = rawKey(key); - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.zRemRange(rawKey, start, end); - return null; - } - }, true); - } - - @Override - public void removeRangeByScore(K key, final double min, final double max) { - final byte[] rawKey = rawKey(key); - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.zRemRangeByScore(rawKey, min, max); - return null; - } - }, true); - } - - @Override - public Set reverseRange(K key, final long start, final long end) { - final byte[] rawKey = rawKey(key); - - Set rawValues = execute(new RedisCallback>() { - @Override - public Set doInRedis(RedisConnection connection) { - return connection.zRevRange(rawKey, start, end); - } - }, true); - - return deserializeValues(rawValues, Set.class); - } - - @Override - public Double score(K key, Object o) { - final byte[] rawKey = rawKey(key); - final byte[] rawValue = rawValue(o); - - return execute(new RedisCallback() { - @Override - public Double doInRedis(RedisConnection connection) { - return connection.zScore(rawKey, rawValue); - } - }, true); - } - - @Override - public Long count(K key, final double min, final double max) { - final byte[] rawKey = rawKey(key); - - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.zCount(rawKey, min, max); - } - }, true); - } - - @Override - public Long size(K key) { - final byte[] rawKey = rawKey(key); - - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.zCard(rawKey); - } - }, true); - } - - @Override - public void unionAndStore(K key, K otherKey, K destKey) { - unionAndStore(key, Collections.singleton(otherKey), destKey); - } - - @Override - public void unionAndStore(K key, Collection otherKeys, K destKey) { - final byte[][] rawKeys = rawKeys(key, otherKeys); - final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.zUnionStore(rawDestKey, rawKeys); - return null; - } - }, true); - } - } - - - // - // Hash Operations - // - - @Override - public BoundHashOperations boundHashOps(K key) { - return new DefaultBoundHashOperations(key, this); - } - - @Override - public HashOperations opsForHash() { - return new DefaultHashOperations(); - } - - private class DefaultHashOperations implements HashOperations { - - @Override - public RedisOperations getOperations() { - return RedisTemplate.this; - } - - @Override - public HV get(K key, Object hashKey) { - final byte[] rawKey = rawKey(key); - final byte[] rawHashKey = rawHashKey(hashKey); - - byte[] rawHashValue = execute(new RedisCallback() { - @Override - public byte[] doInRedis(RedisConnection connection) { - return connection.hGet(rawKey, rawHashKey); - } - }, true); - - return RedisTemplate.this. deserializeHashValue(rawHashValue); - } - - @Override - public Boolean hasKey(K key, Object hashKey) { - final byte[] rawKey = rawKey(key); - final byte[] rawHashKey = rawHashKey(hashKey); - - return execute(new RedisCallback() { - @Override - public Boolean doInRedis(RedisConnection connection) { - return connection.hExists(rawKey, rawHashKey); - } - }, true); - } - - @Override - public Long increment(K key, HK hashKey, final long delta) { - final byte[] rawKey = rawKey(key); - final byte[] rawHashKey = rawHashKey(hashKey); - - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.hIncrBy(rawKey, rawHashKey, delta); - } - }, true); - - } - - @SuppressWarnings("unchecked") - @Override - public Set keys(K key) { - final byte[] rawKey = rawKey(key); - - Set rawValues = execute(new RedisCallback>() { - @Override - public Set doInRedis(RedisConnection connection) { - return connection.hKeys(rawKey); - } - }, true); - - return (Set) deserializeHashKeys(rawValues, Set.class); - } - - @Override - public Long size(K key) { - final byte[] rawKey = rawKey(key); - - return execute(new RedisCallback() { - @Override - public Long doInRedis(RedisConnection connection) { - return connection.hLen(rawKey); - } - }, true); - } - - @Override - public void putAll(K key, Map m) { - if (m.isEmpty()) { - return; - } - - final byte[] rawKey = rawKey(key); - - final Map hashes = new LinkedHashMap(m.size()); - - for (Map.Entry entry : m.entrySet()) { - hashes.put(rawHashKey(entry.getKey()), rawHashValue(entry.getValue())); - } - - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.hMSet(rawKey, hashes); - return null; - } - }, true); - } - - - @SuppressWarnings("unchecked") - @Override - public Collection multiGet(K key, Collection fields) { - if (fields.isEmpty()) { - return Collections.emptyList(); - } - - final byte[] rawKey = rawKey(key); - - final byte[][] rawHashKeys = new byte[fields.size()][]; - - int counter = 0; - for (HK hashKey : fields) { - rawHashKeys[counter++] = rawHashKey(hashKey); - } - - List rawValues = execute(new RedisCallback>() { - @Override - public List doInRedis(RedisConnection connection) { - return connection.hMGet(rawKey, rawHashKeys); - } - }, true); - - return (List) deserializeHashValues(rawValues, List.class); - } - - @Override - 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() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.hSet(rawKey, rawHashKey, rawHashValue); - return null; - } - }, true); - } - - @Override - 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() { - @Override - public Boolean doInRedis(RedisConnection connection) { - return connection.hSetNX(rawKey, rawHashKey, rawHashValue); - } - }, true); - } - - - @SuppressWarnings("unchecked") - @Override - public List values(K key) { - final byte[] rawKey = rawKey(key); - - List rawValues = execute(new RedisCallback>() { - @Override - public List doInRedis(RedisConnection connection) { - return connection.hVals(rawKey); - } - }, true); - - return (List) deserializeHashValues(rawValues, List.class); - } - - @Override - public void delete(K key, Object hashKey) { - final byte[] rawKey = rawKey(key); - final byte[] rawHashKey = rawHashKey(hashKey); - - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.hDel(rawKey, rawHashKey); - return null; - } - }, true); - } - - @Override - public Map entries(K key) { - final byte[] rawKey = rawKey(key); - - Map entries = execute(new RedisCallback>() { - @Override - public Map doInRedis(RedisConnection connection) { - return connection.hGetAll(rawKey); - } - }, true); - - return deserializeHashMap(entries); - } - } - // Sort operations + @SuppressWarnings("unchecked") @Override public List sort(SortQuery query) { @@ -1938,7 +642,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @Override public List sort(SortQuery query, RedisSerializer resultSerializer) { final byte[] rawKey = rawKey(query.getKey()); - final SortParameters params = convertQuery(query, stringSerializer); + final SortParameters params = SerializationUtils.convertQuery(query, stringSerializer); List vals = execute(new RedisCallback>() { @Override @@ -1947,7 +651,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } }, true); - return (List) deserializeValues(vals, List.class, resultSerializer); + return (List) SerializationUtils.deserializeValues(vals, List.class, resultSerializer); } @SuppressWarnings("unchecked") @@ -1981,7 +685,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation public Long sort(SortQuery query, K storeKey) { final byte[] rawStoreKey = rawKey(storeKey); final byte[] rawKey = rawKey(query.getKey()); - final SortParameters params = convertQuery(query, stringSerializer); + final SortParameters params = SerializationUtils.convertQuery(query, stringSerializer); return execute(new RedisCallback() { @Override @@ -1991,24 +695,53 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - private static SortParameters convertQuery(SortQuery query, RedisSerializer stringSerializer) { - - return new DefaultSortParameters(stringSerializer.serialize(query.getBy()), query.getLimit(), serialize( - query.getGetPattern(), stringSerializer), query.getOrder(), query.isAlphabetic()); + @Override + public BoundValueOperations boundValueOps(K key) { + return new DefaultBoundValueOperations(key, this); } - private static byte[][] serialize(List strings, RedisSerializer stringSerializer) { - List raw = null; + @Override + public ValueOperations opsForValue() { + return valueOps; + } - if (strings == null) { - raw = Collections.emptyList(); - } - else { - raw = new ArrayList(strings.size()); - for (String key : strings) { - raw.add(stringSerializer.serialize(key)); - } - } - return raw.toArray(new byte[raw.size()][]); + @Override + public ListOperations opsForList() { + return listOps; + } + + @Override + public BoundListOperations boundListOps(K key) { + return new DefaultBoundListOperations(key, this); + } + + @Override + public BoundSetOperations boundSetOps(K key) { + return new DefaultBoundSetOperations(key, this); + } + + @Override + public SetOperations opsForSet() { + return setOps; + } + + @Override + public BoundZSetOperations boundZSetOps(K key) { + return new DefaultBoundZSetOperations(key, this); + } + + @Override + public ZSetOperations opsForZSet() { + return zSetOps; + } + + @Override + public BoundHashOperations boundHashOps(K key) { + return new DefaultBoundHashOperations(key, this); + } + + @Override + public HashOperations opsForHash() { + return new DefaultHashOperations(this); } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java new file mode 100644 index 000000000..0b70cfdd8 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java @@ -0,0 +1,80 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; + +import org.springframework.data.keyvalue.redis.connection.DefaultSortParameters; +import org.springframework.data.keyvalue.redis.connection.SortParameters; +import org.springframework.data.keyvalue.redis.core.query.SortQuery; +import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; + +/** + * Utility class with various serialization-related methods. + * + * @author Costin Leau + */ +public abstract class SerializationUtils { + + public static T deserialize(byte[] value, RedisSerializer serializer) { + if (isEmpty(value)) { + return null; + } + return serializer.deserialize(value); + } + + @SuppressWarnings("unchecked") + static > T deserializeValues(Collection rawValues, Class type, RedisSerializer redisSerializer) { + Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawValues.size()) + : new LinkedHashSet(rawValues.size())); + for (byte[] bs : rawValues) { + if (bs != null) { + values.add(redisSerializer.deserialize(bs)); + } + } + + return (T) values; + } + + public static boolean isEmpty(byte[] data) { + return (data == null || data.length == 0); + } + + public static SortParameters convertQuery(SortQuery query, RedisSerializer stringSerializer) { + + return new DefaultSortParameters(stringSerializer.serialize(query.getBy()), query.getLimit(), serialize( + query.getGetPattern(), stringSerializer), query.getOrder(), query.isAlphabetic()); + } + + public static byte[][] serialize(List strings, RedisSerializer stringSerializer) { + List raw = null; + + if (strings == null) { + raw = Collections.emptyList(); + } + else { + raw = new ArrayList(strings.size()); + for (String key : strings) { + raw.add(stringSerializer.serialize(key)); + } + } + return raw.toArray(new byte[raw.size()][]); + } +} \ No newline at end of file From 5f1c94c7dc7e8b3da90dac220bc1acb788e6b70e Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 14:32:05 +0200 Subject: [PATCH 05/68] DATAKV-38 + update RedisAtomicXXX classes with better init logic and javadocs --- .../support/atomic/RedisAtomicInteger.java | 34 +++++++++++------ .../redis/support/atomic/RedisAtomicLong.java | 37 ++++++++++++------- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index 16830923e..e178935b9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -48,16 +48,7 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound * @param factory connection factory */ public RedisAtomicInteger(String redisCounter, RedisConnectionFactory factory) { - RedisTemplate redisTemplate = new RedisTemplate(factory); - redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new GenericToStringSerializer(Integer.class)); - redisTemplate.setExposeConnection(true); - this.key = redisCounter; - this.generalOps = redisTemplate; - this.operations = generalOps.opsForValue(); - if (this.operations.get(redisCounter) == null) { - set(0); - } + this(redisCounter, factory, null); } /** @@ -68,12 +59,27 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound * @param initialValue */ public RedisAtomicInteger(String redisCounter, RedisConnectionFactory factory, int initialValue) { - RedisTemplate redisTemplate = new RedisTemplate(factory); + this(redisCounter, factory, Integer.valueOf(initialValue)); + } + + private RedisAtomicInteger(String redisCounter, RedisConnectionFactory factory, Integer initialValue) { + RedisTemplate redisTemplate = new RedisTemplate(); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new GenericToStringSerializer(Integer.class)); redisTemplate.setExposeConnection(true); + redisTemplate.setConnectionFactory(factory); + redisTemplate.afterPropertiesSet(); + this.key = redisCounter; this.generalOps = redisTemplate; this.operations = generalOps.opsForValue(); - this.operations.set(redisCounter, initialValue); + + if (initialValue == null && this.operations.get(redisCounter) == null) { + set(0); + } + else { + set(initialValue); + } } /** @@ -82,6 +88,8 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound * * Use {@link #RedisAtomicInteger(String, RedisOperations, int)} to set the counter to a certain value * as an alternative constructor or {@link #set(int)}. + * + * Note that integers need to be properly serialized so that Redis can recognized the values as numeric and thus modify their value. * * @param redisCounter * @param operations @@ -98,6 +106,8 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound /** * Constructs a new RedisAtomicInteger instance with the given initial value. * + * Note that integers need to be properly serialized so that Redis can recognized the values as numeric and thus modify their value. + * * @param redisCounter * @param operations * @param initialValue diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 10275074a..6d87a106a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -48,16 +48,7 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound redisTemplate = new RedisTemplate(factory); - redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new GenericToStringSerializer(Long.class)); - redisTemplate.setExposeConnection(true); - this.key = redisCounter; - this.generalOps = redisTemplate; - this.operations = generalOps.opsForValue(); - if (this.operations.get(redisCounter) == null) { - set(0); - } + this(redisCounter, factory, null); } /** @@ -68,21 +59,37 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound redisTemplate = new RedisTemplate(factory); + this(redisCounter, factory, Long.valueOf(initialValue)); + } + + private RedisAtomicLong(String redisCounter, RedisConnectionFactory factory, Long initialValue) { + RedisTemplate redisTemplate = new RedisTemplate(); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new GenericToStringSerializer(Long.class)); redisTemplate.setExposeConnection(true); + redisTemplate.setConnectionFactory(factory); + redisTemplate.afterPropertiesSet(); + this.key = redisCounter; this.generalOps = redisTemplate; this.operations = generalOps.opsForValue(); - this.operations.set(redisCounter, initialValue); - } + if (initialValue == null && this.operations.get(redisCounter) == null) { + set(0); + } + else { + set(initialValue); + } + } /** * Constructs a new RedisAtomicLong instance. Uses as initial value * the data from the backing store (sets the counter to 0 if no value is found). * * Use {@link #RedisAtomicLong(String, RedisOperations, long)} to set the counter to a certain value - * as an alternative constructor or {@link #set(long)}. + * as an alternative constructor or {@link #set(long)}. + * + * Note that longs need to be properly serialized so that Redis can recognized the values as numeric and thus modify their value. * * @param redisCounter * @param operations @@ -99,6 +106,8 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBoundRedisAtomicLong instance with the given initial value. * + * Note that longs need to be properly serialized so that Redis can recognized the values as numeric and thus modify their value. + * * @param redisCounter * @param operations * @param initialValue From 1145f6f069b0519ad308ef12cc071d80612cecb6 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 14:37:10 +0200 Subject: [PATCH 06/68] update poms --- pom.xml | 61 --------------------------------------------------------- 1 file changed, 61 deletions(-) diff --git a/pom.xml b/pom.xml index c074c8bb5..3026ac2d1 100644 --- a/pom.xml +++ b/pom.xml @@ -186,68 +186,7 @@ - maven-javadoc-plugin 2.7 From 03da0c150bbcda6798887c656238af8bb7251006 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 16:38:13 +0200 Subject: [PATCH 07/68] + remove unused internal class --- .../redis/support/atomic/CASUtils.java | 73 ------------------- 1 file changed, 73 deletions(-) delete mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/CASUtils.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/CASUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/CASUtils.java deleted file mode 100644 index 4ef4175fc..000000000 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/CASUtils.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.keyvalue.redis.support.atomic; - -import java.util.Collections; -import java.util.concurrent.Callable; - -import org.springframework.data.keyvalue.redis.core.RedisOperations; -import org.springframework.data.keyvalue.redis.core.SessionCallback; - -/** - * Check-And-Set (CAS) utility. Performs the CAS loop until successful pattern using - * Redis watch/exec operations. - * - * The given callback can contain one or multiple reads followed by a multi call - * and one or multiple writes: - * - *
- * return CASUtils.execute(ops, key, new Callable() {
- *  @Override
- *  public Integer call() throws Exception {
- *    // check
- *    int value = get();
- *    // start MULTI
- *    ops.multi();
- *    // set
- *    ops.increment(key, 1);
- *    return value;
- *  }
- * });
- * 
- * - * @author Costin Leau - */ -abstract class CASUtils { - - public static T execute(final RedisOperations ops, final K key, final Callable callback) { - return ops.execute(new SessionCallback() { - @SuppressWarnings("unchecked") - @Override - public T execute(RedisOperations operations) { - try { - for (;;) { - operations.watch(Collections.singleton(key)); - T result = callback.call(); - if (operations.exec() != null) { - return result; - } - } - } catch (Exception ex) { - // includes DataAccessException - if (ex instanceof RuntimeException) { - throw (RuntimeException) ex; - } - throw new RuntimeException("Callback threw exception", ex); - } - } - }); - } -} \ No newline at end of file From f3dfe2e2bbe32cd953ff47c98b3b47fa17ec1696 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 18:28:42 +0200 Subject: [PATCH 08/68] DATAKV-38 + fix potential NPE on init --- .../data/keyvalue/redis/support/atomic/RedisAtomicInteger.java | 2 +- .../data/keyvalue/redis/support/atomic/RedisAtomicLong.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index e178935b9..bc69f1505 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -74,7 +74,7 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound this.generalOps = redisTemplate; this.operations = generalOps.opsForValue(); - if (initialValue == null && this.operations.get(redisCounter) == null) { + if (initialValue == null || this.operations.get(redisCounter) == null) { set(0); } else { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 6d87a106a..7fc319b57 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -74,7 +74,7 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound Date: Mon, 14 Mar 2011 23:02:15 +0200 Subject: [PATCH 09/68] DATAKV-41 + allow indexes higher then 16 --- .../keyvalue/redis/connection/jedis/JedisConnectionFactory.java | 2 +- .../redis/connection/jredis/JredisConnectionFactory.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java index c5e01ab7a..099067bbd 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java @@ -287,7 +287,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, * @param index database index */ public void setDatabase(int index) { - Assert.isTrue(index >= 0 && index < 16, "invalid DB index (needs to be between 0 and 15)"); + Assert.isTrue(index >= 0, "invalid DB index (a positive index required)"); this.dbIndex = index; } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java index b833e78da..87ae5c1a5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java @@ -231,7 +231,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean * @param index database index */ public void setDatabase(int index) { - Assert.isTrue(index >= 0 && index < 16, "invalid DB index (needs to be between 0 and 15)"); + Assert.isTrue(index >= 0, "invalid DB index (a positive index required)"); this.dbIndex = index; } } \ No newline at end of file From 8bb5f424922ae399419b35b68b535804e00ae4e0 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 14 Mar 2011 23:07:04 +0200 Subject: [PATCH 10/68] DATAKV-42 + ValueOperation.multiGet returns a list (instead of collection) --- .../data/keyvalue/redis/core/DefaultValueOperations.java | 2 +- .../data/keyvalue/redis/core/ValueOperations.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java index 73bf9a8c9..9738da7bf 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java @@ -111,7 +111,7 @@ class DefaultValueOperations extends AbstractOperations implements V @SuppressWarnings("unchecked") @Override - public Collection multiGet(Collection keys) { + public List multiGet(Collection keys) { if (keys.isEmpty()) { return Collections.emptyList(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java index 32b2a9622..3fd581ad0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java @@ -16,6 +16,7 @@ package org.springframework.data.keyvalue.redis.core; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -40,7 +41,7 @@ public interface ValueOperations { V getAndSet(K key, V value); - Collection multiGet(Collection keys); + List multiGet(Collection keys); Long increment(K key, long delta); From 503f949337d5192c85ecd550e00260674e01353a Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 12:40:16 +0200 Subject: [PATCH 11/68] DATAKV-34 + improve serialization/deserialization contract of null values + null values are properly preserved on return + disabled some JRedis tests as nulls seem to affect the underlying connection --- .../DefaultStringRedisConnection.java | 2 +- .../redis/core/SerializationUtils.java | 11 +-------- .../redis/core/StringRedisTemplate.java | 9 +++---- .../serializer/GenericToStringSerializer.java | 7 ++++++ .../JacksonJsonRedisSerializer.java | 2 ++ .../JdkSerializationRedisSerializer.java | 7 ++++++ .../redis/serializer/OxmSerializer.java | 2 +- .../redis/serializer/RedisSerializer.java | 1 + .../serializer/StringRedisSerializer.java | 8 +++---- .../AbstractConnectionIntegrationTests.java | 24 ++++++++++++++++++- .../JedisConnectionIntegrationTests.java | 1 - .../JRedisConnectionIntegrationTests.java | 23 +++++++++++++++++- 12 files changed, 71 insertions(+), 26 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index c30385625..caeb8bbf6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -576,7 +576,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { byte[][] ret = new byte[keys.length][]; for (int i = 0; i < ret.length; i++) { - byte[] bs = serializer.serialize(keys[i]); + ret[i] = serializer.serialize(keys[i]); } return ret; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java index 0b70cfdd8..7ae9e0770 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java @@ -34,9 +34,6 @@ import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; public abstract class SerializationUtils { public static T deserialize(byte[] value, RedisSerializer serializer) { - if (isEmpty(value)) { - return null; - } return serializer.deserialize(value); } @@ -45,18 +42,12 @@ public abstract class SerializationUtils { Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawValues.size()) : new LinkedHashSet(rawValues.size())); for (byte[] bs : rawValues) { - if (bs != null) { - values.add(redisSerializer.deserialize(bs)); - } + values.add(redisSerializer.deserialize(bs)); } return (T) values; } - public static boolean isEmpty(byte[] data) { - return (data == null || data.length == 0); - } - public static SortParameters convertQuery(SortQuery query, RedisSerializer stringSerializer) { return new DefaultSortParameters(stringSerializer.serialize(query.getBy()), query.getLimit(), serialize( diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/StringRedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/StringRedisTemplate.java index 6a364b51f..90b22c2d0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/StringRedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/StringRedisTemplate.java @@ -51,12 +51,9 @@ public class StringRedisTemplate extends RedisTemplate { * @param connectionFactory connection factory for creating new connections */ public StringRedisTemplate(RedisConnectionFactory connectionFactory) { - super(connectionFactory); - RedisSerializer stringSerializer = new StringRedisSerializer(); - setKeySerializer(stringSerializer); - setValueSerializer(stringSerializer); - setHashKeySerializer(stringSerializer); - setHashValueSerializer(stringSerializer); + this(); + setConnectionFactory(connectionFactory); + afterPropertiesSet(); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java index 2da22f808..b53387366 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java @@ -66,12 +66,19 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac @Override public T deserialize(byte[] bytes) { + if (bytes == null) { + return null; + } + String string = new String(bytes, charset); return converter.convert(string, type); } @Override public byte[] serialize(T object) { + if (object == null) { + return null; + } String string = converter.convert(object, String.class); return string.getBytes(charset); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java index bf9adaf64..afaba2ec4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java @@ -26,6 +26,8 @@ import org.springframework.util.Assert; * {@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 */ diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java index 202c9203d..c70fe3f08 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java @@ -34,6 +34,10 @@ public class JdkSerializationRedisSerializer implements RedisSerializer @SuppressWarnings("unchecked") @Override public Object deserialize(byte[] bytes) { + if (SerializerUtils.isEmpty(bytes)) { + return null; + } + try { return deserializer.convert(bytes); } catch (Exception ex) { @@ -43,6 +47,9 @@ public class JdkSerializationRedisSerializer implements RedisSerializer @Override public byte[] serialize(Object object) { + if (object == null) { + return SerializerUtils.EMPTY_ARRAY; + } try { return serializer.convert(object); } catch (Exception ex) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java index 596e22f87..7ba182645 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java @@ -31,7 +31,7 @@ import org.springframework.util.Assert; * Delegates serialization/deserialization to OXM {@link Marshaller} and * {@link Unmarshaller}. * - * Note:Null objects are serialized as empty arrays. + * Note:Null objects are serialized as empty arrays and vice versa. * * @author Costin Leau */ diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/RedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/RedisSerializer.java index 910a4333c..18543c579 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/RedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/RedisSerializer.java @@ -19,6 +19,7 @@ package org.springframework.data.keyvalue.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). * * @author Mark Pollack * @author Costin Leau diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java index dbb0f8b3e..d0b361ba1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java @@ -25,14 +25,12 @@ import org.springframework.util.Assert; *

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

Converts null into empty arrays (which get translated into empty strings on deserialization). + *

Does not perform any null conversion since empty strings are valid keys/values. * * @author Costin Leau */ public class StringRedisSerializer implements RedisSerializer { - private final static byte[] EMPTY_ARRAY = new byte[0]; - private final String EMPTY_STRING = ""; private final Charset charset; public StringRedisSerializer() { @@ -46,11 +44,11 @@ public class StringRedisSerializer implements RedisSerializer { @Override public String deserialize(byte[] bytes) { - return (SerializerUtils.isEmpty(bytes) ? EMPTY_STRING : new String(bytes, charset)); + return (bytes == null ? null : new String(bytes, charset)); } @Override public byte[] serialize(String string) { - return (string == null ? EMPTY_ARRAY : string.getBytes(charset)); + return (string == null ? null : string.getBytes(charset)); } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index 95ee8ec75..141b758c2 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -18,6 +18,8 @@ package org.springframework.data.keyvalue.redis.connection; import static org.junit.Assert.*; +import java.util.Arrays; +import java.util.List; import java.util.Properties; import java.util.UUID; @@ -27,6 +29,7 @@ import org.junit.Test; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.redis.Address; import org.springframework.data.keyvalue.redis.Person; +import org.springframework.data.keyvalue.redis.core.StringRedisTemplate; import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; @@ -102,8 +105,12 @@ public abstract class AbstractConnectionIntegrationTests { @Test public void testNullKey() throws Exception { - connection.decr((String) null); connection.decr(EMPTY_ARRAY); + try { + connection.decr((String) null); + } catch (Exception ex) { + // excepted + } } @Test @@ -140,4 +147,19 @@ public abstract class AbstractConnectionIntegrationTests { // expected } } + + @Test + public void testNullSerialization() throws Exception { + String[] keys = new String[] { "~", "[" }; + List mGet = connection.mGet(keys); + assertEquals(2, mGet.size()); + assertNull(mGet.get(0)); + assertNull(mGet.get(1)); + + StringRedisTemplate stringTemplate = new StringRedisTemplate(getConnectionFactory()); + List multiGet = stringTemplate.opsForValue().multiGet(Arrays.asList(keys)); + assertEquals(2, multiGet.size()); + assertNull(multiGet.get(0)); + assertNull(multiGet.get(1)); + } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionIntegrationTests.java index 8ff75a8a0..75a9e7e87 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionIntegrationTests.java @@ -58,7 +58,6 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati public void onMessage(Message message, byte[] pattern) { assertArrayEquals(expectedChannel, message.getChannel()); assertArrayEquals(expectedMessage, message.getBody()); - System.out.println("Received message '" + new String(message.getBody()) + "'"); } }; diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java index 91263aabd..c71dbe63b 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -17,6 +17,7 @@ package org.springframework.data.keyvalue.redis.connection.jredis; import org.jredis.JRedis; +import org.junit.Ignore; import org.junit.Test; import org.springframework.data.keyvalue.redis.SettingsUtils; import org.springframework.data.keyvalue.redis.connection.AbstractConnectionIntegrationTests; @@ -43,10 +44,30 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat @Test public void testRaw() throws Exception { JRedis jr = (JRedis) factory.getConnection().getNativeConnection(); - + System.out.println(jr.dbsize()); System.out.println(jr.exists("foobar")); jr.set("foobar", "barfoo"); System.out.println(jr.get("foobar")); } + + @Ignore("JRedis has connecting issues with null") + public void testNullSerialization() { + } + + @Ignore("JRedis has connecting issues with null") + public void testHashNullValue() { + } + + @Ignore("JRedis has connecting issues with null") + public void testHashNullKey() { + } + + @Ignore("JRedis has connecting issues with null") + public void testNullValue() { + } + + @Ignore("JRedis has connecting issues with null") + public void testNullKey() { + } } From e68430101d476c575b691f40cc760da903698eeb Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 13:04:13 +0200 Subject: [PATCH 12/68] DATAKV-34 + improve handling of collections during pipeline/multi operations --- .../connection/DefaultStringRedisConnection.java | 11 +++++++++++ .../data/keyvalue/redis/core/AbstractOperations.java | 5 +++++ .../data/keyvalue/redis/core/SerializationUtils.java | 5 +++++ .../AbstractConnectionIntegrationTests.java | 8 ++++++++ .../jredis/JRedisConnectionIntegrationTests.java | 4 ++++ 5 files changed, 33 insertions(+) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index caeb8bbf6..b4e75fcb7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -594,6 +594,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection { private List deserialize(Collection data) { + if (data == null) { + return null; + } + List result = new ArrayList(data.size()); for (byte[] raw : data) { result.add(serializer.deserialize(raw)); @@ -602,6 +606,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } private Set deserialize(Set data) { + if (data == null) { + return null; + } + Set result = new LinkedHashSet(data.size()); for (byte[] raw : data) { result.add(serializer.deserialize(raw)); @@ -614,6 +622,9 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } private Set deserializeTuple(Set data) { + if (data == null) { + return null; + } Set result = new LinkedHashSet(data.size()); for (Tuple raw : data) { result.add(new DefaultStringTuple(raw, serializer.deserialize(raw.getValue()))); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java index 49c767178..d7073e811 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java @@ -146,6 +146,11 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") Map deserializeHashMap(Map entries) { + // connection in pipeline/multi mode + if (entries == null) { + return null; + } + Map map = new LinkedHashMap(entries.size()); for (Map.Entry entry : entries.entrySet()) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java index 7ae9e0770..13ec8e4e1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java @@ -39,6 +39,11 @@ public abstract class SerializationUtils { @SuppressWarnings("unchecked") static > T deserializeValues(Collection rawValues, Class type, RedisSerializer redisSerializer) { + // connection in pipeline/multi mode + if (rawValues == null) { + return null; + } + Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawValues.size()) : new LinkedHashSet(rawValues.size())); for (byte[] bs : rawValues) { diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index 141b758c2..3d5612923 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -162,4 +162,12 @@ public abstract class AbstractConnectionIntegrationTests { assertNull(multiGet.get(0)); assertNull(multiGet.get(1)); } + + @Test + public void testNullCollections() throws Exception { + connection.openPipeline(); + assertNull(connection.keys("~*")); + assertNull(connection.hKeys("~")); + connection.closePipeline(); + } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java index c71dbe63b..4a828dcc8 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -70,4 +70,8 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat @Ignore("JRedis has connecting issues with null") public void testNullKey() { } + + @Ignore("JRedis does not support pipelining") + public void testNullCollections() { + } } From 99ca11069669b00af5f8e3db293abd299d0b3c7a Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 15:00:02 +0200 Subject: [PATCH 13/68] + arranged internal code better with respect to serialization util methods + fix annoying connection leakage in old integration test --- .../DefaultStringRedisConnection.java | 26 ++----- .../redis/connection/RedisCommands.java | 4 +- .../connection/jedis/JedisConnection.java | 3 +- .../connection/jredis/JredisConnection.java | 3 +- .../redis/connection/jredis/JredisUtils.java | 12 ++-- .../redis/core/AbstractOperations.java | 30 ++++---- .../redis/core/DefaultListOperations.java | 2 +- .../redis/core/DefaultSetOperations.java | 8 +-- .../redis/core/DefaultValueOperations.java | 2 +- .../redis/core/DefaultZSetOperations.java | 6 +- .../keyvalue/redis/core/RedisTemplate.java | 13 ++-- .../QueryUtils.java} | 33 ++------- .../adapter/MessageListenerAdapter.java | 4 +- .../JacksonJsonRedisSerializer.java | 4 +- .../JdkSerializationRedisSerializer.java | 4 +- .../redis/serializer/OxmSerializer.java | 4 +- .../redis/serializer/SerializationUtils.java | 68 +++++++++++++++++++ .../redis/serializer/SerializerUtils.java | 29 -------- .../AbstractConnectionIntegrationTests.java | 24 ++++++- .../JRedisConnectionIntegrationTests.java | 20 ------ .../listener/adapter/MessageListenerTest.java | 9 ++- .../collections/AbstractRedisZSetTest.java | 2 +- 22 files changed, 157 insertions(+), 153 deletions(-) rename spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/{SerializationUtils.java => query/QueryUtils.java} (60%) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializationUtils.java delete mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializerUtils.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index b4e75fcb7..3d857e3df 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -15,7 +15,6 @@ */ package org.springframework.data.keyvalue.redis.connection; -import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -26,6 +25,7 @@ import java.util.Set; import org.springframework.data.keyvalue.redis.UncategorizedRedisException; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; +import org.springframework.data.keyvalue.redis.serializer.SerializationUtils; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; import org.springframework.util.Assert; @@ -240,7 +240,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.isSubscribed(); } - public Collection keys(byte[] pattern) { + public Set keys(byte[] pattern) { return delegate.keys(pattern); } @@ -593,28 +593,12 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } - private List deserialize(Collection data) { - if (data == null) { - return null; - } - - List result = new ArrayList(data.size()); - for (byte[] raw : data) { - result.add(serializer.deserialize(raw)); - } - return result; + private List deserialize(List data) { + return SerializationUtils.deserialize(data, serializer); } private Set deserialize(Set data) { - if (data == null) { - return null; - } - - Set result = new LinkedHashSet(data.size()); - for (byte[] raw : data) { - result.add(serializer.deserialize(raw)); - } - return result; + return SerializationUtils.deserialize(data, serializer); } private String deserialize(byte[] data) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java index 31a989954..61a7d9a80 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java @@ -16,8 +16,8 @@ package org.springframework.data.keyvalue.redis.connection; -import java.util.Collection; import java.util.List; +import java.util.Set; /** * Interface for the commands supported by Redis. @@ -33,7 +33,7 @@ public interface RedisCommands extends RedisTxCommands, RedisStringCommands, Red DataType type(byte[] key); - Collection keys(byte[] pattern); + Set keys(byte[] pattern); byte[] randomKey(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index f1e6eebf6..d3f898769 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -18,7 +18,6 @@ package org.springframework.data.keyvalue.redis.connection.jedis; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -577,7 +576,7 @@ public class JedisConnection implements RedisConnection { } @Override - public Collection keys(byte[] pattern) { + public Set keys(byte[] pattern) { try { if (isQueueing()) { transaction.keys(pattern); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index bbdb1e18c..dca7e829d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -16,7 +16,6 @@ package org.springframework.data.keyvalue.redis.connection.jredis; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; @@ -300,7 +299,7 @@ public class JredisConnection implements RedisConnection { } @Override - public Collection keys(byte[] pattern) { + public Set keys(byte[] pattern) { try { return JredisUtils.convertCollection(jredis.keys(JredisUtils.decode(pattern))); } catch (Exception ex) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java index a41bd982a..7820186db 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java @@ -16,11 +16,12 @@ package org.springframework.data.keyvalue.redis.connection.jredis; -import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Properties; +import java.util.Set; import org.jredis.ClientRuntimeException; import org.jredis.RedisException; @@ -104,16 +105,15 @@ public abstract class JredisUtils { return result; } - static Collection convertCollection(Collection keys) { - Collection list = new ArrayList(keys.size()); + static Set convertCollection(Collection keys) { + Set set = new LinkedHashSet(keys.size()); for (String string : keys) { - list.add(Base64.decode(string)); + set.add(Base64.decode(string)); } - return list; + return set; } - static Map decodeMap(Map tuple) { Map result = new LinkedHashMap(tuple.size()); for (Map.Entry entry : tuple.entrySet()) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java index d7073e811..ccaeedfe4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java @@ -23,6 +23,7 @@ import java.util.Set; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; +import org.springframework.data.keyvalue.redis.serializer.SerializationUtils; import org.springframework.util.Assert; /** @@ -130,18 +131,24 @@ abstract class AbstractOperations { return rawKeys; } - > T deserializeValues(Collection rawValues, Class type) { - return SerializationUtils.deserializeValues(rawValues, type, valueSerializer); + @SuppressWarnings("unchecked") + Set deserializeValues(Set rawValues) { + return SerializationUtils.deserialize(rawValues, valueSerializer); } @SuppressWarnings("unchecked") - Set deserializeHashKeys(Collection rawKeys) { - return SerializationUtils.deserializeValues(rawKeys, Set.class, hashKeySerializer); + List deserializeValues(List rawValues) { + return SerializationUtils.deserialize(rawValues, valueSerializer); } @SuppressWarnings("unchecked") - List deserializeHashValues(Collection rawValues) { - return SerializationUtils.deserializeValues(rawValues, List.class, hashValueSerializer); + Set deserializeHashKeys(Set rawKeys) { + return SerializationUtils.deserialize(rawKeys, hashKeySerializer); + } + + @SuppressWarnings("unchecked") + List deserializeHashValues(List rawValues) { + return SerializationUtils.deserialize(rawValues, hashValueSerializer); } @SuppressWarnings("unchecked") @@ -162,26 +169,25 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") K deserializeKey(byte[] value) { - return (K) SerializationUtils.deserialize(value, keySerializer); + return (K) keySerializer.deserialize(value); } @SuppressWarnings("unchecked") V deserializeValue(byte[] value) { - return (V) SerializationUtils.deserialize(value, valueSerializer); + return (V) valueSerializer.deserialize(value); } - @SuppressWarnings("unchecked") String deserializeString(byte[] value) { - return (String) SerializationUtils.deserialize(value, stringSerializer); + return (String) stringSerializer.deserialize(value); } @SuppressWarnings( { "unchecked" }) HK deserializeHashKey(byte[] value) { - return (HK) SerializationUtils.deserialize(value, hashKeySerializer); + return (HK) hashKeySerializer.deserialize(value); } @SuppressWarnings("unchecked") HV deserializeHashValue(byte[] value) { - return (HV) SerializationUtils.deserialize(value, hashValueSerializer); + return (HV) hashValueSerializer.deserialize(value); } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java index 3ea644d2a..b6c67936f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java @@ -119,7 +119,7 @@ class DefaultListOperations extends AbstractOperations implements Li @SuppressWarnings("unchecked") @Override public List doInRedis(RedisConnection connection) { - return deserializeValues(connection.lRange(rawKey, start, end), List.class); + return deserializeValues(connection.lRange(rawKey, start, end)); } }, true); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java index 7ebce6f32..a4893104f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java @@ -60,7 +60,7 @@ class DefaultSetOperations extends AbstractOperations implements Set } }, true); - return deserializeValues(rawValues, Set.class); + return deserializeValues(rawValues); } @Override @@ -97,7 +97,7 @@ class DefaultSetOperations extends AbstractOperations implements Set } }, true); - return deserializeValues(rawValues, Set.class); + return deserializeValues(rawValues); } @Override @@ -141,7 +141,7 @@ class DefaultSetOperations extends AbstractOperations implements Set } }, true); - return deserializeValues(rawValues, Set.class); + return deserializeValues(rawValues); } @Override @@ -218,7 +218,7 @@ class DefaultSetOperations extends AbstractOperations implements Set } }, true); - return deserializeValues(rawValues, Set.class); + return deserializeValues(rawValues); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java index 9738da7bf..37172140a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java @@ -130,7 +130,7 @@ class DefaultValueOperations extends AbstractOperations implements V } }, true); - return deserializeValues(rawValues, List.class); + return deserializeValues(rawValues); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java index 03a785029..154163fe7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java @@ -88,7 +88,7 @@ class DefaultZSetOperations extends AbstractOperations implements ZS } }, true); - return deserializeValues(rawValues, Set.class); + return deserializeValues(rawValues); } @SuppressWarnings("unchecked") @@ -103,7 +103,7 @@ class DefaultZSetOperations extends AbstractOperations implements ZS } }, true); - return deserializeValues(rawValues, Set.class); + return deserializeValues(rawValues); } @Override @@ -183,7 +183,7 @@ class DefaultZSetOperations extends AbstractOperations implements ZS } }, true); - return deserializeValues(rawValues, Set.class); + return deserializeValues(rawValues); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index e16cf1291..5b4442dcd 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -29,9 +29,11 @@ import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.data.keyvalue.redis.connection.SortParameters; +import org.springframework.data.keyvalue.redis.core.query.QueryUtils; import org.springframework.data.keyvalue.redis.core.query.SortQuery; import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; +import org.springframework.data.keyvalue.redis.serializer.SerializationUtils; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -377,7 +379,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @SuppressWarnings("unchecked") private K deserializeKey(byte[] value) { - return (K) SerializationUtils.deserialize(value, keySerializer); + return (K) keySerializer.deserialize(value); } // @@ -503,7 +505,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } }, true); - return (Set) SerializationUtils.deserializeValues(rawKeys, Set.class, keySerializer); + return (Set) SerializationUtils.deserialize(rawKeys, keySerializer); } @Override @@ -638,11 +640,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return sort(query, valueSerializer); } - @SuppressWarnings("unchecked") @Override public List sort(SortQuery query, RedisSerializer resultSerializer) { final byte[] rawKey = rawKey(query.getKey()); - final SortParameters params = SerializationUtils.convertQuery(query, stringSerializer); + final SortParameters params = QueryUtils.convertQuery(query, stringSerializer); List vals = execute(new RedisCallback>() { @Override @@ -651,7 +652,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } }, true); - return (List) SerializationUtils.deserializeValues(vals, List.class, resultSerializer); + return SerializationUtils.deserialize(vals, resultSerializer); } @SuppressWarnings("unchecked") @@ -685,7 +686,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation public Long sort(SortQuery query, K storeKey) { final byte[] rawStoreKey = rawKey(storeKey); final byte[] rawKey = rawKey(query.getKey()); - final SortParameters params = SerializationUtils.convertQuery(query, stringSerializer); + final SortParameters params = QueryUtils.convertQuery(query, stringSerializer); return execute(new RedisCallback() { @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/QueryUtils.java similarity index 60% rename from spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java rename to spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/QueryUtils.java index 13ec8e4e1..a8b08ee42 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SerializationUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/QueryUtils.java @@ -13,45 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.keyvalue.redis.core; +package org.springframework.data.keyvalue.redis.core.query; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; import org.springframework.data.keyvalue.redis.connection.DefaultSortParameters; import org.springframework.data.keyvalue.redis.connection.SortParameters; -import org.springframework.data.keyvalue.redis.core.query.SortQuery; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; /** - * Utility class with various serialization-related methods. + * Utilities for {@link SortQuery} implementations. * * @author Costin Leau */ -public abstract class SerializationUtils { - - public static T deserialize(byte[] value, RedisSerializer serializer) { - return serializer.deserialize(value); - } - - @SuppressWarnings("unchecked") - static > T deserializeValues(Collection rawValues, Class type, RedisSerializer redisSerializer) { - // connection in pipeline/multi mode - if (rawValues == null) { - return null; - } - - Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawValues.size()) - : new LinkedHashSet(rawValues.size())); - for (byte[] bs : rawValues) { - values.add(redisSerializer.deserialize(bs)); - } - - return (T) values; - } +public abstract class QueryUtils { public static SortParameters convertQuery(SortQuery query, RedisSerializer stringSerializer) { @@ -59,7 +36,7 @@ public abstract class SerializationUtils { query.getGetPattern(), stringSerializer), query.getOrder(), query.isAlphabetic()); } - public static byte[][] serialize(List strings, RedisSerializer stringSerializer) { + private static byte[][] serialize(List strings, RedisSerializer stringSerializer) { List raw = null; if (strings == null) { @@ -73,4 +50,4 @@ public abstract class SerializationUtils { } return raw.toArray(new byte[raw.size()][]); } -} \ No newline at end of file +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java index 035bb0473..6affa0dc3 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java @@ -15,7 +15,6 @@ */ package org.springframework.data.keyvalue.redis.listener.adapter; -import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import org.apache.commons.logging.Log; @@ -152,8 +151,7 @@ public class MessageListenerAdapter implements MessageListener { /** * Set the serializer that will convert incoming raw Redis messages to * listener method arguments. - *

The default converter is a {@link JdkSerializationRedisSerializer}, which is able - * to handle {@link Serializable} objects. + *

The default converter is a {@link StringRedisSerializer}. */ public void setSerializer(RedisSerializer serializer) { this.serializer = serializer; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java index afaba2ec4..c858cfcb2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java @@ -46,7 +46,7 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { @SuppressWarnings("unchecked") @Override public T deserialize(byte[] bytes) throws SerializationException { - if (SerializerUtils.isEmpty(bytes)) { + if (SerializationUtils.isEmpty(bytes)) { return null; } try { @@ -59,7 +59,7 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { @Override public byte[] serialize(Object t) throws SerializationException { if (t == null) { - return SerializerUtils.EMPTY_ARRAY; + return SerializationUtils.EMPTY_ARRAY; } try { return this.objectMapper.writeValueAsBytes(t); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java index c70fe3f08..fe6de7886 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java @@ -34,7 +34,7 @@ public class JdkSerializationRedisSerializer implements RedisSerializer @SuppressWarnings("unchecked") @Override public Object deserialize(byte[] bytes) { - if (SerializerUtils.isEmpty(bytes)) { + if (SerializationUtils.isEmpty(bytes)) { return null; } @@ -48,7 +48,7 @@ public class JdkSerializationRedisSerializer implements RedisSerializer @Override public byte[] serialize(Object object) { if (object == null) { - return SerializerUtils.EMPTY_ARRAY; + return SerializationUtils.EMPTY_ARRAY; } try { return serializer.convert(object); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java index 7ba182645..b1a2354f8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java @@ -72,7 +72,7 @@ public class OxmSerializer implements InitializingBean, RedisSerializer @Override public Object deserialize(byte[] bytes) throws SerializationException { - if (SerializerUtils.isEmpty(bytes)) { + if (SerializationUtils.isEmpty(bytes)) { return null; } @@ -86,7 +86,7 @@ public class OxmSerializer implements InitializingBean, RedisSerializer @Override public byte[] serialize(Object t) throws SerializationException { if (t == null) { - return SerializerUtils.EMPTY_ARRAY; + return SerializationUtils.EMPTY_ARRAY; } ByteArrayOutputStream stream = new ByteArrayOutputStream(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializationUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializationUtils.java new file mode 100644 index 000000000..fab0120d8 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializationUtils.java @@ -0,0 +1,68 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.serializer; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +/** + * Utility class with various serialization-related methods. + * + * @author Costin Leau + */ +public abstract class SerializationUtils { + + static final byte[] EMPTY_ARRAY = new byte[0]; + + static boolean isEmpty(byte[] data) { + return (data == null || data.length == 0); + } + + + @SuppressWarnings("unchecked") + static > T deserializeValues(Collection rawValues, Class type, RedisSerializer redisSerializer) { + // connection in pipeline/multi mode + if (rawValues == null) { + return null; + } + + Collection values = (List.class.isAssignableFrom(type) ? new ArrayList(rawValues.size()) + : new LinkedHashSet(rawValues.size())); + for (byte[] bs : rawValues) { + values.add(redisSerializer.deserialize(bs)); + } + + return (T) values; + } + + @SuppressWarnings("unchecked") + public static Set deserialize(Set rawValues, RedisSerializer redisSerializer) { + return deserializeValues(rawValues, Set.class, redisSerializer); + } + + @SuppressWarnings("unchecked") + public static List deserialize(List rawValues, RedisSerializer redisSerializer) { + return deserializeValues(rawValues, List.class, redisSerializer); + } + + @SuppressWarnings("unchecked") + public static Collection deserialize(Collection rawValues, RedisSerializer redisSerializer) { + return deserializeValues(rawValues, List.class, redisSerializer); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializerUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializerUtils.java deleted file mode 100644 index aee3832b6..000000000 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializerUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.keyvalue.redis.serializer; - -/** - * Minimal class used for sharing pieces of code between the serializers - * - * @author Costin Leau - */ -abstract class SerializerUtils { - static final byte[] EMPTY_ARRAY = new byte[0]; - - static boolean isEmpty(byte[] data) { - return (data == null || data.length == 0); - } -} diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index 3d5612923..d26002762 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -19,13 +19,17 @@ package org.springframework.data.keyvalue.redis.connection; import static org.junit.Assert.*; import java.util.Arrays; +import java.util.LinkedHashSet; import java.util.List; import java.util.Properties; +import java.util.Set; import java.util.UUID; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; +import org.springframework.beans.factory.DisposableBean; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.redis.Address; import org.springframework.data.keyvalue.redis.Person; @@ -43,12 +47,30 @@ public abstract class AbstractConnectionIntegrationTests { private static final String listName = "test-list"; private static final byte[] EMPTY_ARRAY = new byte[0]; + protected abstract RedisConnectionFactory getConnectionFactory(); + + private static Set connFactories = new LinkedHashSet(); + @Before public void setUp() { connection = new DefaultStringRedisConnection(getConnectionFactory().getConnection()); + connFactories.add(getConnectionFactory()); + + } + + @AfterClass + public static void cleanUp() { + if (connFactories != null) { + for (RedisConnectionFactory connectionFactory : connFactories) { + try { + ((DisposableBean) connectionFactory).destroy(); + } catch (Exception ex) { + System.err.println("Cannot clean factory " + connectionFactory + ex); + } + } + } } - protected abstract RedisConnectionFactory getConnectionFactory(); @After public void tearDown() { diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java index 4a828dcc8..09e1c91d8 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -51,26 +51,6 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat System.out.println(jr.get("foobar")); } - @Ignore("JRedis has connecting issues with null") - public void testNullSerialization() { - } - - @Ignore("JRedis has connecting issues with null") - public void testHashNullValue() { - } - - @Ignore("JRedis has connecting issues with null") - public void testHashNullKey() { - } - - @Ignore("JRedis has connecting issues with null") - public void testNullValue() { - } - - @Ignore("JRedis has connecting issues with null") - public void testNullKey() { - } - @Ignore("JRedis does not support pipelining") public void testNullCollections() { } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerTest.java index 05c46bbec..f8fcdd49c 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerTest.java @@ -25,8 +25,8 @@ import org.mockito.MockitoAnnotations; import org.springframework.data.keyvalue.redis.connection.DefaultMessage; import org.springframework.data.keyvalue.redis.connection.Message; import org.springframework.data.keyvalue.redis.connection.MessageListener; -import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; +import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; /** * Unit test for MessageListenerAdapter. @@ -35,16 +35,16 @@ import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; */ public class MessageListenerTest { - private static final RedisSerializer serializer = new JdkSerializationRedisSerializer(); + private static final RedisSerializer serializer = new StringRedisSerializer(); private static final String CHANNEL = "some::test:"; private static final byte[] RAW_CHANNEL = serializer.serialize(CHANNEL); private static final String PAYLOAD = "do re mi"; private static final byte[] RAW_PAYLOAD = serializer.serialize(PAYLOAD); - private static final Message STRING_MSG = new DefaultMessage(RAW_PAYLOAD, RAW_CHANNEL); + private static final Message STRING_MSG = new DefaultMessage(RAW_CHANNEL, RAW_PAYLOAD); private MessageListenerAdapter adapter; - interface Delegate { + public static interface Delegate { void handleMessage(String argument); void customMethod(String arg); @@ -76,7 +76,6 @@ public class MessageListenerTest { MessageListenerAdapter adapter = new MessageListenerAdapter(mock); adapter.onMessage(STRING_MSG, null); - verify(mock).onMessage(STRING_MSG, null); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisZSetTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisZSetTest.java index 9aae0fde4..6a96f001c 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisZSetTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisZSetTest.java @@ -141,7 +141,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertEquals(Long.valueOf(0), zSet.rank(t1)); assertEquals(Long.valueOf(1), zSet.rank(t2)); assertEquals(Long.valueOf(2), zSet.rank(t3)); - System.out.println(zSet.rank(getT())); + assertNull(zSet.rank(getT())); //assertNull(); } From a1bdf1b06363a2628c3191bc9c51f4b926f73990 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 18:00:36 +0200 Subject: [PATCH 14/68] DATAKV-43 + introduce support for RW pipelined callbacks (in addition to the WO support) --- .../keyvalue/redis/core/RedisOperations.java | 11 ++++ .../keyvalue/redis/core/RedisTemplate.java | 61 ++++++++++++++----- .../keyvalue/redis/core/SessionCallback.java | 4 +- .../data/keyvalue/redis/core/SessionTest.java | 4 +- 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index f9c4411c3..b0e03eba5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -64,6 +64,17 @@ 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. + * + * @param list element return type + * @param action callback object to execute + * @return list of objects returned by the pipeline + */ + List executePipelined(RedisCallback action); + + Boolean hasKey(K key); void delete(K key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 5b4442dcd..b92251df4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.springframework.dao.DataAccessException; +import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; @@ -151,12 +152,14 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } /** - * Executes the given action object within a connection, that can be pipelined or not and which can be exposed or not. + * 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). + * Use {@link #executePipelined(RedisCallback)} as an alternative. * * @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 duration + * @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) { @@ -189,6 +192,48 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } } + + @Override + public T execute(SessionCallback session) { + RedisConnectionFactory factory = getConnectionFactory(); + // bind connection + RedisConnectionUtils.bindConnection(factory); + try { + return session.execute(this); + } finally { + RedisConnectionUtils.unbindConnection(factory); + } + } + + @Override + @SuppressWarnings("unchecked") + public List executePipelined(final RedisCallback action) { + return executePipelined(action, valueSerializer); + } + + /** + * 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 + * @return list of objects returned by the pipeline + */ + public List executePipelined(final RedisCallback action, final RedisSerializer resultSerializer) { + return execute(new RedisCallback>() { + public List doInRedis(RedisConnection connection) throws DataAccessException { + connection.openPipeline(); + Object result = action.doInRedis(connection); + if (result != null) { + throw new InvalidDataAccessApiUsageException( + "Callback cannot returned a non-null value as it gets overwritten by the pipeline"); + } + List pipeline = connection.closePipeline(); + return SerializationUtils.deserialize(pipeline, resultSerializer); + } + }); + } + protected RedisConnection createRedisConnectionProxy(RedisConnection pm) { Class[] ifcs = ClassUtils.getAllInterfacesForClass(pm.getClass(), getClass().getClassLoader()); return (RedisConnection) Proxy.newProxyInstance(pm.getClass().getClassLoader(), ifcs, @@ -208,18 +253,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return result; } - @Override - public T execute(SessionCallback session) { - RedisConnectionFactory factory = getConnectionFactory(); - // bind connection - RedisConnectionUtils.bindConnection(factory); - try { - return session.execute(this); - } finally { - RedisConnectionUtils.unbindConnection(factory); - } - } - /** * Returns whether to expose the native Redis connection to RedisCallback code, or rather a connection proxy (the default). * diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SessionCallback.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SessionCallback.java index d80e2ca3a..8af247965 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SessionCallback.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/SessionCallback.java @@ -15,6 +15,8 @@ */ package org.springframework.data.keyvalue.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. @@ -29,5 +31,5 @@ public interface SessionCallback { * @param operations Redis operations * @return return value */ - T execute(RedisOperations operations); + T execute(RedisOperations operations) throws DataAccessException; } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java index eb9e6c559..f550facfb 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java @@ -36,7 +36,7 @@ public class SessionTest { when(factory.getConnection()).thenReturn(conn); final StringRedisTemplate template = new StringRedisTemplate(factory); - template.execute(new SessionCallback() { + template.execute(new SessionCallback() { @Override public Object execute(RedisOperations operations) { checkConnection(template, conn); @@ -48,7 +48,7 @@ public class SessionTest { }); } - private void checkConnection(RedisTemplate template, final RedisConnection expectedConnection) { + private void checkConnection(RedisTemplate template, final RedisConnection expectedConnection) { template.execute(new RedisCallback() { @Override From e4a805eb1c1c212fbce2a691bef093da67b76a6c Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 20:01:23 +0200 Subject: [PATCH 15/68] DATAKV-44 + renamed KeyBound to BoundKeyOperations (to be consistent with the other interfaces) + enhanced the number of methods available on BoundKeyOperations --- .../redis/core/BoundHashOperations.java | 2 +- .../redis/core/BoundKeyOperations.java | 91 +++++++++++++++++++ .../redis/core/BoundListOperations.java | 2 +- .../redis/core/BoundSetOperations.java | 2 +- .../redis/core/BoundValueOperations.java | 2 +- .../redis/core/BoundZSetOperations.java | 2 +- .../core/DefaultBoundHashOperations.java | 11 ++- .../redis/core/DefaultBoundKeyOperations.java | 82 +++++++++++++++++ .../core/DefaultBoundListOperations.java | 11 ++- .../redis/core/DefaultBoundSetOperations.java | 11 ++- .../core/DefaultBoundValueOperations.java | 11 ++- .../core/DefaultBoundZSetOperations.java | 15 ++- .../keyvalue/redis/core/DefaultKeyBound.java | 41 --------- .../data/keyvalue/redis/core/KeyBound.java | 32 ------- .../support/atomic/RedisAtomicInteger.java | 60 ++++++++++-- .../redis/support/atomic/RedisAtomicLong.java | 60 ++++++++++-- .../collections/AbstractRedisCollection.java | 40 +++++++- .../support/collections/DefaultRedisList.java | 6 ++ .../support/collections/DefaultRedisMap.java | 49 +++++++++- .../support/collections/DefaultRedisSet.java | 6 ++ .../support/collections/DefaultRedisZSet.java | 6 ++ .../redis/support/collections/RedisStore.java | 4 +- 22 files changed, 432 insertions(+), 114 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java delete mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultKeyBound.java delete mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyBound.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java index dd8f53525..d559ed00d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java @@ -24,7 +24,7 @@ import java.util.Set; * * @author Costin Leau */ -public interface BoundHashOperations extends KeyBound { +public interface BoundHashOperations extends BoundKeyOperations { RedisOperations getOperations(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java new file mode 100644 index 000000000..2f632da20 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java @@ -0,0 +1,91 @@ +/* + * Copyright 2010-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import org.springframework.data.keyvalue.redis.connection.DataType; + +/** + * Operations over a Redis key. + * + * Useful for executing common key-'bound' operations to all implementations. + * + * @author Costin Leau + */ +public interface BoundKeyOperations { + + /** + * Returns the key associated with this entity. + * + * @return key associated with the implementing entity + */ + K getKey(); + + /** + * Returns the associated Redis type. + * + * @return key type + */ + DataType getType(); + + /** + * Returns the expiration of this key. + * + * @return expiration value (in seconds) + */ + Long getExpire(); + + /** + * Sets the key time-to-live/expiration. + * + * @param timeout expiration value + * @param unit expiration unit + * @return true if expiration was set, false otherwise + */ + Boolean expire(long timeout, TimeUnit unit); + + /** + * Sets the key time-to-live/expiration. + * + * @param date expiration date + * @return true if expiration was set, false otherwise + */ + Boolean expireAt(Date date); + + /** + * Removes the expiration (if any) of the key. + */ + void persist(); + + /** + * Renames the key. + * + * @param newKey new key + */ + void rename(K newKey); + + /** + * Renames the key (if the new key does not exist). Note that the underlying key + * changes only if the operation returns true (which does not happen if the connection + * is pipelined or in multi mode). + * + * @param newKey new key + * @return true if rename was successful, false otherwise + */ + Boolean renameIfAbsent(K newKey); +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java index a51df518a..5701587ba 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundListOperations.java @@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit; * * @author Costin Leau */ -public interface BoundListOperations extends KeyBound { +public interface BoundListOperations extends BoundKeyOperations { RedisOperations getOperations(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java index 2da61f806..e13520885 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundSetOperations.java @@ -24,7 +24,7 @@ import java.util.Set; * * @author Costin Leau */ -public interface BoundSetOperations extends KeyBound { +public interface BoundSetOperations extends BoundKeyOperations { RedisOperations getOperations(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java index ea7988ed2..6e0450465 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java @@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit; * * @author Costin Leau */ -public interface BoundValueOperations extends KeyBound { +public interface BoundValueOperations extends BoundKeyOperations { RedisOperations getOperations(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java index 37222cc93..2ba5783d4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundZSetOperations.java @@ -25,7 +25,7 @@ import java.util.Set; * * @author Costin Leau */ -public interface BoundZSetOperations extends KeyBound { +public interface BoundZSetOperations extends BoundKeyOperations { RedisOperations getOperations(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java index f55ed85be..c8e6a531e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java @@ -19,12 +19,14 @@ import java.util.Collection; import java.util.Map; import java.util.Set; +import org.springframework.data.keyvalue.redis.connection.DataType; + /** * Default implementation for {@link HashOperations}. * * @author Costin Leau */ -class DefaultBoundHashOperations extends DefaultKeyBound implements BoundHashOperations { +class DefaultBoundHashOperations extends DefaultBoundKeyOperations implements BoundHashOperations { private final HashOperations ops; @@ -35,7 +37,7 @@ class DefaultBoundHashOperations extends DefaultKeyBound implement * @param template */ public DefaultBoundHashOperations(H key, RedisOperations operations) { - super(key); + super(key, operations); this.ops = operations.opsForHash(); } @@ -103,4 +105,9 @@ class DefaultBoundHashOperations extends DefaultKeyBound implement public Map entries() { return ops.entries(getKey()); } + + @Override + public DataType getType() { + return DataType.HASH; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java new file mode 100644 index 000000000..bc17a6310 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java @@ -0,0 +1,82 @@ +/* + * Copyright 2010-2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import java.util.Date; +import java.util.concurrent.TimeUnit; + + +/** + * Default {@link BoundKeyOperations} implementation. + * Meant for internal usage. + * + * @author Costin Leau + */ +abstract class DefaultBoundKeyOperations implements BoundKeyOperations { + + private K key; + private final RedisOperations ops; + + public DefaultBoundKeyOperations(K key, RedisOperations operations) { + setKey(key); + this.ops = operations; + } + + @Override + public K getKey() { + return key; + } + + protected void setKey(K key) { + this.key = key; + } + + @Override + public Boolean expire(long timeout, TimeUnit unit) { + return ops.expire(key, timeout, unit); + } + + @Override + public Boolean expireAt(Date date) { + return ops.expireAt(key, date); + } + + @Override + public Long getExpire() { + return ops.getExpire(key); + } + + @Override + public void persist() { + ops.persist(key); + } + + @Override + public void rename(K newKey) { + ops.rename(key, newKey); + key = newKey; + } + + @Override + public Boolean renameIfAbsent(K newKey) { + Boolean result = ops.renameIfAbsent(key, newKey); + + if (Boolean.TRUE.equals(result)) { + key = newKey; + } + return result; + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java index df302ad11..45a34511c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java @@ -18,13 +18,15 @@ package org.springframework.data.keyvalue.redis.core; import java.util.List; import java.util.concurrent.TimeUnit; +import org.springframework.data.keyvalue.redis.connection.DataType; + /** * Default implementation for {@link BoundListOperations}. * * @author Costin Leau */ -class DefaultBoundListOperations extends DefaultKeyBound implements BoundListOperations { +class DefaultBoundListOperations extends DefaultBoundKeyOperations implements BoundListOperations { private final ListOperations ops; @@ -35,7 +37,7 @@ class DefaultBoundListOperations extends DefaultKeyBound implements Bou * @param operations */ public DefaultBoundListOperations(K key, RedisOperations operations) { - super(key); + super(key, operations); this.ops = operations.opsForList(); } @@ -124,4 +126,9 @@ class DefaultBoundListOperations extends DefaultKeyBound implements Bou public void set(long index, V value) { ops.set(getKey(), index, value); } + + @Override + public DataType getType() { + return DataType.LIST; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java index e92e21bd2..d0010b63a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java @@ -19,12 +19,14 @@ package org.springframework.data.keyvalue.redis.core; import java.util.Collection; import java.util.Set; +import org.springframework.data.keyvalue.redis.connection.DataType; + /** * Default implementation for {@link BoundSetOperations}. * * @author Costin Leau */ -class DefaultBoundSetOperations extends DefaultKeyBound implements BoundSetOperations { +class DefaultBoundSetOperations extends DefaultBoundKeyOperations implements BoundSetOperations { private final SetOperations ops; @@ -36,7 +38,7 @@ class DefaultBoundSetOperations extends DefaultKeyBound implements Boun * @param operations */ DefaultBoundSetOperations(K key, RedisOperations operations) { - super(key); + super(key, operations); this.ops = operations.opsForSet(); } @@ -146,4 +148,9 @@ class DefaultBoundSetOperations extends DefaultKeyBound implements Boun public void unionAndStore(Collection keys, K destKey) { ops.unionAndStore(getKey(), keys, destKey); } + + @Override + public DataType getType() { + return DataType.SET; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java index 7d0b2322f..c808847d5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java @@ -17,10 +17,12 @@ package org.springframework.data.keyvalue.redis.core; import java.util.concurrent.TimeUnit; +import org.springframework.data.keyvalue.redis.connection.DataType; + /** * @author Costin Leau */ -class DefaultBoundValueOperations extends DefaultKeyBound implements BoundValueOperations { +class DefaultBoundValueOperations extends DefaultBoundKeyOperations implements BoundValueOperations { private final ValueOperations ops; @@ -31,7 +33,7 @@ class DefaultBoundValueOperations extends DefaultKeyBound implements Bo * @param operations */ public DefaultBoundValueOperations(K key, RedisOperations operations) { - super(key); + super(key, operations); this.ops = operations.opsForValue(); } @@ -89,4 +91,9 @@ class DefaultBoundValueOperations extends DefaultKeyBound implements Bo public RedisOperations getOperations() { return ops.getOperations(); } + + @Override + public DataType getType() { + return DataType.STRING; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java index 343c1d72b..71590d863 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java @@ -19,12 +19,14 @@ package org.springframework.data.keyvalue.redis.core; import java.util.Collection; import java.util.Set; +import org.springframework.data.keyvalue.redis.connection.DataType; + /** * Default implementation for {@link BoundZSetOperations}. * * @author Costin Leau */ -class DefaultBoundZSetOperations extends DefaultKeyBound implements BoundZSetOperations { +class DefaultBoundZSetOperations extends DefaultBoundKeyOperations implements BoundZSetOperations { private final ZSetOperations ops; @@ -34,9 +36,9 @@ class DefaultBoundZSetOperations extends DefaultKeyBound implements Bou * @param key * @param oeprations */ - public DefaultBoundZSetOperations(K key, RedisOperations oeprations) { - super(key); - this.ops = oeprations.opsForZSet(); + public DefaultBoundZSetOperations(K key, RedisOperations operations) { + super(key, operations); + this.ops = operations.opsForZSet(); } @Override @@ -128,4 +130,9 @@ class DefaultBoundZSetOperations extends DefaultKeyBound implements Bou public void unionAndStore(Collection otherKeys, K destKey) { ops.unionAndStore(getKey(), otherKeys, destKey); } + + @Override + public DataType getType() { + return DataType.ZSET; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultKeyBound.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultKeyBound.java deleted file mode 100644 index 478c2eeb3..000000000 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultKeyBound.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.keyvalue.redis.core; - - -/** - * Default {@link KeyBound} implementation. - * Meant for internal usage. - * - * @author Costin Leau - */ -class DefaultKeyBound implements KeyBound { - - private K key; - - public DefaultKeyBound(K key) { - setKey(key); - } - - @Override - public K getKey() { - return key; - } - - protected void setKey(K key) { - this.key = key; - } -} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyBound.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyBound.java deleted file mode 100644 index 98aaa9b63..000000000 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/KeyBound.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2010-2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.keyvalue.redis.core; - -/** - * Contract defining the bind of the implementing entity to a Redis 'key'. - * Useful for executing 'bound' operations or operating over Redis 'collection' or 'views'. - * - * @author Costin Leau - */ -public interface KeyBound { - - /** - * Returns the key associated with this entity. - * - * @return key associated with the implementing entity - */ - K getKey(); -} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index bc69f1505..778a77cb1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -17,9 +17,12 @@ package org.springframework.data.keyvalue.redis.support.atomic; import java.io.Serializable; import java.util.Collections; +import java.util.Date; +import java.util.concurrent.TimeUnit; +import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; -import org.springframework.data.keyvalue.redis.core.KeyBound; +import org.springframework.data.keyvalue.redis.core.BoundKeyOperations; import org.springframework.data.keyvalue.redis.core.RedisOperations; import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.core.SessionCallback; @@ -34,9 +37,9 @@ import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; * @see java.util.concurrent.atomic.AtomicInteger * @author Costin Leau */ -public class RedisAtomicInteger extends Number implements Serializable, KeyBound { +public class RedisAtomicInteger extends Number implements Serializable, BoundKeyOperations { - private final String key; + private volatile String key; private ValueOperations operations; private RedisOperations generalOps; @@ -119,11 +122,6 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound this.operations.set(redisCounter, initialValue); } - @Override - public String getKey() { - return key; - } - /** * Get the current value. * @@ -261,4 +259,50 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound public double doubleValue() { return (double) get(); } + + @Override + public String getKey() { + return key; + } + + @Override + public Boolean expire(long timeout, TimeUnit unit) { + return generalOps.expire(key, timeout, unit); + } + + @Override + public Boolean expireAt(Date date) { + return generalOps.expireAt(key, date); + } + + @Override + public Long getExpire() { + return generalOps.getExpire(key); + } + + @Override + public void persist() { + generalOps.persist(key); + } + + @Override + public void rename(String newKey) { + generalOps.rename(key, newKey); + key = newKey; + } + + @Override + public Boolean renameIfAbsent(String newKey) { + Boolean result = generalOps.renameIfAbsent(key, newKey); + + if (Boolean.TRUE.equals(result)) { + key = newKey; + } + return result; + } + + @Override + public DataType getType() { + return DataType.STRING; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 7fc319b57..4805a3e13 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -17,9 +17,12 @@ package org.springframework.data.keyvalue.redis.support.atomic; import java.io.Serializable; import java.util.Collections; +import java.util.Date; +import java.util.concurrent.TimeUnit; +import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; -import org.springframework.data.keyvalue.redis.core.KeyBound; +import org.springframework.data.keyvalue.redis.core.BoundKeyOperations; import org.springframework.data.keyvalue.redis.core.RedisOperations; import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.core.SessionCallback; @@ -34,9 +37,9 @@ import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; * @see java.util.concurrent.atomic.AtomicLong * @author Costin Leau */ -public class RedisAtomicLong extends Number implements Serializable, KeyBound { +public class RedisAtomicLong extends Number implements Serializable, BoundKeyOperations { - private final String key; + private volatile String key; private ValueOperations operations; private RedisOperations generalOps; @@ -118,11 +121,6 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound extends AbstractCollection i public static final String ENCODING = "UTF-8"; - private final String key; + private volatile String key; private final RedisOperations operations; public AbstractRedisCollection(String key, RedisOperations operations) { @@ -116,4 +118,40 @@ public abstract class AbstractRedisCollection extends AbstractCollection i sb.append(getKey()); return sb.toString(); } + + @Override + public Boolean expire(long timeout, TimeUnit unit) { + return operations.expire(key, timeout, unit); + } + + @Override + public Boolean expireAt(Date date) { + return operations.expireAt(key, date); + } + + @Override + public Long getExpire() { + return operations.getExpire(key); + } + + @Override + public void persist() { + operations.persist(key); + } + + @Override + public void rename(String newKey) { + operations.rename(key, newKey); + key = newKey; + } + + @Override + public Boolean renameIfAbsent(String newKey) { + Boolean result = operations.renameIfAbsent(key, newKey); + + if (Boolean.TRUE.equals(result)) { + key = newKey; + } + return result; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java index 8992ddbfc..6149838c4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java @@ -23,6 +23,7 @@ import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; +import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.core.BoundListOperations; import org.springframework.data.keyvalue.redis.core.RedisOperations; @@ -498,4 +499,9 @@ public class DefaultRedisList extends AbstractRedisCollection implements R public E takeLast() throws InterruptedException { return pollLast(0, TimeUnit.SECONDS); } + + @Override + public DataType getType() { + return DataType.LIST; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java index e5d0e21db..bd150c3fd 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java @@ -17,11 +17,14 @@ package org.springframework.data.keyvalue.redis.support.collections; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; +import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.core.BoundHashOperations; import org.springframework.data.keyvalue.redis.core.RedisOperations; @@ -84,11 +87,6 @@ public class DefaultRedisMap implements RedisMap { return hashOps.increment(key, delta); } - @Override - public String getKey() { - return hashOps.getKey(); - } - @Override public RedisOperations getOperations() { return hashOps.getOperations(); @@ -295,4 +293,45 @@ public class DefaultRedisMap implements RedisMap { // } // } } + + @Override + public Boolean expire(long timeout, TimeUnit unit) { + return hashOps.expire(timeout, unit); + } + + @Override + public Boolean expireAt(Date date) { + return hashOps.expireAt(date); + } + + @Override + public Long getExpire() { + return hashOps.getExpire(); + } + + @Override + public void persist() { + hashOps.persist(); + } + + + @Override + public String getKey() { + return hashOps.getKey(); + } + + @Override + public void rename(String newKey) { + hashOps.rename(newKey); + } + + @Override + public Boolean renameIfAbsent(String newKey) { + return hashOps.renameIfAbsent(newKey); + } + + @Override + public DataType getType() { + return hashOps.getType(); + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java index 50a69ea11..368d7c204 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java @@ -21,6 +21,7 @@ import java.util.Iterator; import java.util.Set; import java.util.UUID; +import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.core.BoundSetOperations; import org.springframework.data.keyvalue.redis.core.RedisOperations; @@ -166,4 +167,9 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re public int size() { return boundSetOps.size().intValue(); } + + @Override + public DataType getType() { + return DataType.SET; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java index d3ee04765..4794aae99 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java @@ -20,6 +20,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; +import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.core.BoundZSetOperations; import org.springframework.data.keyvalue.redis.core.RedisOperations; @@ -211,4 +212,9 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R public Double score(Object o) { return boundZSetOps.score(o); } + + @Override + public DataType getType() { + return DataType.ZSET; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisStore.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisStore.java index 5a8c1fbfc..d3c9205d8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisStore.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisStore.java @@ -15,7 +15,7 @@ */ package org.springframework.data.keyvalue.redis.support.collections; -import org.springframework.data.keyvalue.redis.core.KeyBound; +import org.springframework.data.keyvalue.redis.core.BoundKeyOperations; import org.springframework.data.keyvalue.redis.core.RedisOperations; /** @@ -26,7 +26,7 @@ import org.springframework.data.keyvalue.redis.core.RedisOperations; * * @author Costin Leau */ -public interface RedisStore extends KeyBound { +public interface RedisStore extends BoundKeyOperations { /** * Returns the underlying Redis operations used by the backing implementation. From c2c6cd8791ec0dd9bcd1e9d0f2bf64ab94d3eabe Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 20:29:59 +0200 Subject: [PATCH 16/68] + improve connection cleanup in some tests --- .../AbstractConnectionIntegrationTests.java | 17 +++-------------- .../redis/support/atomic/RedisAtomicTests.java | 1 + 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index d26002762..afe8e7219 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -19,19 +19,17 @@ package org.springframework.data.keyvalue.redis.connection; import static org.junit.Assert.*; import java.util.Arrays; -import java.util.LinkedHashSet; import java.util.List; import java.util.Properties; -import java.util.Set; import java.util.UUID; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; -import org.springframework.beans.factory.DisposableBean; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.redis.Address; +import org.springframework.data.keyvalue.redis.ConnectionFactoryTracker; import org.springframework.data.keyvalue.redis.Person; import org.springframework.data.keyvalue.redis.core.StringRedisTemplate; import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer; @@ -49,26 +47,17 @@ public abstract class AbstractConnectionIntegrationTests { protected abstract RedisConnectionFactory getConnectionFactory(); - private static Set connFactories = new LinkedHashSet(); @Before public void setUp() { connection = new DefaultStringRedisConnection(getConnectionFactory().getConnection()); - connFactories.add(getConnectionFactory()); + ConnectionFactoryTracker.add(getConnectionFactory()); } @AfterClass public static void cleanUp() { - if (connFactories != null) { - for (RedisConnectionFactory connectionFactory : connFactories) { - try { - ((DisposableBean) connectionFactory).destroy(); - } catch (Exception ex) { - System.err.println("Cannot clean factory " + connectionFactory + ex); - } - } - } + ConnectionFactoryTracker.cleanUp(); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java index 306f7dff9..25c0a93dc 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java @@ -44,6 +44,7 @@ public class RedisAtomicTests { intCounter = new RedisAtomicInteger(getClass().getSimpleName() + ":int", factory); longCounter = new RedisAtomicLong(getClass().getSimpleName() + ":long", factory); this.factory = factory; + ConnectionFactoryTracker.add(factory); } @After From 3331c8744c55d1c9763974e1d9681169a3f4923a Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 21:36:45 +0200 Subject: [PATCH 17/68] + update persist signature to return boolean instead of void --- .../data/keyvalue/redis/core/RedisOperations.java | 2 +- .../data/keyvalue/redis/core/RedisTemplate.java | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index b0e03eba5..836277f63 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -95,7 +95,7 @@ public interface RedisOperations { Boolean expireAt(K key, Date date); - void persist(K key); + Boolean persist(K key); Long getExpire(K key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index b92251df4..c541cd39b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -542,14 +542,13 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @Override - public void persist(K key) { + public Boolean persist(K key) { final byte[] rawKey = rawKey(key); - execute(new RedisCallback() { + return execute(new RedisCallback() { @Override - public Object doInRedis(RedisConnection connection) { - connection.persist(rawKey); - return null; + public Boolean doInRedis(RedisConnection connection) { + return connection.persist(rawKey); } }, true); } From 31533a9dc2e7e64f3586c59f35c8c5200d400087 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 21:38:40 +0200 Subject: [PATCH 18/68] DATAKV-44 + update persist signature --- .../data/keyvalue/redis/core/BoundKeyOperations.java | 3 ++- .../data/keyvalue/redis/core/DefaultBoundKeyOperations.java | 4 ++-- .../keyvalue/redis/support/atomic/RedisAtomicInteger.java | 4 ++-- .../data/keyvalue/redis/support/atomic/RedisAtomicLong.java | 4 ++-- .../redis/support/collections/AbstractRedisCollection.java | 4 ++-- .../keyvalue/redis/support/collections/DefaultRedisMap.java | 4 ++-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java index 2f632da20..f2eb1fb4b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java @@ -69,8 +69,9 @@ public interface BoundKeyOperations { /** * Removes the expiration (if any) of the key. + * @return true if expiration was removed, false otherwise */ - void persist(); + Boolean persist(); /** * Renames the key. diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java index bc17a6310..b33c3f234 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java @@ -60,8 +60,8 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { } @Override - public void persist() { - ops.persist(key); + public Boolean persist() { + return ops.persist(key); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index 778a77cb1..c9a6e5172 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -281,8 +281,8 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey } @Override - public void persist() { - generalOps.persist(key); + public Boolean persist() { + return generalOps.persist(key); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 4805a3e13..4ef22ed70 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -284,8 +284,8 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe } @Override - public void persist() { - generalOps.persist(key); + public Boolean persist() { + return generalOps.persist(key); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java index 3cdbbffb7..3bd04f14d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java @@ -135,8 +135,8 @@ public abstract class AbstractRedisCollection extends AbstractCollection i } @Override - public void persist() { - operations.persist(key); + public Boolean persist() { + return operations.persist(key); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java index bd150c3fd..79bef39c7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java @@ -310,8 +310,8 @@ public class DefaultRedisMap implements RedisMap { } @Override - public void persist() { - hashOps.persist(); + public Boolean persist() { + return hashOps.persist(); } From 689af37119ed025ba9634b560563a449e4d78422 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 21:53:48 +0200 Subject: [PATCH 19/68] DATAKV-44 + integration tests for the new BoundKeyOperations interface --- .../redis/support/BoundKeyOperationsTest.java | 105 ++++++++++++++++++ .../redis/support/BoundKeyParams.java | 72 ++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyParams.java diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java new file mode 100644 index 000000000..535cb4cf2 --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java @@ -0,0 +1,105 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.support; + +import static org.junit.Assert.*; + +import java.util.Collection; +import java.util.concurrent.TimeUnit; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.springframework.data.keyvalue.redis.ConnectionFactoryTracker; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; +import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; +import org.springframework.data.keyvalue.redis.core.BoundKeyOperations; +import org.springframework.data.keyvalue.redis.support.collections.ObjectFactory; + +/** + * @author Costin Leau + */ +@RunWith(Parameterized.class) +public class BoundKeyOperationsTest { + private RedisConnectionFactory factory; + private BoundKeyOperations keyOps; + private ObjectFactory objFactory; + + public BoundKeyOperationsTest(BoundKeyOperations keyOps, ObjectFactory objFactory, + RedisConnectionFactory factory) { + this.factory = factory; + this.objFactory = objFactory; + this.keyOps = keyOps; + ConnectionFactoryTracker.add(factory); + } + + @After + public void stop() { + RedisConnection connection = factory.getConnection(); + connection.close(); + } + + @AfterClass + public static void cleanUp() { + ConnectionFactoryTracker.cleanUp(); + } + + @Parameters + public static Collection testParams() { + return BoundKeyParams.testParams(); + } + + @Test + public void testRename() throws Exception { + Object key = keyOps.getKey(); + assertNotNull(key); + Object newName = objFactory.instance(); + keyOps.rename(newName); + assertEquals(newName, keyOps.getKey()); + keyOps.rename(key); + assertEquals(key, keyOps.getKey()); + } + + @Test + public void testRenameIfAbsent() throws Exception { + Object key = keyOps.getKey(); + assertNotNull(key); + Object newName = objFactory.instance(); + keyOps.renameIfAbsent(newName); + assertEquals(newName, keyOps.getKey()); + keyOps.rename(key); + } + + @Test + public void testExpire() throws Exception { + assertEquals(Long.valueOf(-1), keyOps.getExpire()); + assertTrue(keyOps.expire(10, TimeUnit.SECONDS)); + long expire = keyOps.getExpire().longValue(); + assertTrue(expire <= 10 && expire > 5); + } + + @Test + public void testPersist() throws Exception { + assertEquals(Long.valueOf(-1), keyOps.getExpire()); + assertTrue(keyOps.expire(10, TimeUnit.SECONDS)); + assertTrue(keyOps.getExpire().longValue() > 0); + keyOps.persist(); + assertTrue(keyOps.getExpire().longValue() > 0); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyParams.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyParams.java new file mode 100644 index 000000000..21aa9462b --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyParams.java @@ -0,0 +1,72 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.support; + +import java.util.Arrays; +import java.util.Collection; + +import org.springframework.data.keyvalue.redis.SettingsUtils; +import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.keyvalue.redis.connection.jredis.JredisConnectionFactory; +import org.springframework.data.keyvalue.redis.core.StringRedisTemplate; +import org.springframework.data.keyvalue.redis.support.atomic.RedisAtomicInteger; +import org.springframework.data.keyvalue.redis.support.atomic.RedisAtomicLong; +import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisList; +import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisMap; +import org.springframework.data.keyvalue.redis.support.collections.DefaultRedisSet; +import org.springframework.data.keyvalue.redis.support.collections.RedisList; +import org.springframework.data.keyvalue.redis.support.collections.StringObjectFactory; + +/** + * @author Costin Leau + */ +public class BoundKeyParams { + + public static Collection testParams() { + // create Jedis Factory + JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); + jedisConnFactory.setPort(SettingsUtils.getPort()); + jedisConnFactory.setHostName(SettingsUtils.getHost()); + jedisConnFactory.afterPropertiesSet(); + + // jredis factory + JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(); + jredisConnFactory.setUsePool(true); + jredisConnFactory.setPort(SettingsUtils.getPort()); + jredisConnFactory.setHostName(SettingsUtils.getHost()); + jredisConnFactory.afterPropertiesSet(); + + StringRedisTemplate templateJS = new StringRedisTemplate(jedisConnFactory); + StringRedisTemplate templateJR = new StringRedisTemplate(jredisConnFactory); + + StringObjectFactory sof = new StringObjectFactory(); + + DefaultRedisMap mapJS = new DefaultRedisMap("bound:key:map", templateJS); + mapJS.put("foo", "bar"); + + DefaultRedisSet setJS = new DefaultRedisSet("bound:key:set", templateJS); + setJS.add("foo"); + + RedisList list = new DefaultRedisList("bound:key:list", templateJS); + list.add("foo"); + + return Arrays.asList(new Object[][] { + { new RedisAtomicInteger("bound:key:int", jedisConnFactory), sof, jedisConnFactory }, + { new RedisAtomicLong("bound:key:long", jedisConnFactory), sof, jedisConnFactory }, + { list, sof, jedisConnFactory }, + { setJS, sof, jedisConnFactory }, { mapJS, sof, jedisConnFactory } }); + } +} From bb236634f0222d26038da668442f72d5330552b1 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 22:11:57 +0200 Subject: [PATCH 20/68] + update return signature for jedis exec --- .../redis/connection/DefaultStringRedisConnection.java | 2 +- .../data/keyvalue/redis/connection/RedisTxCommands.java | 2 +- .../keyvalue/redis/connection/jedis/JedisConnection.java | 9 +++++++-- .../redis/connection/jredis/JredisConnection.java | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index 3d857e3df..f966bbee8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -116,7 +116,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.echo(message); } - public List exec() { + public List exec() { return delegate.exec(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisTxCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisTxCommands.java index 73f82f600..79f14bec4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisTxCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisTxCommands.java @@ -27,7 +27,7 @@ public interface RedisTxCommands { void multi(); - List exec(); + List exec(); void discard(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index d3f898769..6f4286615 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -511,14 +511,19 @@ public class JedisConnection implements RedisConnection { } } + @SuppressWarnings("unchecked") @Override - public List exec() { + public List exec() { try { if (isPipelined()) { pipeline.exec(); return null; } - return transaction.exec(); + List execute = transaction.exec(); + if (execute != null && !execute.isEmpty()) { + return (List) execute; + } + return Collections.emptyList(); } catch (Exception ex) { throw convertJedisAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index dca7e829d..92f5ebc34 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -267,7 +267,7 @@ public class JredisConnection implements RedisConnection { } @Override - public List exec() { + public List exec() { throw new UnsupportedOperationException(); } From 0523430a454f1135383f061afceffeaf51990d03 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 23:42:31 +0200 Subject: [PATCH 21/68] + change exec return type to List --- .../redis/connection/DefaultStringRedisConnection.java | 2 +- .../data/keyvalue/redis/connection/RedisTxCommands.java | 2 +- .../keyvalue/redis/connection/jedis/JedisConnection.java | 9 ++------- .../redis/connection/jredis/JredisConnection.java | 2 +- .../data/keyvalue/redis/core/RedisOperations.java | 2 +- .../data/keyvalue/redis/core/RedisTemplate.java | 6 +++--- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index f966bbee8..3d857e3df 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -116,7 +116,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.echo(message); } - public List exec() { + public List exec() { return delegate.exec(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisTxCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisTxCommands.java index 79f14bec4..73f82f600 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisTxCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisTxCommands.java @@ -27,7 +27,7 @@ public interface RedisTxCommands { void multi(); - List exec(); + List exec(); void discard(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 6f4286615..d3f898769 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -511,19 +511,14 @@ public class JedisConnection implements RedisConnection { } } - @SuppressWarnings("unchecked") @Override - public List exec() { + public List exec() { try { if (isPipelined()) { pipeline.exec(); return null; } - List execute = transaction.exec(); - if (execute != null && !execute.isEmpty()) { - return (List) execute; - } - return Collections.emptyList(); + return transaction.exec(); } catch (Exception ex) { throw convertJedisAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 92f5ebc34..dca7e829d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -267,7 +267,7 @@ public class JredisConnection implements RedisConnection { } @Override - public List exec() { + public List exec() { throw new UnsupportedOperationException(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index 836277f63..dbae2dbba 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -112,7 +112,7 @@ public interface RedisOperations { void discard(); - Object exec(); + List exec(); // pubsub functionality on the template void convertAndSend(String destination, Object message); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index c541cd39b..6358593c5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -419,11 +419,11 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // RedisOperations // @Override - public Object exec() { - return execute(new RedisCallback() { + public List exec() { + return execute(new RedisCallback>() { @Override - public Object doInRedis(RedisConnection connection) throws DataAccessException { + public List doInRedis(RedisConnection connection) throws DataAccessException { return connection.exec(); } }); From 3d4d30e21690052c5277be327891770406aec9d7 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 23:43:02 +0200 Subject: [PATCH 22/68] + add atomic key/check/rename to abstract redis collection (sort of messy) --- .../collections/AbstractRedisCollection.java | 54 +++++++++++++++++-- .../redis/support/BoundKeyOperationsTest.java | 33 ++++++------ .../redis/support/BoundKeyParams.java | 12 ++--- 3 files changed, 71 insertions(+), 28 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java index 3bd04f14d..2ef2337dc 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java @@ -18,9 +18,12 @@ package org.springframework.data.keyvalue.redis.support.collections; import java.util.AbstractCollection; import java.util.Collection; import java.util.Date; +import java.util.List; import java.util.concurrent.TimeUnit; +import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.redis.core.RedisOperations; +import org.springframework.data.keyvalue.redis.core.SessionCallback; /** * Base implementation for {@link RedisCollection}. @@ -140,14 +143,57 @@ public abstract class AbstractRedisCollection extends AbstractCollection i } @Override - public void rename(String newKey) { - operations.rename(key, newKey); + public void rename(final String newKey) { + operations.execute(new SessionCallback() { + @SuppressWarnings("unchecked") + @Override + public Object execute(RedisOperations operations) throws DataAccessException { + do { + operations.watch(key); + + if (operations.hasKey(key)) { + operations.multi(); + operations.rename(key, newKey); + } + else { + operations.multi(); + } + } while (operations.exec() == null); + return null; + } + }); key = newKey; } @Override - public Boolean renameIfAbsent(String newKey) { - Boolean result = operations.renameIfAbsent(key, newKey); + public Boolean renameIfAbsent(final String newKey) { + Boolean result = operations.execute(new SessionCallback() { + @Override + public Boolean execute(RedisOperations operations) throws DataAccessException { + List exec = null; + do { + operations.watch(key); + + if (operations.hasKey(key)) { + operations.multi(); + operations.renameIfAbsent(key, newKey); + } + else { + operations.watch(newKey); + operations.multi(); + operations.hasKey(newKey); + operations.hasKey(newKey); + } + exec = operations.exec(); + } while (exec == null); + + boolean result = ((Long) exec.get(0) == 1); + if (exec.size()>1) { + result = !result; + } + return result; + } + }); if (Boolean.TRUE.equals(result)) { key = newKey; diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java index 535cb4cf2..8f36bad53 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java @@ -27,9 +27,8 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import org.springframework.data.keyvalue.redis.ConnectionFactoryTracker; -import org.springframework.data.keyvalue.redis.connection.RedisConnection; -import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.data.keyvalue.redis.core.BoundKeyOperations; +import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.support.collections.ObjectFactory; /** @@ -37,22 +36,20 @@ import org.springframework.data.keyvalue.redis.support.collections.ObjectFactory */ @RunWith(Parameterized.class) public class BoundKeyOperationsTest { - private RedisConnectionFactory factory; private BoundKeyOperations keyOps; private ObjectFactory objFactory; + private RedisTemplate template; public BoundKeyOperationsTest(BoundKeyOperations keyOps, ObjectFactory objFactory, - RedisConnectionFactory factory) { - this.factory = factory; + RedisTemplate template) { this.objFactory = objFactory; this.keyOps = keyOps; - ConnectionFactoryTracker.add(factory); + this.template = template; + ConnectionFactoryTracker.add(template.getConnectionFactory()); } @After public void stop() { - RedisConnection connection = factory.getConnection(); - connection.close(); } @AfterClass @@ -81,7 +78,8 @@ public class BoundKeyOperationsTest { Object key = keyOps.getKey(); assertNotNull(key); Object newName = objFactory.instance(); - keyOps.renameIfAbsent(newName); + assertFalse(template.hasKey(newName)); + assertTrue("cannot rename to key " + newName, keyOps.renameIfAbsent(newName)); assertEquals(newName, keyOps.getKey()); keyOps.rename(key); } @@ -89,17 +87,20 @@ public class BoundKeyOperationsTest { @Test public void testExpire() throws Exception { assertEquals(Long.valueOf(-1), keyOps.getExpire()); - assertTrue(keyOps.expire(10, TimeUnit.SECONDS)); - long expire = keyOps.getExpire().longValue(); - assertTrue(expire <= 10 && expire > 5); + if (keyOps.expire(10, TimeUnit.SECONDS)) { + long expire = keyOps.getExpire().longValue(); + assertTrue(expire <= 10 && expire > 5); + } } @Test public void testPersist() throws Exception { - assertEquals(Long.valueOf(-1), keyOps.getExpire()); - assertTrue(keyOps.expire(10, TimeUnit.SECONDS)); - assertTrue(keyOps.getExpire().longValue() > 0); keyOps.persist(); - assertTrue(keyOps.getExpire().longValue() > 0); + assertEquals(Long.valueOf(-1), keyOps.getExpire()); + if (keyOps.expire(10, TimeUnit.SECONDS)) { + assertTrue(keyOps.getExpire().longValue() > 0); + } + keyOps.persist(); + assertEquals(-1, keyOps.getExpire().longValue()); } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyParams.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyParams.java index 21aa9462b..df2156509 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyParams.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyParams.java @@ -55,18 +55,14 @@ public class BoundKeyParams { StringObjectFactory sof = new StringObjectFactory(); DefaultRedisMap mapJS = new DefaultRedisMap("bound:key:map", templateJS); - mapJS.put("foo", "bar"); DefaultRedisSet setJS = new DefaultRedisSet("bound:key:set", templateJS); - setJS.add("foo"); - + RedisList list = new DefaultRedisList("bound:key:list", templateJS); - list.add("foo"); return Arrays.asList(new Object[][] { - { new RedisAtomicInteger("bound:key:int", jedisConnFactory), sof, jedisConnFactory }, - { new RedisAtomicLong("bound:key:long", jedisConnFactory), sof, jedisConnFactory }, - { list, sof, jedisConnFactory }, - { setJS, sof, jedisConnFactory }, { mapJS, sof, jedisConnFactory } }); + { 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 } }); } } From cd0dcf9b137a032a6b267ee574d610fe49de2e44 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 15 Mar 2011 23:53:26 +0200 Subject: [PATCH 23/68] + extracted cas rename logic into utility class --- .../collections/AbstractRedisCollection.java | 50 +--------------- .../support/collections/CollectionUtils.java | 57 ++++++++++++++++++- 2 files changed, 58 insertions(+), 49 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java index 2ef2337dc..d37640671 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java @@ -18,12 +18,9 @@ package org.springframework.data.keyvalue.redis.support.collections; import java.util.AbstractCollection; import java.util.Collection; import java.util.Date; -import java.util.List; import java.util.concurrent.TimeUnit; -import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.redis.core.RedisOperations; -import org.springframework.data.keyvalue.redis.core.SessionCallback; /** * Base implementation for {@link RedisCollection}. @@ -144,56 +141,13 @@ public abstract class AbstractRedisCollection extends AbstractCollection i @Override public void rename(final String newKey) { - operations.execute(new SessionCallback() { - @SuppressWarnings("unchecked") - @Override - public Object execute(RedisOperations operations) throws DataAccessException { - do { - operations.watch(key); - - if (operations.hasKey(key)) { - operations.multi(); - operations.rename(key, newKey); - } - else { - operations.multi(); - } - } while (operations.exec() == null); - return null; - } - }); + CollectionUtils.rename(key, newKey, operations); key = newKey; } @Override public Boolean renameIfAbsent(final String newKey) { - Boolean result = operations.execute(new SessionCallback() { - @Override - public Boolean execute(RedisOperations operations) throws DataAccessException { - List exec = null; - do { - operations.watch(key); - - if (operations.hasKey(key)) { - operations.multi(); - operations.renameIfAbsent(key, newKey); - } - else { - operations.watch(newKey); - operations.multi(); - operations.hasKey(newKey); - operations.hasKey(newKey); - } - exec = operations.exec(); - } while (exec == null); - - boolean result = ((Long) exec.get(0) == 1); - if (exec.size()>1) { - result = !result; - } - return result; - } - }); + Boolean result = CollectionUtils.renameIfAbsent(key, newKey, operations); if (Boolean.TRUE.equals(result)) { key = newKey; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java index 20cfd6450..e98c8287a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java @@ -20,6 +20,10 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import org.springframework.dao.DataAccessException; +import org.springframework.data.keyvalue.redis.core.RedisOperations; +import org.springframework.data.keyvalue.redis.core.SessionCallback; + /** * Utility class used mainly for type conversion by the default collection implementations. * Meant for internal use. @@ -48,4 +52,55 @@ abstract class CollectionUtils { return keys; } -} + + static void rename(final K key, final K newKey, RedisOperations operations) { + operations.execute(new SessionCallback() { + @SuppressWarnings("unchecked") + @Override + public Object execute(RedisOperations operations) throws DataAccessException { + do { + operations.watch(key); + + if (operations.hasKey(key)) { + operations.multi(); + operations.rename(key, newKey); + } + else { + operations.multi(); + } + } while (operations.exec() == null); + return null; + } + }); + } + + static Boolean renameIfAbsent(final K key, final K newKey, RedisOperations operations) { + return operations.execute(new SessionCallback() { + @Override + public Boolean execute(RedisOperations operations) throws DataAccessException { + List exec = null; + do { + operations.watch(key); + + if (operations.hasKey(key)) { + operations.multi(); + operations.renameIfAbsent(key, newKey); + } + else { + operations.watch(newKey); + operations.multi(); + operations.hasKey(newKey); + operations.hasKey(newKey); + } + exec = operations.exec(); + } while (exec == null); + + boolean result = ((Long) exec.get(0) == 1); + if (exec.size() > 1) { + result = !result; + } + return result; + } + }); + } +} \ No newline at end of file From 850560f2237f5d8964479ba2ba16e25c7b752c49 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 09:49:07 +0200 Subject: [PATCH 24/68] DATAKV-46 + add initial Rjc connection/connection factory support --- spring-data-redis/pom.xml | 23 +- .../jedis/JedisConnectionFactory.java | 2 +- .../connection/jredis/JredisConnection.java | 6 +- .../redis/connection/rjc/RjcConnection.java | 709 ++++++++++++++++++ .../connection/rjc/RjcConnectionFactory.java | 209 ++++++ .../redis/connection/rjc/RjcUtils.java | 41 + .../connection/rjc/SingleDataSource.java | 38 + 7 files changed, 1011 insertions(+), 17 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index 2f683aefe..c0fe69d97 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -16,8 +16,10 @@ "[3.0.0, 4.0.0)" 03122010 1.5.2 + 0.6.2 "[1.0.0,2.0.0)" "[1.6, 2.0.0)" + "[0.6.2, 0.6.2]" @@ -135,27 +137,18 @@ compile - org.jredis jredis-anthonylauzon ${jredis.ver} compile + + org.idevlab + rjc + ${rjc.ver} + compile + diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java index 099067bbd..51f326a39 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java @@ -34,7 +34,7 @@ import redis.clients.jedis.JedisShardInfo; import redis.clients.jedis.Protocol; /** - * Connection factory using creating Jedis based connections. + * Connection factory creating Jedis based connections. * * @author Costin Leau */ diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index dca7e829d..6357ff522 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -81,7 +81,11 @@ public class JredisConnection implements RedisConnection { // don't actually close the connection // if a pool is used if (!isPool) { - jredis.quit(); + try { + jredis.quit(); + } catch (Exception ex) { + throw convertJredisAccessException(ex); + } } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java new file mode 100644 index 000000000..1983555d5 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -0,0 +1,709 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.idevlab.rjc.RedisException; +import org.idevlab.rjc.Session; +import org.idevlab.rjc.SessionFactoryImpl; +import org.springframework.dao.DataAccessException; +import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; +import org.springframework.data.keyvalue.redis.connection.DataType; +import org.springframework.data.keyvalue.redis.connection.MessageListener; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; +import org.springframework.data.keyvalue.redis.connection.SortParameters; +import org.springframework.data.keyvalue.redis.connection.Subscription; + +/** + * {@code RedisConnection} implementation on top of rjc library. + * + * @author Costin Leau + */ +public class RjcConnection implements RedisConnection { + + private final int dbIndex; + private final Session session; + private boolean isClosed = false; + + public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { + session = new SessionFactoryImpl(new SingleDataSource(connection)).create(); + this.dbIndex = dbIndex; + + // select the db + if (dbIndex > 0) { + select(dbIndex); + } + } + + protected DataAccessException convertRjcAccessException(Exception ex) { + if (ex instanceof RedisException) { + return RjcUtils.convertRjcAccessException((RedisException) ex); + } + return new UncategorizedKeyvalueStoreException("Unknown rjc exception", ex); + } + + @Override + public void close() throws DataAccessException { + isClosed = true; + try { + session.close(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + @Override + public boolean isClosed() { + return isClosed; + } + + @Override + public Session getNativeConnection() { + return session; + } + + @Override + public List closePipeline() { + throw new UnsupportedOperationException(); + } + + + @Override + public boolean isPipelined() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isQueueing() { + throw new UnsupportedOperationException(); + } + + @Override + public void openPipeline() { + throw new UnsupportedOperationException(); + } + + @Override + public Long del(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] echo(byte[] message) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean exists(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean expire(byte[] key, long seconds) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean expireAt(byte[] key, long unixTime) { + throw new UnsupportedOperationException(); + } + + @Override + public Set keys(byte[] pattern) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean persist(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public String ping() { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] randomKey() { + throw new UnsupportedOperationException(); + } + + @Override + public void rename(byte[] oldName, byte[] newName) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean renameNX(byte[] oldName, byte[] newName) { + throw new UnsupportedOperationException(); + } + + @Override + public void select(int dbIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public List sort(byte[] key, SortParameters params) { + throw new UnsupportedOperationException(); + } + + @Override + public Long sort(byte[] key, SortParameters params, byte[] storeKey) { + throw new UnsupportedOperationException(); + } + + @Override + public Long ttl(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public DataType type(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public void discard() { + throw new UnsupportedOperationException(); + } + + @Override + public List exec() { + throw new UnsupportedOperationException(); + } + + @Override + public void multi() { + throw new UnsupportedOperationException(); + } + + @Override + public void unwatch() { + throw new UnsupportedOperationException(); + } + + @Override + public void watch(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public Long append(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long decr(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long decrBy(byte[] key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] get(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean getBit(byte[] key, long offset) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] getRange(byte[] key, int begin, int end) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] getSet(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long incr(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long incrBy(byte[] key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public List mGet(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void mSet(Map tuple) { + throw new UnsupportedOperationException(); + } + + @Override + public void mSetNX(Map tuple) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setBit(byte[] key, long offset, boolean value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setEx(byte[] key, long seconds, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean setNX(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setRange(byte[] key, int begin, int end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long strLen(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public List bLPop(int timeout, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public List bRPop(int timeout, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] lIndex(byte[] key, long index) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lLen(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] lPop(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lPush(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lPushX(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public List lRange(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lRem(byte[] key, long count, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public void lSet(byte[] key, long index, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public void lTrim(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] rPop(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { + throw new UnsupportedOperationException(); + } + + @Override + public Long rPush(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long rPushX(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean sAdd(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long sCard(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Set sDiff(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void sDiffStore(byte[] destKey, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public Set sInter(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void sInterStore(byte[] destKey, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean sIsMember(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Set sMembers(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] sPop(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] sRandMember(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean sRem(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Set sUnion(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void sUnionStore(byte[] destKey, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean zAdd(byte[] key, double score, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zCard(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zCount(byte[] key, double min, double max) { + throw new UnsupportedOperationException(); + } + + @Override + public Double zIncrBy(byte[] key, double increment, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zInterStore(byte[] destKey, byte[]... sets) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRange(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeByScore(byte[] key, double min, double max) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeByScoreWithScore(byte[] key, double min, double max) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeWithScore(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zRank(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean zRem(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zRemRange(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zRemRangeByScore(byte[] key, double min, double max) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRevRange(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRevRangeWithScore(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zRevRank(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Double zScore(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zUnionStore(byte[] destKey, byte[]... sets) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean hDel(byte[] key, byte[] field) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean hExists(byte[] key, byte[] field) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] hGet(byte[] key, byte[] field) { + throw new UnsupportedOperationException(); + } + + @Override + public Map hGetAll(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long hIncrBy(byte[] key, byte[] field, long delta) { + throw new UnsupportedOperationException(); + } + + @Override + public Set hKeys(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long hLen(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public List hMGet(byte[] key, byte[]... fields) { + throw new UnsupportedOperationException(); + } + + @Override + public void hMSet(byte[] key, Map hashes) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean hSet(byte[] key, byte[] field, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public List hVals(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public void bgSave() { + throw new UnsupportedOperationException(); + } + + @Override + public void bgWriteAof() { + throw new UnsupportedOperationException(); + } + + @Override + public Long dbSize() { + throw new UnsupportedOperationException(); + } + + @Override + public void flushAll() { + throw new UnsupportedOperationException(); + } + + @Override + public void flushDb() { + throw new UnsupportedOperationException(); + } + + @Override + public List getConfig(String pattern) { + throw new UnsupportedOperationException(); + } + + @Override + public Properties info() { + throw new UnsupportedOperationException(); + } + + @Override + public Long lastSave() { + throw new UnsupportedOperationException(); + } + + @Override + public void resetConfigStats() { + throw new UnsupportedOperationException(); + } + + @Override + public void save() { + throw new UnsupportedOperationException(); + } + + @Override + public void setConfig(String param, String value) { + throw new UnsupportedOperationException(); + } + + @Override + public void shutdown() { + throw new UnsupportedOperationException(); + } + + @Override + public Subscription getSubscription() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isSubscribed() { + throw new UnsupportedOperationException(); + } + + @Override + public void pSubscribe(MessageListener listener, byte[]... patterns) { + throw new UnsupportedOperationException(); + } + + @Override + public Long publish(byte[] channel, byte[] message) { + throw new UnsupportedOperationException(); + } + + @Override + public void subscribe(MessageListener listener, byte[]... channels) { + throw new UnsupportedOperationException(); + } + +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java new file mode 100644 index 000000000..97f1c65cd --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java @@ -0,0 +1,209 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.idevlab.rjc.ds.DataSource; +import org.idevlab.rjc.ds.PoolableDataSource; +import org.idevlab.rjc.ds.SimpleDataSource; +import org.idevlab.rjc.protocol.Protocol; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.dao.DataAccessException; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; +import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; +import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.util.Assert; + +/** + * Connection factory creating rjc based connections. + * + * @author Costin Leau + */ +public class RjcConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory { + + private final static Log log = LogFactory.getLog(JedisConnectionFactory.class); + + private String hostName = "localhost"; + private int port = Protocol.DEFAULT_PORT; + private int timeout = Protocol.DEFAULT_TIMEOUT; + private String password; + + private boolean usePool = true; + private int dbIndex = 0; + private DataSource dataSource; + + + /** + * Constructs a new RjcConnectionFactory instance + * with default settings (default connection pooling, no shard information). + */ + public RjcConnectionFactory() { + } + + + public void afterPropertiesSet() { + if (usePool) { + PoolableDataSource pool = new PoolableDataSource(); + pool.setHost(hostName); + pool.setPort(port); + pool.setPassword(password); + pool.setTimeout(timeout); + + pool.init(); + + dataSource = pool; + + } + else { + dataSource = new SimpleDataSource(hostName, port, timeout, password); + } + } + + public void destroy() { + if (usePool && dataSource != null) { + try { + ((PoolableDataSource) dataSource).close(); + } catch (Exception ex) { + log.warn("Cannot properly close Rjc pool", ex); + } + dataSource = null; + } + } + + @Override + public RedisConnection getConnection() { + return postProcessConnection(new RjcConnection(dataSource.getConnection(), usePool, dbIndex)); + } + + /** + * 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 + */ + protected RjcConnection postProcessConnection(RjcConnection connection) { + return connection; + } + + @Override + public DataAccessException translateExceptionIfPossible(RuntimeException ex) { + return RjcUtils.convertRjcAccessException(ex); + } + + + /** + * Returns the Redis hostName. + * + * @return Returns the hostName + */ + public String getHostName() { + return hostName; + } + + /** + * Sets the Redis hostName. + * + * @param hostName The hostName to set. + */ + public void setHostName(String hostName) { + this.hostName = hostName; + } + + /** + * Returns the password used for authenticating with the Redis server. + * + * @return password for authentication + */ + public String getPassword() { + return password; + } + + /** + * Sets the password used for authenticating with the Redis server. + * + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + + /** + * Returns the port used to connect to the Redis instance. + * + * @return Redis port. + */ + public int getPort() { + return port; + + } + + /** + * Sets the port used to connect to the Redis instance. + * + * @param port Redis port + */ + public void setPort(int port) { + this.port = port; + } + /** + * Returns the timeout. + * + * @return Returns the timeout + */ + public int getTimeout() { + return timeout; + } + + /** + * @param timeout The timeout to set. + */ + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + /** + * Indicates the use of a connection pool. + * + * @return Returns the use of connection pooling. + */ + public boolean getUsePool() { + return usePool; + } + + /** + * Turns on or off the use of connection pooling. + * + * @param usePool The usePool to set. + */ + public void setUsePool(boolean usePool) { + this.usePool = usePool; + } + + /** + * Sets the index of the database used by this connection factory. + * Can be between 0 (default) and 15. + * + * @param index database index + */ + public void setDatabase(int index) { + Assert.isTrue(index >= 0, "invalid DB index (a positive index required)"); + this.dbIndex = index; + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java new file mode 100644 index 000000000..9c0370bb0 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java @@ -0,0 +1,41 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.idevlab.rjc.RedisException; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.data.keyvalue.redis.UncategorizedRedisException; + +/** + * Helper class featuring methods for RJC connection handling, providing support for exception translation. + * + * @author Costin Leau + */ +public abstract class RjcUtils { + + public static DataAccessException convertRjcAccessException(RuntimeException ex) { + if (ex instanceof RedisException) { + return convertRjcAccessException((RedisException) ex); + } + + return new UncategorizedRedisException("Unknown exception", ex); + } + + public static DataAccessException convertRjcAccessException(RedisException ex) { + return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); + } +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java new file mode 100644 index 000000000..db152b72c --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java @@ -0,0 +1,38 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.idevlab.rjc.ds.DataSource; +import org.idevlab.rjc.ds.RedisConnection; + +/** + * Basic data source that always returns the same connection. + * + * @author Costin Leau + */ +class SingleDataSource implements DataSource { + + private final RedisConnection connection; + + SingleDataSource(RedisConnection connection) { + this.connection = connection; + } + + @Override + public RedisConnection getConnection() { + return connection; + } +} From 897122263a2f02dcd9052bf6ddeb7ff2136b11dc Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 13:13:27 +0200 Subject: [PATCH 25/68] DATAKV-44 + almost done with the Rjc connection + arranged base64 a bit + fixed some jredis/jedis bug in the process + updated some of the RedisConnection methods --- .../DefaultStringRedisConnection.java | 6 +- .../redis/connection/RedisStringCommands.java | 4 +- .../connection/jedis/JedisConnection.java | 9 +- .../redis/connection/jedis/JedisUtils.java | 9 +- .../connection/jredis/JredisConnection.java | 8 +- .../redis/connection/jredis/JredisUtils.java | 43 +- .../redis/connection/rjc/RjcConnection.java | 2468 +++++++++++++---- .../connection/rjc/RjcConnectionFactory.java | 2 +- .../redis/connection/rjc/RjcUtils.java | 180 +- .../connection/{jredis => util}/Base64.java | 2 +- .../redis/connection/util/DecodeUtils.java | 82 + 11 files changed, 2196 insertions(+), 617 deletions(-) rename spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/{jredis => util}/Base64.java (99%) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index 3d857e3df..9db1d2af4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -156,7 +156,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.getNativeConnection(); } - public byte[] getRange(byte[] key, int start, int end) { + public byte[] getRange(byte[] key, long start, long end) { return delegate.getRange(key, start, end); } @@ -396,8 +396,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.setNX(key, value); } - public void setRange(byte[] key, int start, int end) { - delegate.setRange(key, start, end); + public void setRange(byte[] key, long start, byte[] value) { + delegate.setRange(key, start, value); } public void shutdown() { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java index ea96dfde6..d68acd0d6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java @@ -52,9 +52,9 @@ public interface RedisStringCommands { Long append(byte[] key, byte[] value); - byte[] getRange(byte[] key, int begin, int end); + byte[] getRange(byte[] key, long begin, long end); - void setRange(byte[] key, int begin, int end); + void setRange(byte[] key, long offset, byte[] value); Boolean getBit(byte[] key, long offset); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index d3f898769..5fdd3beb2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -914,7 +914,7 @@ public class JedisConnection implements RedisConnection { } @Override - public byte[] getRange(byte[] key, int start, int end) { + public byte[] getRange(byte[] key, long start, long end) { try { if (isQueueing()) { transaction.substr(key, (int) start, (int) end); @@ -1033,7 +1033,7 @@ public class JedisConnection implements RedisConnection { } @Override - public void setRange(byte[] key, int start, int end) { + public void setRange(byte[] key, long start, byte[] value) { throw new UnsupportedOperationException(); } @@ -1770,11 +1770,10 @@ public class JedisConnection implements RedisConnection { public Set zRevRangeWithScore(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.zrangeWithScores(key, (int) start, (int) end); - return null; + throw new UnsupportedOperationException(); } if (isPipelined()) { - pipeline.zrangeWithScores(key, (int) start, (int) end); + pipeline.zrangeByScoreWithScores(key, (int) start, (int) end); return null; } return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, (int) start, (int) end)); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java index bdfe315cd..b76e1d08a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java @@ -55,8 +55,8 @@ public abstract class JedisUtils { private static final String OK_CODE = "OK"; private static final String OK_MULTI_CODE = "+OK"; - private static final byte[] ONE = new byte[] { 0 }; - private static final byte[] ZERO = new byte[] { 1 }; + private static final byte[] ONE = new byte[] { 1 }; + private static final byte[] ZERO = new byte[] { 0 }; /** * Converts the given, native Jedis exception to Spring's DAO hierarchy. @@ -194,10 +194,13 @@ public abstract class JedisUtils { static Properties info(String string) { Properties info = new Properties(); + StringReader stringReader = new StringReader(string); try { - info.load(new StringReader(string)); + info.load(stringReader); } catch (Exception ex) { throw new UncategorizedRedisException("Cannot read Redis info", ex); + } finally { + stringReader.close(); } return info; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 6357ff522..63072f3ff 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -305,7 +305,7 @@ public class JredisConnection implements RedisConnection { @Override public Set keys(byte[] pattern) { try { - return JredisUtils.convertCollection(jredis.keys(JredisUtils.decode(pattern))); + return JredisUtils.convertToSet(jredis.keys(JredisUtils.decode(pattern))); } catch (Exception ex) { throw convertJredisAccessException(ex); } @@ -463,7 +463,7 @@ public class JredisConnection implements RedisConnection { } @Override - public byte[] getRange(byte[] key, int start, int end) { + public byte[] getRange(byte[] key, long start, long end) { try { return jredis.substr(JredisUtils.decode(key), start, end); } catch (Exception ex) { @@ -518,7 +518,7 @@ public class JredisConnection implements RedisConnection { } @Override - public void setRange(byte[] key, int start, int end) { + public void setRange(byte[] key, long start, byte[] value) { throw new UnsupportedOperationException(); } @@ -1032,7 +1032,7 @@ public class JredisConnection implements RedisConnection { @Override public Set hKeys(byte[] key) { try { - return new LinkedHashSet(JredisUtils.convertCollection(jredis.hkeys(JredisUtils.decode(key)))); + return new LinkedHashSet(JredisUtils.convertToSet(jredis.hkeys(JredisUtils.decode(key)))); } catch (Exception ex) { throw convertJredisAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java index 7820186db..9cb3dc146 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java @@ -17,8 +17,6 @@ package org.springframework.data.keyvalue.redis.connection.jredis; import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -34,6 +32,7 @@ import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.SortParameters; import org.springframework.data.keyvalue.redis.connection.SortParameters.Order; import org.springframework.data.keyvalue.redis.connection.SortParameters.Range; +import org.springframework.data.keyvalue.redis.connection.util.DecodeUtils; /** * Helper class featuring methods for JRedis connection handling, providing support for exception translation. @@ -82,46 +81,28 @@ public abstract class JredisUtils { } static String decode(byte[] bytes) { - return Base64.encodeToString(bytes, false); - } - - static String[] decodeMultiple(byte[]... bytes) { - String[] result = new String[bytes.length]; - for (int i = 0; i < bytes.length; i++) { - result[i] = decode(bytes[i]); - } - return result; + return DecodeUtils.decode(bytes); } static byte[] encode(String string) { - return Base64.decode(string); + return DecodeUtils.encode(string); + } + + static String[] decodeMultiple(byte[]... bytes) { + return DecodeUtils.decodeMultiple(bytes); } static Map encodeMap(Map map) { - Map result = new LinkedHashMap(map.size()); - for (Map.Entry entry : map.entrySet()) { - result.put(encode(entry.getKey()), entry.getValue()); - } - return result; - } - - static Set convertCollection(Collection keys) { - Set set = new LinkedHashSet(keys.size()); - - for (String string : keys) { - set.add(Base64.decode(string)); - } - return set; + return DecodeUtils.encodeMap(map); } static Map decodeMap(Map tuple) { - Map result = new LinkedHashMap(tuple.size()); - for (Map.Entry entry : tuple.entrySet()) { - result.put(decode(entry.getKey()), entry.getValue()); - } - return result; + return DecodeUtils.decodeMap(tuple); } + static Set convertToSet(Collection keys) { + return DecodeUtils.convertToSet(keys); + } static Sort applySortingParams(Sort jredisSort, SortParameters params, byte[] storeKey) { if (params != null) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 1983555d5..a95e5a2d3 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -15,16 +15,21 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import org.idevlab.rjc.Client; import org.idevlab.rjc.RedisException; import org.idevlab.rjc.Session; import org.idevlab.rjc.SessionFactoryImpl; +import org.idevlab.rjc.SortingParams; +import org.idevlab.rjc.ZParams; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; +import org.springframework.data.keyvalue.redis.SubscribedRedisConnectionException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnection; @@ -39,11 +44,16 @@ import org.springframework.data.keyvalue.redis.connection.Subscription; public class RjcConnection implements RedisConnection { private final int dbIndex; - private final Session session; private boolean isClosed = false; + private final Client client; + private final Session session; + private volatile Client pipeline; + public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { session = new SessionFactoryImpl(new SingleDataSource(connection)).create(); + client = new Client(connection); + this.dbIndex = dbIndex; // select the db @@ -81,629 +91,1955 @@ public class RjcConnection implements RedisConnection { } @Override - public List closePipeline() { - throw new UnsupportedOperationException(); + public boolean isQueueing() { + return client.isInMulti(); } - @Override public boolean isPipelined() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isQueueing() { - throw new UnsupportedOperationException(); + return (pipeline != null); } @Override public void openPipeline() { - throw new UnsupportedOperationException(); + if (pipeline == null) { + pipeline = client; + } } + @SuppressWarnings("unchecked") @Override - public Long del(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] echo(byte[] message) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean exists(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean expire(byte[] key, long seconds) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean expireAt(byte[] key, long unixTime) { - throw new UnsupportedOperationException(); - } - - @Override - public Set keys(byte[] pattern) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean persist(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public String ping() { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] randomKey() { - throw new UnsupportedOperationException(); - } - - @Override - public void rename(byte[] oldName, byte[] newName) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean renameNX(byte[] oldName, byte[] newName) { - throw new UnsupportedOperationException(); - } - - @Override - public void select(int dbIndex) { - throw new UnsupportedOperationException(); + public List closePipeline() { + if (pipeline != null) { + List execute = client.getAll(); + if (execute != null && !execute.isEmpty()) { + return (List) execute; + } + } + return Collections.emptyList(); } @Override public List sort(byte[] key, SortParameters params) { - throw new UnsupportedOperationException(); - } - - @Override - public Long sort(byte[] key, SortParameters params, byte[] storeKey) { - throw new UnsupportedOperationException(); - } - - @Override - public Long ttl(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public DataType type(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public void discard() { - throw new UnsupportedOperationException(); - } - - @Override - public List exec() { - throw new UnsupportedOperationException(); - } - - @Override - public void multi() { - throw new UnsupportedOperationException(); - } - - @Override - public void unwatch() { - throw new UnsupportedOperationException(); - } - - @Override - public void watch(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public Long append(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long decr(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long decrBy(byte[] key, long value) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] get(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean getBit(byte[] key, long offset) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] getRange(byte[] key, int begin, int end) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] getSet(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long incr(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long incrBy(byte[] key, long value) { - throw new UnsupportedOperationException(); - } - - @Override - public List mGet(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public void mSet(Map tuple) { - throw new UnsupportedOperationException(); - } - - @Override - public void mSetNX(Map tuple) { - throw new UnsupportedOperationException(); - } - - @Override - public void set(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public void setBit(byte[] key, long offset, boolean value) { - throw new UnsupportedOperationException(); - } - - @Override - public void setEx(byte[] key, long seconds, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean setNX(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public void setRange(byte[] key, int begin, int end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long strLen(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public List bLPop(int timeout, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public List bRPop(int timeout, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] lIndex(byte[] key, long index) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lLen(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] lPop(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lPush(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lPushX(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public List lRange(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lRem(byte[] key, long count, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public void lSet(byte[] key, long index, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public void lTrim(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] rPop(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { - throw new UnsupportedOperationException(); - } - - @Override - public Long rPush(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long rPushX(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean sAdd(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long sCard(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Set sDiff(byte[]... keys) { - throw new UnsupportedOperationException(); - } - @Override - public void sDiffStore(byte[] destKey, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public Set sInter(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public void sInterStore(byte[] destKey, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean sIsMember(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Set sMembers(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] sPop(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] sRandMember(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean sRem(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Set sUnion(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public void sUnionStore(byte[] destKey, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean zAdd(byte[] key, double score, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zCard(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zCount(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Double zIncrBy(byte[] key, double increment, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zInterStore(byte[] destKey, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRange(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScoreWithScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeWithScore(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zRank(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean zRem(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zRemRange(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zRemRangeByScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRevRange(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRevRangeWithScore(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zRevRank(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Double zScore(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zUnionStore(byte[] destKey, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean hDel(byte[] key, byte[] field) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean hExists(byte[] key, byte[] field) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] hGet(byte[] key, byte[] field) { - throw new UnsupportedOperationException(); - } - - @Override - public Map hGetAll(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long hIncrBy(byte[] key, byte[] field, long delta) { - throw new UnsupportedOperationException(); - } - - @Override - public Set hKeys(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long hLen(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public List hMGet(byte[] key, byte[]... fields) { - throw new UnsupportedOperationException(); - } - - @Override - public void hMSet(byte[] key, Map hashes) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean hSet(byte[] key, byte[] field, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public List hVals(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public void bgSave() { - throw new UnsupportedOperationException(); - } - - @Override - public void bgWriteAof() { - throw new UnsupportedOperationException(); + SortingParams sortParams = RjcUtils.convertSortParams(params); + final String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + if (sortParams != null) { + pipeline.sort(stringKey, sortParams); + } + else { + pipeline.sort(stringKey); + } + + return null; + } + return RjcUtils.convertToList((sortParams != null ? session.sort(stringKey, sortParams) + : session.sort(stringKey))); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long sort(byte[] key, SortParameters params, byte[] sortKey) { + + SortingParams sortParams = RjcUtils.convertSortParams(params); + final String stringKey = RjcUtils.decode(key); + final String stringSortKey = RjcUtils.decode(sortKey); + + try { + if (isPipelined()) { + if (sortParams != null) { + pipeline.sort(stringKey, sortParams, stringSortKey); + } + else { + pipeline.sort(stringKey, stringSortKey); + } + + return null; + } + return (sortParams != null ? session.sort(stringKey, sortParams, stringSortKey) : session.sort(stringKey, + stringSortKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public Long dbSize() { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.dbSize(); + return null; + } + return session.dbSize(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + @Override + public void flushDb() { + try { + if (isPipelined()) { + pipeline.flushDB(); + return; + } + session.flushDB(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void flushAll() { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.flushAll(); + return; + } + session.flushAll(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override - public void flushDb() { - throw new UnsupportedOperationException(); + public void bgSave() { + try { + if (isPipelined()) { + pipeline.bgsave(); + return; + } + session.bgsave(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override - public List getConfig(String pattern) { - throw new UnsupportedOperationException(); - } - - @Override - public Properties info() { - throw new UnsupportedOperationException(); - } - - @Override - public Long lastSave() { - throw new UnsupportedOperationException(); - } - - @Override - public void resetConfigStats() { - throw new UnsupportedOperationException(); + public void bgWriteAof() { + try { + if (isPipelined()) { + pipeline.bgrewriteaof(); + return; + } + session.bgrewriteaof(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void save() { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.save(); + return; + } + session.save(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List getConfig(String param) { + try { + if (isPipelined()) { + pipeline.configGet(param); + return null; + } + return session.configGet(param); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Properties info() { + try { + if (isPipelined()) { + pipeline.info(); + return null; + } + return RjcUtils.info(session.info()); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lastSave() { + try { + if (isPipelined()) { + pipeline.lastsave(); + return null; + } + return session.lastsave(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void setConfig(String param, String value) { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.configSet(param, value); + return; + } + session.configSet(param, value); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + @Override + public void resetConfigStats() { + try { + if (isPipelined()) { + pipeline.configResetStat(); + return; + } + client.configResetStat(); + client.getStatusCodeReply(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void shutdown() { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.shutdown(); + return; + } + session.shutdown(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] echo(byte[] message) { + String stringMsg = RjcUtils.decode(message); + try { + if (isPipelined()) { + pipeline.echo(stringMsg); + return null; + } + return RjcUtils.encode(session.echo(stringMsg)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public String ping() { + try { + if (isPipelined()) { + pipeline.ping(); + } + return session.ping(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long del(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + if (isPipelined()) { + pipeline.del(stringKeys); + return null; + } + return session.del(stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void discard() { + try { + if (isPipelined()) { + pipeline.discard(); + return; + } + + session.discard(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List exec() { + try { + if (isPipelined()) { + pipeline.exec(); + return null; + } + return session.exec(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean exists(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.exists(stringKey); + return null; + } + return session.exists(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean expire(byte[] key, long seconds) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.expire(stringKey, (int) seconds); + return null; + } + return session.expire(stringKey, (int) seconds); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean expireAt(byte[] key, long unixTime) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.expireAt(stringKey, unixTime); + return null; + } + return session.expireAt(stringKey, unixTime); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set keys(byte[] pattern) { + String stringKey = RjcUtils.decode(pattern); + + try { + if (isPipelined()) { + pipeline.keys(stringKey); + return null; + } + return RjcUtils.convertToSet(session.keys(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void multi() { + if (isQueueing()) { + return; + } + try { + if (isPipelined()) { + pipeline.multi(); + return; + } + session.multi(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean persist(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.persist(stringKey); + return null; + } + return session.persist(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] randomKey() { + try { + if (isPipelined()) { + pipeline.randomKey(); + return null; + } + return RjcUtils.encode(session.randomKey()); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void rename(byte[] oldName, byte[] newName) { + String stringOldKey = RjcUtils.decode(oldName); + String stringNewKey = RjcUtils.decode(newName); + + try { + if (isPipelined()) { + pipeline.rename(stringOldKey, stringNewKey); + return; + } + session.rename(stringOldKey, stringNewKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean renameNX(byte[] oldName, byte[] newName) { + String stringOldKey = RjcUtils.decode(oldName); + String stringNewKey = RjcUtils.decode(newName); + + try { + if (isPipelined()) { + pipeline.renamenx(stringOldKey, stringNewKey); + return null; + } + return session.renamenx(stringOldKey, stringNewKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void select(int dbIndex) { + try { + if (isPipelined()) { + pipeline.select(dbIndex); + return; + } + session.select(dbIndex); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long ttl(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.ttl(stringKey); + return null; + } + return session.ttl(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public DataType type(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.type(stringKey); + return null; + } + return DataType.fromCode(session.type(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void unwatch() { + try { + if (isPipelined()) { + pipeline.unwatch(); + return; + } + + session.unwatch(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void watch(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + if (isQueueing()) { + return; + } + try { + if (isPipelined()) { + pipeline.watch(stringKeys); + return; + } + else { + session.watch(stringKeys); + } + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + // + // String commands + // + + @Override + public byte[] get(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.get(stringKey); + return null; + } + + return RjcUtils.encode(session.get(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void set(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.set(stringKey, stringValue); + return; + } + session.set(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + @Override + public byte[] getSet(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.getSet(stringKey, stringValue); + return null; + } + return RjcUtils.encode(session.getSet(stringKey, stringValue)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long append(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.append(stringKey, stringValue); + return null; + } + return session.append(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List mGet(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + if (isPipelined()) { + pipeline.mget(stringKeys); + return null; + } + return RjcUtils.convertToList(session.mget(stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void mSet(Map tuples) { + String[] decodeMap = RjcUtils.flatten(tuples); + + try { + if (isPipelined()) { + pipeline.mset(decodeMap); + return; + } + session.mset(decodeMap); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void mSetNX(Map tuples) { + String[] decodeMap = RjcUtils.flatten(tuples); + + try { + + if (isPipelined()) { + pipeline.msetnx(decodeMap); + return; + } + session.msetnx(decodeMap); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void setEx(byte[] key, long time, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.setex(stringKey, (int) time, stringValue); + return; + } + session.setex(stringKey, (int) time, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean setNX(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.setnx(stringKey, stringValue); + return null; + } + return session.setnx(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] getRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.getRange(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.encode(session.getRange(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long decr(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.decr(stringKey); + return null; + } + return session.decr(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long decrBy(byte[] key, long value) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.decrBy(stringKey, (int) value); + return null; + } + return session.decrBy(stringKey, (int) value); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long incr(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.incr(stringKey); + return null; + } + return session.incr(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long incrBy(byte[] key, long value) { + String stringKey = RjcUtils.decode(key); + + + try { + if (isPipelined()) { + pipeline.incrBy(stringKey, (int) value); + return null; + } + return session.incrBy(stringKey, (int) value); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean getBit(byte[] key, long offset) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.getbit(stringKey, (int) offset); + return null; + } + return (session.getBit(stringKey, (int) offset) == 0 ? Boolean.FALSE : Boolean.TRUE); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void setBit(byte[] key, long offset, boolean value) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.setbit(stringKey, (int) offset, RjcUtils.asBit(value)); + return; + } + session.setBit(stringKey, (int) offset, RjcUtils.asBit(value)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void setRange(byte[] key, long offset, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.setRange(stringKey, (int) offset, stringValue); + return; + } + session.setRange(stringKey, (int) offset, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long strLen(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.strlen(stringKey); + return null; + } + return session.strlen(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + // + // List commands + // + + @Override + public Long lPush(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.lpush(stringKey, stringValue); + return null; + } + return session.lpush(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long rPush(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.rpush(stringKey, stringValue); + return null; + } + return session.rpush(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List bLPop(int timeout, byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + if (isPipelined()) { + pipeline.blpop(stringKeys); + return null; + } + return RjcUtils.convertToList(session.blpop(timeout, stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List bRPop(int timeout, byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + if (isPipelined()) { + pipeline.brpop(stringKeys); + return null; + } + return RjcUtils.convertToList(session.brpop(timeout, stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] lIndex(byte[] key, long index) { + String stringKey = RjcUtils.decode(key); + + + try { + if (isPipelined()) { + pipeline.lindex(stringKey, (int) index); + return null; + } + return RjcUtils.encode(session.lindex(stringKey, (int) index)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + String stringPivot = RjcUtils.decode(pivot); + Client.LIST_POSITION position = RjcUtils.convertPosition(where); + + try { + if (isPipelined()) { + pipeline.linsert(stringKey, position, stringPivot, stringValue); + return null; + } + return session.linsert(stringKey, position, stringPivot, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lLen(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.llen(stringKey); + return null; + } + return session.llen(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] lPop(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.lpop(stringKey); + return null; + } + return RjcUtils.encode(session.lpop(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List lRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.lrange(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.convertToList(session.lrange(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lRem(byte[] key, long count, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.lrem(stringKey, (int) count, stringValue); + return null; + } + return session.lrem(stringKey, (int) count, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void lSet(byte[] key, long index, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + try { + + if (isPipelined()) { + pipeline.lset(stringKey, (int) index, stringValue); + return; + } + session.lset(stringKey, (int) index, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void lTrim(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.ltrim(stringKey, (int) start, (int) end); + return; + } + session.ltrim(stringKey, (int) start, (int) end); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] rPop(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.rpop(stringKey); + return null; + } + return RjcUtils.encode(session.rpop(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { + String stringKey = RjcUtils.decode(srcKey); + String stringDest = RjcUtils.decode(dstKey); + + try { + + if (isPipelined()) { + pipeline.rpoplpush(stringKey, stringDest); + return null; + } + return RjcUtils.encode(session.rpoplpush(stringKey, stringDest)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { + String stringKey = RjcUtils.decode(srcKey); + String stringDest = RjcUtils.decode(dstKey); + + try { + if (isPipelined()) { + pipeline.brpoplpush(stringKey, stringDest, timeout); + return null; + } + return RjcUtils.encode(session.brpoplpush(stringKey, stringDest, timeout)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lPushX(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + try { + if (isPipelined()) { + pipeline.lpushx(stringKey, stringValue); + return null; + } + return session.lpushx(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long rPushX(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + try { + if (isPipelined()) { + pipeline.rpushx(stringKey, stringValue); + return null; + } + return session.rpushx(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + // + // Set commands + // + + @Override + public Boolean sAdd(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.sadd(stringKey, stringValue); + return null; + } + return session.sadd(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long sCard(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.scard(stringKey); + return null; + } + return session.scard(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set sDiff(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + + if (isPipelined()) { + pipeline.sdiff(stringKeys); + return null; + } + return RjcUtils.convertToSet(session.sdiff(stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void sDiffStore(byte[] destKey, byte[]... keys) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + + if (isPipelined()) { + pipeline.sdiffstore(stringKey, stringKeys); + return; + } + session.sdiffstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set sInter(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + try { + + if (isPipelined()) { + pipeline.sinter(stringKeys); + return null; + } + return RjcUtils.convertToSet(session.sinter(stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void sInterStore(byte[] destKey, byte[]... keys) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(keys); + try { + + if (isPipelined()) { + pipeline.sinterstore(stringKey, stringKeys); + return; + } + session.sinterstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean sIsMember(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.sismember(stringKey, stringValue); + return null; + } + return session.sismember(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set sMembers(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.smembers(stringKey); + return null; + } + return RjcUtils.convertToSet(session.smembers(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { + String stringSrc = RjcUtils.decode(srcKey); + String stringDest = RjcUtils.decode(destKey); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.smove(stringSrc, stringDest, stringValue); + return null; + } + return session.smove(stringSrc, stringDest, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] sPop(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.spop(stringKey); + return null; + } + return RjcUtils.encode(session.spop(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] sRandMember(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.srandmember(stringKey); + return null; + } + return RjcUtils.encode(session.srandmember(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean sRem(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.srem(stringKey, stringValue); + return null; + } + return session.srem(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set sUnion(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + + if (isPipelined()) { + pipeline.sunion(stringKeys); + return null; + } + return RjcUtils.convertToSet(session.sunion(stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void sUnionStore(byte[] destKey, byte[]... keys) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + + if (isPipelined()) { + pipeline.sunionstore(stringKey, stringKeys); + return; + } + session.sunionstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + // + // ZSet commands + // + + @Override + public Boolean zAdd(byte[] key, double score, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zadd(stringKey, score, stringValue); + return null; + } + return session.zadd(stringKey, score, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zCard(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.zcard(stringKey); + return null; + } + return session.zcard(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zCount(byte[] key, double min, double max) { + String stringKey = RjcUtils.decode(key); + try { + if (isPipelined()) { + pipeline.zcount(stringKey, min, max); + return null; + } + + return session.zcount(stringKey, min, max); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Double zIncrBy(byte[] key, double increment, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zincrby(stringKey, increment, stringValue); + return null; + } + return Double.valueOf(session.zincrby(stringKey, increment, stringValue)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(sets); + + ZParams zparams = RjcUtils.toZParams(aggregate, weights); + + try { + if (isPipelined()) { + pipeline.zinterstore(stringKey, zparams, stringKeys); + return null; + } + return session.zinterstore(stringKey, zparams, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zInterStore(byte[] destKey, byte[]... sets) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(sets); + try { + if (isPipelined()) { + pipeline.zinterstore(stringKey, stringKeys); + return null; + } + + return session.zinterstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.zrange(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.convertToSet(session.zrange(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeWithScore(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.zrangeWithScores(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.convertElementScore(session.zrangeWithScores(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeByScore(byte[] key, double min, double max) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zrangeByScore(stringKey, minString, maxString); + return null; + } + return RjcUtils.convertToSet(session.zrangeByScore(stringKey, minString, maxString)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeByScoreWithScore(byte[] key, double min, double max) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zrangeByScoreWithScores(stringKey, minString, maxString); + return null; + } + return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRevRangeWithScore(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + String minString = Long.toString(start); + String maxString = Long.toString(end); + + try { + + if (isPipelined()) { + pipeline.zrangeByScoreWithScores(stringKey, minString, maxString); + return null; + } + return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zrangeByScore(stringKey, minString, maxString, (int) offset, (int) count); + return null; + } + return RjcUtils.convertToSet(session.zrangeByScore(stringKey, minString, maxString, (int) offset, + (int) count)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zrangeByScoreWithScores(stringKey, minString, maxString, (int) offset, (int) count); + return null; + } + return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString, + (int) offset, (int) count)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zRank(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zrank(stringKey, stringValue); + return null; + } + return session.zrank(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean zRem(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zrem(stringKey, stringValue); + return null; + } + return session.zrem(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zRemRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + try { + if (isPipelined()) { + pipeline.zremrangeByRank(stringKey, (int) start, (int) end); + return null; + } + return session.zremrangeByRank(stringKey, (int) start, (int) end); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zRemRangeByScore(byte[] key, double min, double max) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zremrangeByScore(stringKey, minString, maxString); + return null; + } + return session.zremrangeByScore(stringKey, minString, maxString); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRevRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.zrevrange(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.convertToSet(session.zrevrange(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zRevRank(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zrevrank(stringKey, stringValue); + return null; + } + return session.zrevrank(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Double zScore(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zscore(stringKey, stringValue); + return null; + } + return Double.valueOf(session.zscore(stringKey, stringValue)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(destKey); + + ZParams zparams = RjcUtils.toZParams(aggregate, weights); + + try { + if (isPipelined()) { + pipeline.zunionstore(stringKey, zparams, stringKeys); + return null; + } + return session.zunionstore(stringKey, zparams, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zUnionStore(byte[] destKey, byte[]... sets) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(sets); + + try { + if (isPipelined()) { + pipeline.zunionstore(stringKey, stringKeys); + return null; + } + return session.zunionstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + // + // Hash commands + // + + @Override + public Boolean hSet(byte[] key, byte[] field, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.hset(stringKey, stringField, stringValue); + return null; + } + return session.hset(stringKey, stringField, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.hsetnx(stringKey, stringField, stringValue); + return null; + } + return session.hsetnx(stringKey, stringField, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean hDel(byte[] key, byte[] field) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + + try { + if (isPipelined()) { + pipeline.hdel(stringKey, stringField); + return null; + } + return session.hdel(stringKey, stringField); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean hExists(byte[] key, byte[] field) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + + try { + if (isPipelined()) { + pipeline.hexists(stringKey, stringField); + return null; + } + return session.hexists(stringKey, stringField); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] hGet(byte[] key, byte[] field) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + + try { + if (isPipelined()) { + pipeline.hget(stringKey, stringField); + return null; + } + return RjcUtils.encode(session.hget(stringKey, stringField)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Map hGetAll(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.hgetAll(stringKey); + return null; + } + return RjcUtils.encodeMap(session.hgetAll(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long hIncrBy(byte[] key, byte[] field, long delta) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + + try { + if (isPipelined()) { + pipeline.hincrBy(stringKey, stringField, (int) delta); + return null; + } + return session.hincrBy(stringKey, stringField, (int) delta); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set hKeys(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + if (isPipelined()) { + pipeline.hkeys(stringKey); + return null; + } + return RjcUtils.convertToSet(session.hkeys(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long hLen(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + if (isPipelined()) { + pipeline.hlen(stringKey); + return null; + } + return session.hlen(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List hMGet(byte[] key, byte[]... fields) { + String stringKey = RjcUtils.decode(key); + String[] stringKeys = RjcUtils.decodeMultiple(fields); + + try { + if (isPipelined()) { + pipeline.hmget(stringKey, stringKeys); + return null; + } + return RjcUtils.convertToList(session.hmget(stringKey, stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void hMSet(byte[] key, Map tuple) { + String stringKey = RjcUtils.decode(key); + Map stringTuple = RjcUtils.decodeMap(tuple); + + try { + if (isPipelined()) { + pipeline.hmset(stringKey, stringTuple); + return; + } + session.hmset(stringKey, stringTuple); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List hVals(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.hvals(stringKey); + return null; + } + return RjcUtils.convertToList(session.hvals(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + // + // Pub/Sub functionality + // + @Override + public Long publish(byte[] channel, byte[] message) { + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + if (isPipelined()) { + throw new UnsupportedOperationException(); + } + return session.publish(channel, message); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public Subscription getSubscription() { - throw new UnsupportedOperationException(); + return subscription; } @Override public boolean isSubscribed() { - throw new UnsupportedOperationException(); + return (subscription != null && subscription.isAlive()); } @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { - throw new UnsupportedOperationException(); - } + String[] stringKeys = RjcUtils.decodeMultiple(patterns); - @Override - public Long publish(byte[] channel, byte[] message) { - throw new UnsupportedOperationException(); + if (isSubscribed()) { + throw new SubscribedRedisConnectionException( + "Connection already subscribed; use the connection Subscription to cancel or add new channels"); + } + + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + if (isPipelined()) { + throw new UnsupportedOperationException(); + } + + BinarysessionPubSub sessionPubSub = RjcUtils.adaptPubSub(listener); + + subscription = new sessionSubscription(listener, sessionPubSub, null, patterns); + session.psubscribe(sessionPubSub, patterns); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void subscribe(MessageListener listener, byte[]... channels) { - throw new UnsupportedOperationException(); + String[] stringKeys = RjcUtils.decodeMultiple(channels); + + if (isSubscribed()) { + throw new SubscribedRedisConnectionException( + "Connection already subscribed; use the connection Subscription to cancel or add new channels"); + } + + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + if (isPipelined()) { + throw new UnsupportedOperationException(); + } + + BinarysessionPubSub sessionPubSub = RjcUtils.adaptPubSub(listener); + + subscription = new sessionSubscription(listener, sessionPubSub, channels, null); + session.subscribe(sessionPubSub, channels); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } -} + private void checkSubscription() { + if (isSubscribed()) { + throw new SubscribedRedisConnectionException("Cannot execute command - connection is subscribed"); + } + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java index 97f1c65cd..5c149f107 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java @@ -87,7 +87,7 @@ public class RjcConnectionFactory implements InitializingBean, DisposableBean, R @Override public RedisConnection getConnection() { - return postProcessConnection(new RjcConnection(dataSource.getConnection(), usePool, dbIndex)); + return postProcessConnection(new RjcConnection(dataSource.getConnection(), dbIndex)); } /** diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java index 9c0370bb0..50c92316f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java @@ -15,10 +15,33 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; +import java.io.StringReader; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.idevlab.rjc.ElementScore; import org.idevlab.rjc.RedisException; +import org.idevlab.rjc.SortingParams; +import org.idevlab.rjc.ZParams; +import org.idevlab.rjc.Client.LIST_POSITION; import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.keyvalue.redis.UncategorizedRedisException; +import org.springframework.data.keyvalue.redis.connection.DataType; +import org.springframework.data.keyvalue.redis.connection.DefaultTuple; +import org.springframework.data.keyvalue.redis.connection.SortParameters; +import org.springframework.data.keyvalue.redis.connection.RedisListCommands.Position; +import org.springframework.data.keyvalue.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.keyvalue.redis.connection.RedisZSetCommands.Tuple; +import org.springframework.data.keyvalue.redis.connection.SortParameters.Order; +import org.springframework.data.keyvalue.redis.connection.SortParameters.Range; +import org.springframework.data.keyvalue.redis.connection.util.DecodeUtils; + /** * Helper class featuring methods for RJC connection handling, providing support for exception translation. @@ -27,6 +50,10 @@ import org.springframework.data.keyvalue.redis.UncategorizedRedisException; */ public abstract class RjcUtils { + private static final String ONE = "1"; + private static final String ZERO = "0"; + + public static DataAccessException convertRjcAccessException(RuntimeException ex) { if (ex instanceof RedisException) { return convertRjcAccessException((RedisException) ex); @@ -38,4 +65,155 @@ public abstract class RjcUtils { public static DataAccessException convertRjcAccessException(RedisException ex) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } -} + + static DataType convertDataType(String type) { + if ("string".equals(type)) { + return DataType.STRING; + } + else if ("list".equals(type)) { + return DataType.LIST; + } + else if ("set".equals(type)) { + return DataType.SET; + } + else if ("zset".equals(type)) { + return DataType.ZSET; + } + else if ("hash".equals(type)) { + return DataType.HASH; + } + else if ("none".equals(type)) { + return DataType.NONE; + } + + return null; + } + + static String decode(byte[] bytes) { + return DecodeUtils.decode(bytes); + } + + static byte[] encode(String string) { + return DecodeUtils.encode(string); + } + + static String[] decodeMultiple(byte[]... bytes) { + return DecodeUtils.decodeMultiple(bytes); + } + + static String[] flatten(Map tuple) { + String[] result = new String[tuple.size() * 2]; + int index = 0; + for (Map.Entry entry : tuple.entrySet()) { + result[index++] = decode(entry.getKey()); + result[index++] = decode(entry.getValue()); + } + return result; + + } + + static Set convertToSet(Collection keys) { + if (keys == null) { + return null; + } + + return DecodeUtils.convertToSet(keys); + } + + static List convertToList(Collection keys) { + if (keys == null) { + return null; + } + return DecodeUtils.convertToList(keys); + } + + static SortingParams convertSortParams(SortParameters params) { + SortingParams rjcSort = null; + + if (params != null) { + rjcSort = new SortingParams(); + + byte[] byPattern = params.getByPattern(); + if (byPattern != null) { + rjcSort.by(DecodeUtils.decode(byPattern)); + } + byte[][] getPattern = params.getGetPattern(); + + if (getPattern != null && getPattern.length > 0) { + for (byte[] bs : getPattern) { + rjcSort.get(DecodeUtils.decode(bs)); + } + } + Range limit = params.getLimit(); + if (limit != null) { + rjcSort.limit((int) limit.getStart(), (int) limit.getCount()); + } + Order order = params.getOrder(); + if (order != null && order.equals(Order.DESC)) { + rjcSort.desc(); + } + Boolean isAlpha = params.isAlphabetic(); + if (isAlpha != null && isAlpha) { + rjcSort.alpha(); + } + } + return rjcSort; + } + + static Properties info(String string) { + Properties info = new Properties(); + StringReader stringReader = new StringReader(string); + try { + info.load(stringReader); + } catch (Exception ex) { + throw new UncategorizedRedisException("Cannot read Redis info", ex); + } finally { + stringReader.close(); + } + return info; + } + + static String asBit(boolean value) { + return (value ? ONE : ZERO); + } + + static LIST_POSITION convertPosition(Position where) { + switch (where) { + case BEFORE: + return LIST_POSITION.BEFORE; + + case AFTER: + return LIST_POSITION.AFTER; + } + return null; + } + + static ZParams toZParams(Aggregate aggregate, int[] weights) { + return new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name())); + } + + static Set convertElementScore(List tuples) { + Set value = new LinkedHashSet(tuples.size()); + for (ElementScore tuple : tuples) { + value.add(new DefaultTuple(encode(tuple.getElement()), Double.valueOf(tuple.getScore()))); + } + + return value; + } + + static Map encodeMap(Map map) { + Map result = new LinkedHashMap(map.size()); + for (Map.Entry entry : map.entrySet()) { + result.put(encode(entry.getKey()), encode(entry.getValue())); + } + return result; + } + + static Map decodeMap(Map map) { + Map result = new LinkedHashMap(map.size()); + for (Map.Entry entry : map.entrySet()) { + result.put(decode(entry.getKey()), decode(entry.getValue())); + } + return result; + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/Base64.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/Base64.java similarity index 99% rename from spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/Base64.java rename to spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/Base64.java index 6feb3a4d6..3e99472d6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/Base64.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/Base64.java @@ -1,4 +1,4 @@ -package org.springframework.data.keyvalue.redis.connection.jredis; +package org.springframework.data.keyvalue.redis.connection.util; import java.util.Arrays; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java new file mode 100644 index 000000000..d3588856c --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java @@ -0,0 +1,82 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Simple class containing various decoding utilities. + * + * @author Costin Leau + */ +public abstract class DecodeUtils { + + public static String decode(byte[] bytes) { + return Base64.encodeToString(bytes, false); + } + + public static String[] decodeMultiple(byte[]... bytes) { + String[] result = new String[bytes.length]; + for (int i = 0; i < bytes.length; i++) { + result[i] = decode(bytes[i]); + } + return result; + } + + public static byte[] encode(String string) { + return Base64.decode(string); + } + + public static Map encodeMap(Map map) { + Map result = new LinkedHashMap(map.size()); + for (Map.Entry entry : map.entrySet()) { + result.put(encode(entry.getKey()), entry.getValue()); + } + return result; + } + + public static Map decodeMap(Map tuple) { + Map result = new LinkedHashMap(tuple.size()); + for (Map.Entry entry : tuple.entrySet()) { + result.put(decode(entry.getKey()), entry.getValue()); + } + return result; + } + + public static Set convertToSet(Collection keys) { + Set set = new LinkedHashSet(keys.size()); + + for (String string : keys) { + set.add(Base64.decode(string)); + } + return set; + } + + public static List convertToList(Collection keys) { + List set = new ArrayList(keys.size()); + + for (String string : keys) { + set.add(Base64.decode(string)); + } + return set; + } +} \ No newline at end of file From 79631fb6ecaabe7d9177fe67ee2a81dc54a0d0c5 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 14:48:49 +0200 Subject: [PATCH 26/68] DATAKV-46 + wrap up RJC connector with pub sub support --- .../redis/connection/rjc/RjcConnection.java | 25 +-- .../connection/rjc/RjcMessageListener.java | 45 ++++++ .../redis/connection/rjc/RjcSubscription.java | 149 ++++++++++++++++++ 3 files changed, 207 insertions(+), 12 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index a95e5a2d3..93e452427 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -27,6 +27,7 @@ import org.idevlab.rjc.Session; import org.idevlab.rjc.SessionFactoryImpl; import org.idevlab.rjc.SortingParams; import org.idevlab.rjc.ZParams; +import org.idevlab.rjc.message.RedisNodeSubscriber; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; import org.springframework.data.keyvalue.redis.SubscribedRedisConnectionException; @@ -50,9 +51,14 @@ public class RjcConnection implements RedisConnection { private final Session session; private volatile Client pipeline; + private volatile RjcSubscription subscription; + private volatile RedisNodeSubscriber subscriber; + public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { - session = new SessionFactoryImpl(new SingleDataSource(connection)).create(); + SingleDataSource connectionDataSource = new SingleDataSource(connection); + session = new SessionFactoryImpl().create(); client = new Client(connection); + subscriber = new RedisNodeSubscriber(connectionDataSource); this.dbIndex = dbIndex; @@ -73,6 +79,7 @@ public class RjcConnection implements RedisConnection { public void close() throws DataAccessException { isClosed = true; try { + subscriber.close(); session.close(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -1969,7 +1976,7 @@ public class RjcConnection implements RedisConnection { if (isPipelined()) { throw new UnsupportedOperationException(); } - return session.publish(channel, message); + return session.publish(RjcUtils.decode(channel), RjcUtils.decode(message)); } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -1987,8 +1994,6 @@ public class RjcConnection implements RedisConnection { @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { - String[] stringKeys = RjcUtils.decodeMultiple(patterns); - if (isSubscribed()) { throw new SubscribedRedisConnectionException( "Connection already subscribed; use the connection Subscription to cancel or add new channels"); @@ -2002,10 +2007,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - BinarysessionPubSub sessionPubSub = RjcUtils.adaptPubSub(listener); + subscription = new RjcSubscription(listener, subscriber); + subscription.pSubscribe(patterns); - subscription = new sessionSubscription(listener, sessionPubSub, null, patterns); - session.psubscribe(sessionPubSub, patterns); } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -2013,8 +2017,6 @@ public class RjcConnection implements RedisConnection { @Override public void subscribe(MessageListener listener, byte[]... channels) { - String[] stringKeys = RjcUtils.decodeMultiple(channels); - if (isSubscribed()) { throw new SubscribedRedisConnectionException( "Connection already subscribed; use the connection Subscription to cancel or add new channels"); @@ -2028,10 +2030,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - BinarysessionPubSub sessionPubSub = RjcUtils.adaptPubSub(listener); + subscription = new RjcSubscription(listener, subscriber); + subscription.pSubscribe(channels); - subscription = new sessionSubscription(listener, sessionPubSub, channels, null); - session.subscribe(sessionPubSub, channels); } catch (Exception ex) { throw convertRjcAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java new file mode 100644 index 000000000..c16a2040f --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java @@ -0,0 +1,45 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.idevlab.rjc.message.MessageListener; +import org.idevlab.rjc.message.PMessageListener; +import org.springframework.data.keyvalue.redis.connection.DefaultMessage; + +/** + * Message listener adapter for RJC library. + * + * @author Costin Leau + */ +class RjcMessageListener implements MessageListener, PMessageListener { + + private final org.springframework.data.keyvalue.redis.connection.MessageListener listener; + + RjcMessageListener(org.springframework.data.keyvalue.redis.connection.MessageListener messageListener) { + this.listener = messageListener; + } + + @Override + public void onMessage(String channel, String message) { + listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), null); + } + + @Override + public void onMessage(String pattern, String channel, String message) { + listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), + RjcUtils.encode(pattern)); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java new file mode 100644 index 000000000..a1075a120 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java @@ -0,0 +1,149 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import java.util.ArrayList; +import java.util.Collection; + +import org.idevlab.rjc.message.RedisSubscriber; +import org.springframework.data.keyvalue.redis.connection.MessageListener; +import org.springframework.data.keyvalue.redis.connection.Subscription; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; + +/** + * Message subscription on top of RJC. + * + * @author Costin Leau + */ +class RjcSubscription implements Subscription { + + private final MessageListener listener; + private final RedisSubscriber subscriber; + private final RjcMessageListener listenerAdapter; + + private final Collection channels = new ArrayList(2); + private final Collection patterns = new ArrayList(2); + + RjcSubscription(MessageListener listener, RedisSubscriber subscriber) { + Assert.notNull(listener); + this.listener = listener; + this.subscriber = subscriber; + this.listenerAdapter = new RjcMessageListener(listener); + } + + @Override + public Collection getChannels() { + synchronized (channels) { + return new ArrayList(channels); + } + } + + @Override + public MessageListener getListener() { + return listener; + } + + @Override + public Collection getPatterns() { + synchronized (patterns) { + return new ArrayList(patterns); + } + } + + @Override + public void pSubscribe(byte[]... patterns) { + Assert.notEmpty(patterns, "at least one pattern required"); + + synchronized (this.patterns) { + for (byte[] bs : patterns) { + this.patterns.add(bs); + } + } + + for (String pattern : RjcUtils.decodeMultiple(patterns)) { + subscriber.psubscribe(pattern, listenerAdapter); + } + } + + @Override + public void pUnsubscribe() { + pUnsubscribe(null); + + synchronized (patterns) { + patterns.clear(); + } + } + + @Override + public void pUnsubscribe(byte[]... patterns) { + if (ObjectUtils.isEmpty(patterns)) { + patterns = this.patterns.toArray(new byte[this.patterns.size()][]); + } + + synchronized (this.patterns) { + for (byte[] bs : patterns) { + this.patterns.remove(bs); + } + } + + subscriber.punsubscribe(RjcUtils.decodeMultiple(patterns)); + } + + @Override + public void subscribe(byte[]... channels) { + Assert.notEmpty(channels, "at least one channel required"); + + synchronized (this.channels) { + for (byte[] bs : channels) { + this.channels.add(bs); + } + } + + for (String channel : RjcUtils.decodeMultiple(channels)) { + subscriber.subscribe(channel, listenerAdapter); + } + } + + @Override + public void unsubscribe() { + unsubscribe(null); + + synchronized (patterns) { + patterns.clear(); + } + } + + @Override + public void unsubscribe(byte[]... channels) { + if (ObjectUtils.isEmpty(channels)) { + channels = this.channels.toArray(new byte[this.channels.size()][]); + } + + synchronized (this.channels) { + for (byte[] bs : channels) { + this.channels.remove(bs); + } + } + + subscriber.punsubscribe(RjcUtils.decodeMultiple(channels)); + } + + @Override + public boolean isAlive() { + return (!channels.isEmpty() || !patterns.isEmpty()); + } +} \ No newline at end of file From a1a562c7863153ae29d634d34d6600af6b034ab2 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 14:49:09 +0200 Subject: [PATCH 27/68] update value get/set operations --- .../DefaultStringRedisConnection.java | 6 ++--- .../connection/StringRedisConnection.java | 4 ++-- .../redis/core/BoundValueOperations.java | 4 ++-- .../core/DefaultBoundValueOperations.java | 6 ++--- .../redis/core/DefaultValueOperations.java | 7 +++--- .../keyvalue/redis/core/RedisTemplate.java | 23 +++++++++++++------ .../keyvalue/redis/core/ValueOperations.java | 4 ++-- 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index 9db1d2af4..85799bca9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -683,7 +683,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } @Override - public String getRange(String key, int start, int end) { + public String getRange(String key, long start, long end) { return deserialize(delegate.getRange(serialize(key), start, end)); } @@ -919,8 +919,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } @Override - public void setRange(String key, int start, int end) { - delegate.setRange(serialize(key), start, end); + public void setRange(String key, long offset, String value) { + delegate.setRange(serialize(key), offset, serialize(value)); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java index 7622c3b56..53517c8ea 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java @@ -95,9 +95,9 @@ public interface StringRedisConnection extends RedisConnection { Long append(String key, String value); - String getRange(String key, int start, int end); + String getRange(String key, long start, long end); - void setRange(String key, int start, int end); + void setRange(String key, long offset, String value); Boolean getBit(String key, long offset); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java index 6e0450465..18f0fd3a9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java @@ -40,9 +40,9 @@ public interface BoundValueOperations extends BoundKeyOperations { Integer append(String value); - String get(int start, int end); + String get(long start, long end); - void set(int start, int end); + void set(long offset, V value); Long size(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java index c808847d5..f8691ffec 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java @@ -58,7 +58,7 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp } @Override - public String get(int start, int end) { + public String get(long start, long end) { return ops.get(getKey(), start, end); } @@ -78,8 +78,8 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp } @Override - public void set(int start, int end) { - ops.set(getKey(), start, end); + public void set(long offset, V value) { + ops.set(getKey(), offset, null); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java index 37172140a..3d1b6c5f4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java @@ -96,7 +96,7 @@ class DefaultValueOperations extends AbstractOperations implements V } @Override - public String get(K key, final int start, final int end) { + public String get(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); byte[] rawReturn = execute(new RedisCallback() { @@ -217,13 +217,14 @@ class DefaultValueOperations extends AbstractOperations implements V @Override - public void set(K key, final int start, final int end) { + public void set(K key, final long offset, V value) { final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); execute(new RedisCallback() { @Override public Object doInRedis(RedisConnection connection) { - connection.setRange(rawKey, start, end); + connection.setRange(rawKey, offset, rawValue); return null; } }, true); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 6358593c5..e91bfc499 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -223,13 +223,22 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return execute(new RedisCallback>() { public List doInRedis(RedisConnection connection) throws DataAccessException { connection.openPipeline(); - Object result = action.doInRedis(connection); - if (result != null) { - throw new InvalidDataAccessApiUsageException( - "Callback cannot returned a non-null value as it gets overwritten by the pipeline"); + boolean pipelinedClosed = false; + try { + Object result = action.doInRedis(connection); + if (result != null) { + throw new InvalidDataAccessApiUsageException( + "Callback cannot returned a non-null value as it gets overwritten by the pipeline"); + } + List pipeline = connection.closePipeline(); + pipelinedClosed = true; + return SerializationUtils.deserialize(pipeline, resultSerializer); + + } finally { + if (!pipelinedClosed) { + connection.closePipeline(); + } } - List pipeline = connection.closePipeline(); - return SerializationUtils.deserialize(pipeline, resultSerializer); } }); } @@ -377,7 +386,7 @@ 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}. * - * @see ValueOperations#get(Object, int, int) + * @see ValueOperations#get(Object, long, long) * @param stringSerializer The stringValueSerializer to set. */ public void setStringSerializer(RedisSerializer stringSerializer) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java index 3fd581ad0..479bebd5b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java @@ -47,9 +47,9 @@ public interface ValueOperations { Integer append(K key, String value); - String get(K key, int start, int end); + String get(K key, long start, long end); - void set(K key, int start, int end); + void set(K key, long offset, V value); Long size(K key); From c385bc4d7c6afbdb3c7b6fe1fe37d5825548991d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 09:49:07 +0200 Subject: [PATCH 28/68] DATAKV-46 + add initial Rjc connection/connection factory support --- spring-data-redis/pom.xml | 23 +- .../jedis/JedisConnectionFactory.java | 2 +- .../connection/jredis/JredisConnection.java | 6 +- .../redis/connection/rjc/RjcConnection.java | 709 ++++++++++++++++++ .../connection/rjc/RjcConnectionFactory.java | 209 ++++++ .../redis/connection/rjc/RjcUtils.java | 41 + .../connection/rjc/SingleDataSource.java | 38 + 7 files changed, 1011 insertions(+), 17 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index 2f683aefe..c0fe69d97 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -16,8 +16,10 @@ "[3.0.0, 4.0.0)" 03122010 1.5.2 + 0.6.2 "[1.0.0,2.0.0)" "[1.6, 2.0.0)" + "[0.6.2, 0.6.2]" @@ -135,27 +137,18 @@ compile - org.jredis jredis-anthonylauzon ${jredis.ver} compile + + org.idevlab + rjc + ${rjc.ver} + compile + diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java index 099067bbd..51f326a39 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java @@ -34,7 +34,7 @@ import redis.clients.jedis.JedisShardInfo; import redis.clients.jedis.Protocol; /** - * Connection factory using creating Jedis based connections. + * Connection factory creating Jedis based connections. * * @author Costin Leau */ diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index dca7e829d..6357ff522 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -81,7 +81,11 @@ public class JredisConnection implements RedisConnection { // don't actually close the connection // if a pool is used if (!isPool) { - jredis.quit(); + try { + jredis.quit(); + } catch (Exception ex) { + throw convertJredisAccessException(ex); + } } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java new file mode 100644 index 000000000..1983555d5 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -0,0 +1,709 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.idevlab.rjc.RedisException; +import org.idevlab.rjc.Session; +import org.idevlab.rjc.SessionFactoryImpl; +import org.springframework.dao.DataAccessException; +import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; +import org.springframework.data.keyvalue.redis.connection.DataType; +import org.springframework.data.keyvalue.redis.connection.MessageListener; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; +import org.springframework.data.keyvalue.redis.connection.SortParameters; +import org.springframework.data.keyvalue.redis.connection.Subscription; + +/** + * {@code RedisConnection} implementation on top of rjc library. + * + * @author Costin Leau + */ +public class RjcConnection implements RedisConnection { + + private final int dbIndex; + private final Session session; + private boolean isClosed = false; + + public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { + session = new SessionFactoryImpl(new SingleDataSource(connection)).create(); + this.dbIndex = dbIndex; + + // select the db + if (dbIndex > 0) { + select(dbIndex); + } + } + + protected DataAccessException convertRjcAccessException(Exception ex) { + if (ex instanceof RedisException) { + return RjcUtils.convertRjcAccessException((RedisException) ex); + } + return new UncategorizedKeyvalueStoreException("Unknown rjc exception", ex); + } + + @Override + public void close() throws DataAccessException { + isClosed = true; + try { + session.close(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + @Override + public boolean isClosed() { + return isClosed; + } + + @Override + public Session getNativeConnection() { + return session; + } + + @Override + public List closePipeline() { + throw new UnsupportedOperationException(); + } + + + @Override + public boolean isPipelined() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isQueueing() { + throw new UnsupportedOperationException(); + } + + @Override + public void openPipeline() { + throw new UnsupportedOperationException(); + } + + @Override + public Long del(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] echo(byte[] message) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean exists(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean expire(byte[] key, long seconds) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean expireAt(byte[] key, long unixTime) { + throw new UnsupportedOperationException(); + } + + @Override + public Set keys(byte[] pattern) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean persist(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public String ping() { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] randomKey() { + throw new UnsupportedOperationException(); + } + + @Override + public void rename(byte[] oldName, byte[] newName) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean renameNX(byte[] oldName, byte[] newName) { + throw new UnsupportedOperationException(); + } + + @Override + public void select(int dbIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public List sort(byte[] key, SortParameters params) { + throw new UnsupportedOperationException(); + } + + @Override + public Long sort(byte[] key, SortParameters params, byte[] storeKey) { + throw new UnsupportedOperationException(); + } + + @Override + public Long ttl(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public DataType type(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public void discard() { + throw new UnsupportedOperationException(); + } + + @Override + public List exec() { + throw new UnsupportedOperationException(); + } + + @Override + public void multi() { + throw new UnsupportedOperationException(); + } + + @Override + public void unwatch() { + throw new UnsupportedOperationException(); + } + + @Override + public void watch(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public Long append(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long decr(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long decrBy(byte[] key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] get(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean getBit(byte[] key, long offset) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] getRange(byte[] key, int begin, int end) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] getSet(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long incr(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long incrBy(byte[] key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public List mGet(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void mSet(Map tuple) { + throw new UnsupportedOperationException(); + } + + @Override + public void mSetNX(Map tuple) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setBit(byte[] key, long offset, boolean value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setEx(byte[] key, long seconds, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean setNX(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public void setRange(byte[] key, int begin, int end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long strLen(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public List bLPop(int timeout, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public List bRPop(int timeout, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] lIndex(byte[] key, long index) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lLen(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] lPop(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lPush(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lPushX(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public List lRange(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long lRem(byte[] key, long count, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public void lSet(byte[] key, long index, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public void lTrim(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] rPop(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { + throw new UnsupportedOperationException(); + } + + @Override + public Long rPush(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long rPushX(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean sAdd(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long sCard(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Set sDiff(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void sDiffStore(byte[] destKey, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public Set sInter(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void sInterStore(byte[] destKey, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean sIsMember(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Set sMembers(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] sPop(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] sRandMember(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean sRem(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Set sUnion(byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public void sUnionStore(byte[] destKey, byte[]... keys) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean zAdd(byte[] key, double score, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zCard(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zCount(byte[] key, double min, double max) { + throw new UnsupportedOperationException(); + } + + @Override + public Double zIncrBy(byte[] key, double increment, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zInterStore(byte[] destKey, byte[]... sets) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRange(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeByScore(byte[] key, double min, double max) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeByScoreWithScore(byte[] key, double min, double max) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRangeWithScore(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zRank(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean zRem(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zRemRange(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zRemRangeByScore(byte[] key, double min, double max) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRevRange(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Set zRevRangeWithScore(byte[] key, long begin, long end) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zRevRank(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Double zScore(byte[] key, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zUnionStore(byte[] destKey, byte[]... sets) { + throw new UnsupportedOperationException(); + } + + @Override + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean hDel(byte[] key, byte[] field) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean hExists(byte[] key, byte[] field) { + throw new UnsupportedOperationException(); + } + + @Override + public byte[] hGet(byte[] key, byte[] field) { + throw new UnsupportedOperationException(); + } + + @Override + public Map hGetAll(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long hIncrBy(byte[] key, byte[] field, long delta) { + throw new UnsupportedOperationException(); + } + + @Override + public Set hKeys(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public Long hLen(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public List hMGet(byte[] key, byte[]... fields) { + throw new UnsupportedOperationException(); + } + + @Override + public void hMSet(byte[] key, Map hashes) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean hSet(byte[] key, byte[] field, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { + throw new UnsupportedOperationException(); + } + + @Override + public List hVals(byte[] key) { + throw new UnsupportedOperationException(); + } + + @Override + public void bgSave() { + throw new UnsupportedOperationException(); + } + + @Override + public void bgWriteAof() { + throw new UnsupportedOperationException(); + } + + @Override + public Long dbSize() { + throw new UnsupportedOperationException(); + } + + @Override + public void flushAll() { + throw new UnsupportedOperationException(); + } + + @Override + public void flushDb() { + throw new UnsupportedOperationException(); + } + + @Override + public List getConfig(String pattern) { + throw new UnsupportedOperationException(); + } + + @Override + public Properties info() { + throw new UnsupportedOperationException(); + } + + @Override + public Long lastSave() { + throw new UnsupportedOperationException(); + } + + @Override + public void resetConfigStats() { + throw new UnsupportedOperationException(); + } + + @Override + public void save() { + throw new UnsupportedOperationException(); + } + + @Override + public void setConfig(String param, String value) { + throw new UnsupportedOperationException(); + } + + @Override + public void shutdown() { + throw new UnsupportedOperationException(); + } + + @Override + public Subscription getSubscription() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isSubscribed() { + throw new UnsupportedOperationException(); + } + + @Override + public void pSubscribe(MessageListener listener, byte[]... patterns) { + throw new UnsupportedOperationException(); + } + + @Override + public Long publish(byte[] channel, byte[] message) { + throw new UnsupportedOperationException(); + } + + @Override + public void subscribe(MessageListener listener, byte[]... channels) { + throw new UnsupportedOperationException(); + } + +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java new file mode 100644 index 000000000..97f1c65cd --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java @@ -0,0 +1,209 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.idevlab.rjc.ds.DataSource; +import org.idevlab.rjc.ds.PoolableDataSource; +import org.idevlab.rjc.ds.SimpleDataSource; +import org.idevlab.rjc.protocol.Protocol; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.dao.DataAccessException; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; +import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; +import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.util.Assert; + +/** + * Connection factory creating rjc based connections. + * + * @author Costin Leau + */ +public class RjcConnectionFactory implements InitializingBean, DisposableBean, RedisConnectionFactory { + + private final static Log log = LogFactory.getLog(JedisConnectionFactory.class); + + private String hostName = "localhost"; + private int port = Protocol.DEFAULT_PORT; + private int timeout = Protocol.DEFAULT_TIMEOUT; + private String password; + + private boolean usePool = true; + private int dbIndex = 0; + private DataSource dataSource; + + + /** + * Constructs a new RjcConnectionFactory instance + * with default settings (default connection pooling, no shard information). + */ + public RjcConnectionFactory() { + } + + + public void afterPropertiesSet() { + if (usePool) { + PoolableDataSource pool = new PoolableDataSource(); + pool.setHost(hostName); + pool.setPort(port); + pool.setPassword(password); + pool.setTimeout(timeout); + + pool.init(); + + dataSource = pool; + + } + else { + dataSource = new SimpleDataSource(hostName, port, timeout, password); + } + } + + public void destroy() { + if (usePool && dataSource != null) { + try { + ((PoolableDataSource) dataSource).close(); + } catch (Exception ex) { + log.warn("Cannot properly close Rjc pool", ex); + } + dataSource = null; + } + } + + @Override + public RedisConnection getConnection() { + return postProcessConnection(new RjcConnection(dataSource.getConnection(), usePool, dbIndex)); + } + + /** + * 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 + */ + protected RjcConnection postProcessConnection(RjcConnection connection) { + return connection; + } + + @Override + public DataAccessException translateExceptionIfPossible(RuntimeException ex) { + return RjcUtils.convertRjcAccessException(ex); + } + + + /** + * Returns the Redis hostName. + * + * @return Returns the hostName + */ + public String getHostName() { + return hostName; + } + + /** + * Sets the Redis hostName. + * + * @param hostName The hostName to set. + */ + public void setHostName(String hostName) { + this.hostName = hostName; + } + + /** + * Returns the password used for authenticating with the Redis server. + * + * @return password for authentication + */ + public String getPassword() { + return password; + } + + /** + * Sets the password used for authenticating with the Redis server. + * + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + + /** + * Returns the port used to connect to the Redis instance. + * + * @return Redis port. + */ + public int getPort() { + return port; + + } + + /** + * Sets the port used to connect to the Redis instance. + * + * @param port Redis port + */ + public void setPort(int port) { + this.port = port; + } + /** + * Returns the timeout. + * + * @return Returns the timeout + */ + public int getTimeout() { + return timeout; + } + + /** + * @param timeout The timeout to set. + */ + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + /** + * Indicates the use of a connection pool. + * + * @return Returns the use of connection pooling. + */ + public boolean getUsePool() { + return usePool; + } + + /** + * Turns on or off the use of connection pooling. + * + * @param usePool The usePool to set. + */ + public void setUsePool(boolean usePool) { + this.usePool = usePool; + } + + /** + * Sets the index of the database used by this connection factory. + * Can be between 0 (default) and 15. + * + * @param index database index + */ + public void setDatabase(int index) { + Assert.isTrue(index >= 0, "invalid DB index (a positive index required)"); + this.dbIndex = index; + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java new file mode 100644 index 000000000..9c0370bb0 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java @@ -0,0 +1,41 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.idevlab.rjc.RedisException; +import org.springframework.dao.DataAccessException; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.data.keyvalue.redis.UncategorizedRedisException; + +/** + * Helper class featuring methods for RJC connection handling, providing support for exception translation. + * + * @author Costin Leau + */ +public abstract class RjcUtils { + + public static DataAccessException convertRjcAccessException(RuntimeException ex) { + if (ex instanceof RedisException) { + return convertRjcAccessException((RedisException) ex); + } + + return new UncategorizedRedisException("Unknown exception", ex); + } + + public static DataAccessException convertRjcAccessException(RedisException ex) { + return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); + } +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java new file mode 100644 index 000000000..db152b72c --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java @@ -0,0 +1,38 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.idevlab.rjc.ds.DataSource; +import org.idevlab.rjc.ds.RedisConnection; + +/** + * Basic data source that always returns the same connection. + * + * @author Costin Leau + */ +class SingleDataSource implements DataSource { + + private final RedisConnection connection; + + SingleDataSource(RedisConnection connection) { + this.connection = connection; + } + + @Override + public RedisConnection getConnection() { + return connection; + } +} From dfd6ae3087e51fce8fd7e73521cb7bc4bd87ec9c Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 13:13:27 +0200 Subject: [PATCH 29/68] DATAKV-46 + almost done with the Rjc connection + arranged base64 a bit + fixed some jredis/jedis bug in the process + updated some of the RedisConnection methods --- .../DefaultStringRedisConnection.java | 6 +- .../redis/connection/RedisStringCommands.java | 4 +- .../connection/jedis/JedisConnection.java | 9 +- .../redis/connection/jedis/JedisUtils.java | 9 +- .../connection/jredis/JredisConnection.java | 8 +- .../redis/connection/jredis/JredisUtils.java | 43 +- .../redis/connection/rjc/RjcConnection.java | 2468 +++++++++++++---- .../connection/rjc/RjcConnectionFactory.java | 2 +- .../redis/connection/rjc/RjcUtils.java | 180 +- .../connection/{jredis => util}/Base64.java | 2 +- .../redis/connection/util/DecodeUtils.java | 82 + 11 files changed, 2196 insertions(+), 617 deletions(-) rename spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/{jredis => util}/Base64.java (99%) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index 3d857e3df..9db1d2af4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -156,7 +156,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.getNativeConnection(); } - public byte[] getRange(byte[] key, int start, int end) { + public byte[] getRange(byte[] key, long start, long end) { return delegate.getRange(key, start, end); } @@ -396,8 +396,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.setNX(key, value); } - public void setRange(byte[] key, int start, int end) { - delegate.setRange(key, start, end); + public void setRange(byte[] key, long start, byte[] value) { + delegate.setRange(key, start, value); } public void shutdown() { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java index ea96dfde6..d68acd0d6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java @@ -52,9 +52,9 @@ public interface RedisStringCommands { Long append(byte[] key, byte[] value); - byte[] getRange(byte[] key, int begin, int end); + byte[] getRange(byte[] key, long begin, long end); - void setRange(byte[] key, int begin, int end); + void setRange(byte[] key, long offset, byte[] value); Boolean getBit(byte[] key, long offset); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index d3f898769..5fdd3beb2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -914,7 +914,7 @@ public class JedisConnection implements RedisConnection { } @Override - public byte[] getRange(byte[] key, int start, int end) { + public byte[] getRange(byte[] key, long start, long end) { try { if (isQueueing()) { transaction.substr(key, (int) start, (int) end); @@ -1033,7 +1033,7 @@ public class JedisConnection implements RedisConnection { } @Override - public void setRange(byte[] key, int start, int end) { + public void setRange(byte[] key, long start, byte[] value) { throw new UnsupportedOperationException(); } @@ -1770,11 +1770,10 @@ public class JedisConnection implements RedisConnection { public Set zRevRangeWithScore(byte[] key, long start, long end) { try { if (isQueueing()) { - transaction.zrangeWithScores(key, (int) start, (int) end); - return null; + throw new UnsupportedOperationException(); } if (isPipelined()) { - pipeline.zrangeWithScores(key, (int) start, (int) end); + pipeline.zrangeByScoreWithScores(key, (int) start, (int) end); return null; } return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, (int) start, (int) end)); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java index bdfe315cd..b76e1d08a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java @@ -55,8 +55,8 @@ public abstract class JedisUtils { private static final String OK_CODE = "OK"; private static final String OK_MULTI_CODE = "+OK"; - private static final byte[] ONE = new byte[] { 0 }; - private static final byte[] ZERO = new byte[] { 1 }; + private static final byte[] ONE = new byte[] { 1 }; + private static final byte[] ZERO = new byte[] { 0 }; /** * Converts the given, native Jedis exception to Spring's DAO hierarchy. @@ -194,10 +194,13 @@ public abstract class JedisUtils { static Properties info(String string) { Properties info = new Properties(); + StringReader stringReader = new StringReader(string); try { - info.load(new StringReader(string)); + info.load(stringReader); } catch (Exception ex) { throw new UncategorizedRedisException("Cannot read Redis info", ex); + } finally { + stringReader.close(); } return info; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 6357ff522..63072f3ff 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -305,7 +305,7 @@ public class JredisConnection implements RedisConnection { @Override public Set keys(byte[] pattern) { try { - return JredisUtils.convertCollection(jredis.keys(JredisUtils.decode(pattern))); + return JredisUtils.convertToSet(jredis.keys(JredisUtils.decode(pattern))); } catch (Exception ex) { throw convertJredisAccessException(ex); } @@ -463,7 +463,7 @@ public class JredisConnection implements RedisConnection { } @Override - public byte[] getRange(byte[] key, int start, int end) { + public byte[] getRange(byte[] key, long start, long end) { try { return jredis.substr(JredisUtils.decode(key), start, end); } catch (Exception ex) { @@ -518,7 +518,7 @@ public class JredisConnection implements RedisConnection { } @Override - public void setRange(byte[] key, int start, int end) { + public void setRange(byte[] key, long start, byte[] value) { throw new UnsupportedOperationException(); } @@ -1032,7 +1032,7 @@ public class JredisConnection implements RedisConnection { @Override public Set hKeys(byte[] key) { try { - return new LinkedHashSet(JredisUtils.convertCollection(jredis.hkeys(JredisUtils.decode(key)))); + return new LinkedHashSet(JredisUtils.convertToSet(jredis.hkeys(JredisUtils.decode(key)))); } catch (Exception ex) { throw convertJredisAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java index 7820186db..9cb3dc146 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisUtils.java @@ -17,8 +17,6 @@ package org.springframework.data.keyvalue.redis.connection.jredis; import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -34,6 +32,7 @@ import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.SortParameters; import org.springframework.data.keyvalue.redis.connection.SortParameters.Order; import org.springframework.data.keyvalue.redis.connection.SortParameters.Range; +import org.springframework.data.keyvalue.redis.connection.util.DecodeUtils; /** * Helper class featuring methods for JRedis connection handling, providing support for exception translation. @@ -82,46 +81,28 @@ public abstract class JredisUtils { } static String decode(byte[] bytes) { - return Base64.encodeToString(bytes, false); - } - - static String[] decodeMultiple(byte[]... bytes) { - String[] result = new String[bytes.length]; - for (int i = 0; i < bytes.length; i++) { - result[i] = decode(bytes[i]); - } - return result; + return DecodeUtils.decode(bytes); } static byte[] encode(String string) { - return Base64.decode(string); + return DecodeUtils.encode(string); + } + + static String[] decodeMultiple(byte[]... bytes) { + return DecodeUtils.decodeMultiple(bytes); } static Map encodeMap(Map map) { - Map result = new LinkedHashMap(map.size()); - for (Map.Entry entry : map.entrySet()) { - result.put(encode(entry.getKey()), entry.getValue()); - } - return result; - } - - static Set convertCollection(Collection keys) { - Set set = new LinkedHashSet(keys.size()); - - for (String string : keys) { - set.add(Base64.decode(string)); - } - return set; + return DecodeUtils.encodeMap(map); } static Map decodeMap(Map tuple) { - Map result = new LinkedHashMap(tuple.size()); - for (Map.Entry entry : tuple.entrySet()) { - result.put(decode(entry.getKey()), entry.getValue()); - } - return result; + return DecodeUtils.decodeMap(tuple); } + static Set convertToSet(Collection keys) { + return DecodeUtils.convertToSet(keys); + } static Sort applySortingParams(Sort jredisSort, SortParameters params, byte[] storeKey) { if (params != null) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 1983555d5..a95e5a2d3 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -15,16 +15,21 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import org.idevlab.rjc.Client; import org.idevlab.rjc.RedisException; import org.idevlab.rjc.Session; import org.idevlab.rjc.SessionFactoryImpl; +import org.idevlab.rjc.SortingParams; +import org.idevlab.rjc.ZParams; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; +import org.springframework.data.keyvalue.redis.SubscribedRedisConnectionException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnection; @@ -39,11 +44,16 @@ import org.springframework.data.keyvalue.redis.connection.Subscription; public class RjcConnection implements RedisConnection { private final int dbIndex; - private final Session session; private boolean isClosed = false; + private final Client client; + private final Session session; + private volatile Client pipeline; + public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { session = new SessionFactoryImpl(new SingleDataSource(connection)).create(); + client = new Client(connection); + this.dbIndex = dbIndex; // select the db @@ -81,629 +91,1955 @@ public class RjcConnection implements RedisConnection { } @Override - public List closePipeline() { - throw new UnsupportedOperationException(); + public boolean isQueueing() { + return client.isInMulti(); } - @Override public boolean isPipelined() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isQueueing() { - throw new UnsupportedOperationException(); + return (pipeline != null); } @Override public void openPipeline() { - throw new UnsupportedOperationException(); + if (pipeline == null) { + pipeline = client; + } } + @SuppressWarnings("unchecked") @Override - public Long del(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] echo(byte[] message) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean exists(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean expire(byte[] key, long seconds) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean expireAt(byte[] key, long unixTime) { - throw new UnsupportedOperationException(); - } - - @Override - public Set keys(byte[] pattern) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean persist(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public String ping() { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] randomKey() { - throw new UnsupportedOperationException(); - } - - @Override - public void rename(byte[] oldName, byte[] newName) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean renameNX(byte[] oldName, byte[] newName) { - throw new UnsupportedOperationException(); - } - - @Override - public void select(int dbIndex) { - throw new UnsupportedOperationException(); + public List closePipeline() { + if (pipeline != null) { + List execute = client.getAll(); + if (execute != null && !execute.isEmpty()) { + return (List) execute; + } + } + return Collections.emptyList(); } @Override public List sort(byte[] key, SortParameters params) { - throw new UnsupportedOperationException(); - } - - @Override - public Long sort(byte[] key, SortParameters params, byte[] storeKey) { - throw new UnsupportedOperationException(); - } - - @Override - public Long ttl(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public DataType type(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public void discard() { - throw new UnsupportedOperationException(); - } - - @Override - public List exec() { - throw new UnsupportedOperationException(); - } - - @Override - public void multi() { - throw new UnsupportedOperationException(); - } - - @Override - public void unwatch() { - throw new UnsupportedOperationException(); - } - - @Override - public void watch(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public Long append(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long decr(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long decrBy(byte[] key, long value) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] get(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean getBit(byte[] key, long offset) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] getRange(byte[] key, int begin, int end) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] getSet(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long incr(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long incrBy(byte[] key, long value) { - throw new UnsupportedOperationException(); - } - - @Override - public List mGet(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public void mSet(Map tuple) { - throw new UnsupportedOperationException(); - } - - @Override - public void mSetNX(Map tuple) { - throw new UnsupportedOperationException(); - } - - @Override - public void set(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public void setBit(byte[] key, long offset, boolean value) { - throw new UnsupportedOperationException(); - } - - @Override - public void setEx(byte[] key, long seconds, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean setNX(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public void setRange(byte[] key, int begin, int end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long strLen(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public List bLPop(int timeout, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public List bRPop(int timeout, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] lIndex(byte[] key, long index) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lLen(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] lPop(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lPush(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lPushX(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public List lRange(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long lRem(byte[] key, long count, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public void lSet(byte[] key, long index, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public void lTrim(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] rPop(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { - throw new UnsupportedOperationException(); - } - - @Override - public Long rPush(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long rPushX(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean sAdd(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long sCard(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Set sDiff(byte[]... keys) { - throw new UnsupportedOperationException(); - } - @Override - public void sDiffStore(byte[] destKey, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public Set sInter(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public void sInterStore(byte[] destKey, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean sIsMember(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Set sMembers(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] sPop(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] sRandMember(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean sRem(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Set sUnion(byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public void sUnionStore(byte[] destKey, byte[]... keys) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean zAdd(byte[] key, double score, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zCard(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zCount(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Double zIncrBy(byte[] key, double increment, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zInterStore(byte[] destKey, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRange(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScoreWithScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRangeWithScore(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zRank(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean zRem(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zRemRange(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zRemRangeByScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRevRange(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Set zRevRangeWithScore(byte[] key, long begin, long end) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zRevRank(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Double zScore(byte[] key, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zUnionStore(byte[] destKey, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - @Override - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean hDel(byte[] key, byte[] field) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean hExists(byte[] key, byte[] field) { - throw new UnsupportedOperationException(); - } - - @Override - public byte[] hGet(byte[] key, byte[] field) { - throw new UnsupportedOperationException(); - } - - @Override - public Map hGetAll(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long hIncrBy(byte[] key, byte[] field, long delta) { - throw new UnsupportedOperationException(); - } - - @Override - public Set hKeys(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public Long hLen(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public List hMGet(byte[] key, byte[]... fields) { - throw new UnsupportedOperationException(); - } - - @Override - public void hMSet(byte[] key, Map hashes) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean hSet(byte[] key, byte[] field, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { - throw new UnsupportedOperationException(); - } - - @Override - public List hVals(byte[] key) { - throw new UnsupportedOperationException(); - } - - @Override - public void bgSave() { - throw new UnsupportedOperationException(); - } - - @Override - public void bgWriteAof() { - throw new UnsupportedOperationException(); + SortingParams sortParams = RjcUtils.convertSortParams(params); + final String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + if (sortParams != null) { + pipeline.sort(stringKey, sortParams); + } + else { + pipeline.sort(stringKey); + } + + return null; + } + return RjcUtils.convertToList((sortParams != null ? session.sort(stringKey, sortParams) + : session.sort(stringKey))); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long sort(byte[] key, SortParameters params, byte[] sortKey) { + + SortingParams sortParams = RjcUtils.convertSortParams(params); + final String stringKey = RjcUtils.decode(key); + final String stringSortKey = RjcUtils.decode(sortKey); + + try { + if (isPipelined()) { + if (sortParams != null) { + pipeline.sort(stringKey, sortParams, stringSortKey); + } + else { + pipeline.sort(stringKey, stringSortKey); + } + + return null; + } + return (sortParams != null ? session.sort(stringKey, sortParams, stringSortKey) : session.sort(stringKey, + stringSortKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public Long dbSize() { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.dbSize(); + return null; + } + return session.dbSize(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + @Override + public void flushDb() { + try { + if (isPipelined()) { + pipeline.flushDB(); + return; + } + session.flushDB(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void flushAll() { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.flushAll(); + return; + } + session.flushAll(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override - public void flushDb() { - throw new UnsupportedOperationException(); + public void bgSave() { + try { + if (isPipelined()) { + pipeline.bgsave(); + return; + } + session.bgsave(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override - public List getConfig(String pattern) { - throw new UnsupportedOperationException(); - } - - @Override - public Properties info() { - throw new UnsupportedOperationException(); - } - - @Override - public Long lastSave() { - throw new UnsupportedOperationException(); - } - - @Override - public void resetConfigStats() { - throw new UnsupportedOperationException(); + public void bgWriteAof() { + try { + if (isPipelined()) { + pipeline.bgrewriteaof(); + return; + } + session.bgrewriteaof(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void save() { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.save(); + return; + } + session.save(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List getConfig(String param) { + try { + if (isPipelined()) { + pipeline.configGet(param); + return null; + } + return session.configGet(param); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Properties info() { + try { + if (isPipelined()) { + pipeline.info(); + return null; + } + return RjcUtils.info(session.info()); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lastSave() { + try { + if (isPipelined()) { + pipeline.lastsave(); + return null; + } + return session.lastsave(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void setConfig(String param, String value) { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.configSet(param, value); + return; + } + session.configSet(param, value); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + @Override + public void resetConfigStats() { + try { + if (isPipelined()) { + pipeline.configResetStat(); + return; + } + client.configResetStat(); + client.getStatusCodeReply(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void shutdown() { - throw new UnsupportedOperationException(); + try { + if (isPipelined()) { + pipeline.shutdown(); + return; + } + session.shutdown(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] echo(byte[] message) { + String stringMsg = RjcUtils.decode(message); + try { + if (isPipelined()) { + pipeline.echo(stringMsg); + return null; + } + return RjcUtils.encode(session.echo(stringMsg)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public String ping() { + try { + if (isPipelined()) { + pipeline.ping(); + } + return session.ping(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long del(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + if (isPipelined()) { + pipeline.del(stringKeys); + return null; + } + return session.del(stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void discard() { + try { + if (isPipelined()) { + pipeline.discard(); + return; + } + + session.discard(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List exec() { + try { + if (isPipelined()) { + pipeline.exec(); + return null; + } + return session.exec(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean exists(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.exists(stringKey); + return null; + } + return session.exists(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean expire(byte[] key, long seconds) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.expire(stringKey, (int) seconds); + return null; + } + return session.expire(stringKey, (int) seconds); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean expireAt(byte[] key, long unixTime) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.expireAt(stringKey, unixTime); + return null; + } + return session.expireAt(stringKey, unixTime); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set keys(byte[] pattern) { + String stringKey = RjcUtils.decode(pattern); + + try { + if (isPipelined()) { + pipeline.keys(stringKey); + return null; + } + return RjcUtils.convertToSet(session.keys(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void multi() { + if (isQueueing()) { + return; + } + try { + if (isPipelined()) { + pipeline.multi(); + return; + } + session.multi(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean persist(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.persist(stringKey); + return null; + } + return session.persist(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] randomKey() { + try { + if (isPipelined()) { + pipeline.randomKey(); + return null; + } + return RjcUtils.encode(session.randomKey()); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void rename(byte[] oldName, byte[] newName) { + String stringOldKey = RjcUtils.decode(oldName); + String stringNewKey = RjcUtils.decode(newName); + + try { + if (isPipelined()) { + pipeline.rename(stringOldKey, stringNewKey); + return; + } + session.rename(stringOldKey, stringNewKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean renameNX(byte[] oldName, byte[] newName) { + String stringOldKey = RjcUtils.decode(oldName); + String stringNewKey = RjcUtils.decode(newName); + + try { + if (isPipelined()) { + pipeline.renamenx(stringOldKey, stringNewKey); + return null; + } + return session.renamenx(stringOldKey, stringNewKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void select(int dbIndex) { + try { + if (isPipelined()) { + pipeline.select(dbIndex); + return; + } + session.select(dbIndex); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long ttl(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.ttl(stringKey); + return null; + } + return session.ttl(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public DataType type(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.type(stringKey); + return null; + } + return DataType.fromCode(session.type(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void unwatch() { + try { + if (isPipelined()) { + pipeline.unwatch(); + return; + } + + session.unwatch(); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void watch(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + if (isQueueing()) { + return; + } + try { + if (isPipelined()) { + pipeline.watch(stringKeys); + return; + } + else { + session.watch(stringKeys); + } + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + // + // String commands + // + + @Override + public byte[] get(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.get(stringKey); + return null; + } + + return RjcUtils.encode(session.get(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void set(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.set(stringKey, stringValue); + return; + } + session.set(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + @Override + public byte[] getSet(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.getSet(stringKey, stringValue); + return null; + } + return RjcUtils.encode(session.getSet(stringKey, stringValue)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long append(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.append(stringKey, stringValue); + return null; + } + return session.append(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List mGet(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + if (isPipelined()) { + pipeline.mget(stringKeys); + return null; + } + return RjcUtils.convertToList(session.mget(stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void mSet(Map tuples) { + String[] decodeMap = RjcUtils.flatten(tuples); + + try { + if (isPipelined()) { + pipeline.mset(decodeMap); + return; + } + session.mset(decodeMap); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void mSetNX(Map tuples) { + String[] decodeMap = RjcUtils.flatten(tuples); + + try { + + if (isPipelined()) { + pipeline.msetnx(decodeMap); + return; + } + session.msetnx(decodeMap); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void setEx(byte[] key, long time, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.setex(stringKey, (int) time, stringValue); + return; + } + session.setex(stringKey, (int) time, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean setNX(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.setnx(stringKey, stringValue); + return null; + } + return session.setnx(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] getRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.getRange(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.encode(session.getRange(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long decr(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.decr(stringKey); + return null; + } + return session.decr(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long decrBy(byte[] key, long value) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.decrBy(stringKey, (int) value); + return null; + } + return session.decrBy(stringKey, (int) value); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long incr(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.incr(stringKey); + return null; + } + return session.incr(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long incrBy(byte[] key, long value) { + String stringKey = RjcUtils.decode(key); + + + try { + if (isPipelined()) { + pipeline.incrBy(stringKey, (int) value); + return null; + } + return session.incrBy(stringKey, (int) value); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean getBit(byte[] key, long offset) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.getbit(stringKey, (int) offset); + return null; + } + return (session.getBit(stringKey, (int) offset) == 0 ? Boolean.FALSE : Boolean.TRUE); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void setBit(byte[] key, long offset, boolean value) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.setbit(stringKey, (int) offset, RjcUtils.asBit(value)); + return; + } + session.setBit(stringKey, (int) offset, RjcUtils.asBit(value)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void setRange(byte[] key, long offset, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.setRange(stringKey, (int) offset, stringValue); + return; + } + session.setRange(stringKey, (int) offset, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long strLen(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.strlen(stringKey); + return null; + } + return session.strlen(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + // + // List commands + // + + @Override + public Long lPush(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.lpush(stringKey, stringValue); + return null; + } + return session.lpush(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long rPush(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.rpush(stringKey, stringValue); + return null; + } + return session.rpush(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List bLPop(int timeout, byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + if (isPipelined()) { + pipeline.blpop(stringKeys); + return null; + } + return RjcUtils.convertToList(session.blpop(timeout, stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List bRPop(int timeout, byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + if (isPipelined()) { + pipeline.brpop(stringKeys); + return null; + } + return RjcUtils.convertToList(session.brpop(timeout, stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] lIndex(byte[] key, long index) { + String stringKey = RjcUtils.decode(key); + + + try { + if (isPipelined()) { + pipeline.lindex(stringKey, (int) index); + return null; + } + return RjcUtils.encode(session.lindex(stringKey, (int) index)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + String stringPivot = RjcUtils.decode(pivot); + Client.LIST_POSITION position = RjcUtils.convertPosition(where); + + try { + if (isPipelined()) { + pipeline.linsert(stringKey, position, stringPivot, stringValue); + return null; + } + return session.linsert(stringKey, position, stringPivot, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lLen(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.llen(stringKey); + return null; + } + return session.llen(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] lPop(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.lpop(stringKey); + return null; + } + return RjcUtils.encode(session.lpop(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List lRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.lrange(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.convertToList(session.lrange(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lRem(byte[] key, long count, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.lrem(stringKey, (int) count, stringValue); + return null; + } + return session.lrem(stringKey, (int) count, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void lSet(byte[] key, long index, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + try { + + if (isPipelined()) { + pipeline.lset(stringKey, (int) index, stringValue); + return; + } + session.lset(stringKey, (int) index, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void lTrim(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.ltrim(stringKey, (int) start, (int) end); + return; + } + session.ltrim(stringKey, (int) start, (int) end); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] rPop(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.rpop(stringKey); + return null; + } + return RjcUtils.encode(session.rpop(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { + String stringKey = RjcUtils.decode(srcKey); + String stringDest = RjcUtils.decode(dstKey); + + try { + + if (isPipelined()) { + pipeline.rpoplpush(stringKey, stringDest); + return null; + } + return RjcUtils.encode(session.rpoplpush(stringKey, stringDest)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { + String stringKey = RjcUtils.decode(srcKey); + String stringDest = RjcUtils.decode(dstKey); + + try { + if (isPipelined()) { + pipeline.brpoplpush(stringKey, stringDest, timeout); + return null; + } + return RjcUtils.encode(session.brpoplpush(stringKey, stringDest, timeout)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long lPushX(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + try { + if (isPipelined()) { + pipeline.lpushx(stringKey, stringValue); + return null; + } + return session.lpushx(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long rPushX(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + try { + if (isPipelined()) { + pipeline.rpushx(stringKey, stringValue); + return null; + } + return session.rpushx(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + // + // Set commands + // + + @Override + public Boolean sAdd(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.sadd(stringKey, stringValue); + return null; + } + return session.sadd(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long sCard(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + + if (isPipelined()) { + pipeline.scard(stringKey); + return null; + } + return session.scard(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set sDiff(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + + if (isPipelined()) { + pipeline.sdiff(stringKeys); + return null; + } + return RjcUtils.convertToSet(session.sdiff(stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void sDiffStore(byte[] destKey, byte[]... keys) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + + if (isPipelined()) { + pipeline.sdiffstore(stringKey, stringKeys); + return; + } + session.sdiffstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set sInter(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + try { + + if (isPipelined()) { + pipeline.sinter(stringKeys); + return null; + } + return RjcUtils.convertToSet(session.sinter(stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void sInterStore(byte[] destKey, byte[]... keys) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(keys); + try { + + if (isPipelined()) { + pipeline.sinterstore(stringKey, stringKeys); + return; + } + session.sinterstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean sIsMember(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.sismember(stringKey, stringValue); + return null; + } + return session.sismember(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set sMembers(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.smembers(stringKey); + return null; + } + return RjcUtils.convertToSet(session.smembers(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { + String stringSrc = RjcUtils.decode(srcKey); + String stringDest = RjcUtils.decode(destKey); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.smove(stringSrc, stringDest, stringValue); + return null; + } + return session.smove(stringSrc, stringDest, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] sPop(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.spop(stringKey); + return null; + } + return RjcUtils.encode(session.spop(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] sRandMember(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.srandmember(stringKey); + return null; + } + return RjcUtils.encode(session.srandmember(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean sRem(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + + if (isPipelined()) { + pipeline.srem(stringKey, stringValue); + return null; + } + return session.srem(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set sUnion(byte[]... keys) { + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + + if (isPipelined()) { + pipeline.sunion(stringKeys); + return null; + } + return RjcUtils.convertToSet(session.sunion(stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void sUnionStore(byte[] destKey, byte[]... keys) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(keys); + + try { + + if (isPipelined()) { + pipeline.sunionstore(stringKey, stringKeys); + return; + } + session.sunionstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + // + // ZSet commands + // + + @Override + public Boolean zAdd(byte[] key, double score, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zadd(stringKey, score, stringValue); + return null; + } + return session.zadd(stringKey, score, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zCard(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.zcard(stringKey); + return null; + } + return session.zcard(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zCount(byte[] key, double min, double max) { + String stringKey = RjcUtils.decode(key); + try { + if (isPipelined()) { + pipeline.zcount(stringKey, min, max); + return null; + } + + return session.zcount(stringKey, min, max); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Double zIncrBy(byte[] key, double increment, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zincrby(stringKey, increment, stringValue); + return null; + } + return Double.valueOf(session.zincrby(stringKey, increment, stringValue)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(sets); + + ZParams zparams = RjcUtils.toZParams(aggregate, weights); + + try { + if (isPipelined()) { + pipeline.zinterstore(stringKey, zparams, stringKeys); + return null; + } + return session.zinterstore(stringKey, zparams, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zInterStore(byte[] destKey, byte[]... sets) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(sets); + try { + if (isPipelined()) { + pipeline.zinterstore(stringKey, stringKeys); + return null; + } + + return session.zinterstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.zrange(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.convertToSet(session.zrange(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeWithScore(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.zrangeWithScores(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.convertElementScore(session.zrangeWithScores(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeByScore(byte[] key, double min, double max) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zrangeByScore(stringKey, minString, maxString); + return null; + } + return RjcUtils.convertToSet(session.zrangeByScore(stringKey, minString, maxString)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeByScoreWithScore(byte[] key, double min, double max) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zrangeByScoreWithScores(stringKey, minString, maxString); + return null; + } + return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRevRangeWithScore(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + String minString = Long.toString(start); + String maxString = Long.toString(end); + + try { + + if (isPipelined()) { + pipeline.zrangeByScoreWithScores(stringKey, minString, maxString); + return null; + } + return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zrangeByScore(stringKey, minString, maxString, (int) offset, (int) count); + return null; + } + return RjcUtils.convertToSet(session.zrangeByScore(stringKey, minString, maxString, (int) offset, + (int) count)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zrangeByScoreWithScores(stringKey, minString, maxString, (int) offset, (int) count); + return null; + } + return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString, + (int) offset, (int) count)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zRank(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zrank(stringKey, stringValue); + return null; + } + return session.zrank(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean zRem(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zrem(stringKey, stringValue); + return null; + } + return session.zrem(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zRemRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + try { + if (isPipelined()) { + pipeline.zremrangeByRank(stringKey, (int) start, (int) end); + return null; + } + return session.zremrangeByRank(stringKey, (int) start, (int) end); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zRemRangeByScore(byte[] key, double min, double max) { + String stringKey = RjcUtils.decode(key); + String minString = Double.toString(min); + String maxString = Double.toString(max); + + try { + if (isPipelined()) { + pipeline.zremrangeByScore(stringKey, minString, maxString); + return null; + } + return session.zremrangeByScore(stringKey, minString, maxString); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set zRevRange(byte[] key, long start, long end) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.zrevrange(stringKey, (int) start, (int) end); + return null; + } + return RjcUtils.convertToSet(session.zrevrange(stringKey, (int) start, (int) end)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zRevRank(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zrevrank(stringKey, stringValue); + return null; + } + return session.zrevrank(stringKey, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Double zScore(byte[] key, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.zscore(stringKey, stringValue); + return null; + } + return Double.valueOf(session.zscore(stringKey, stringValue)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(destKey); + + ZParams zparams = RjcUtils.toZParams(aggregate, weights); + + try { + if (isPipelined()) { + pipeline.zunionstore(stringKey, zparams, stringKeys); + return null; + } + return session.zunionstore(stringKey, zparams, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long zUnionStore(byte[] destKey, byte[]... sets) { + String stringKey = RjcUtils.decode(destKey); + String[] stringKeys = RjcUtils.decodeMultiple(sets); + + try { + if (isPipelined()) { + pipeline.zunionstore(stringKey, stringKeys); + return null; + } + return session.zunionstore(stringKey, stringKeys); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + // + // Hash commands + // + + @Override + public Boolean hSet(byte[] key, byte[] field, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.hset(stringKey, stringField, stringValue); + return null; + } + return session.hset(stringKey, stringField, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + String stringValue = RjcUtils.decode(value); + + try { + if (isPipelined()) { + pipeline.hsetnx(stringKey, stringField, stringValue); + return null; + } + return session.hsetnx(stringKey, stringField, stringValue); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean hDel(byte[] key, byte[] field) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + + try { + if (isPipelined()) { + pipeline.hdel(stringKey, stringField); + return null; + } + return session.hdel(stringKey, stringField); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Boolean hExists(byte[] key, byte[] field) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + + try { + if (isPipelined()) { + pipeline.hexists(stringKey, stringField); + return null; + } + return session.hexists(stringKey, stringField); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public byte[] hGet(byte[] key, byte[] field) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + + try { + if (isPipelined()) { + pipeline.hget(stringKey, stringField); + return null; + } + return RjcUtils.encode(session.hget(stringKey, stringField)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Map hGetAll(byte[] key) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.hgetAll(stringKey); + return null; + } + return RjcUtils.encodeMap(session.hgetAll(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long hIncrBy(byte[] key, byte[] field, long delta) { + String stringKey = RjcUtils.decode(key); + String stringField = RjcUtils.decode(field); + + try { + if (isPipelined()) { + pipeline.hincrBy(stringKey, stringField, (int) delta); + return null; + } + return session.hincrBy(stringKey, stringField, (int) delta); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Set hKeys(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + if (isPipelined()) { + pipeline.hkeys(stringKey); + return null; + } + return RjcUtils.convertToSet(session.hkeys(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public Long hLen(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + if (isPipelined()) { + pipeline.hlen(stringKey); + return null; + } + return session.hlen(stringKey); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List hMGet(byte[] key, byte[]... fields) { + String stringKey = RjcUtils.decode(key); + String[] stringKeys = RjcUtils.decodeMultiple(fields); + + try { + if (isPipelined()) { + pipeline.hmget(stringKey, stringKeys); + return null; + } + return RjcUtils.convertToList(session.hmget(stringKey, stringKeys)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public void hMSet(byte[] key, Map tuple) { + String stringKey = RjcUtils.decode(key); + Map stringTuple = RjcUtils.decodeMap(tuple); + + try { + if (isPipelined()) { + pipeline.hmset(stringKey, stringTuple); + return; + } + session.hmset(stringKey, stringTuple); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + @Override + public List hVals(byte[] key) { + String stringKey = RjcUtils.decode(key); + try { + + if (isPipelined()) { + pipeline.hvals(stringKey); + return null; + } + return RjcUtils.convertToList(session.hvals(stringKey)); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + + + // + // Pub/Sub functionality + // + @Override + public Long publish(byte[] channel, byte[] message) { + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + if (isPipelined()) { + throw new UnsupportedOperationException(); + } + return session.publish(channel, message); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public Subscription getSubscription() { - throw new UnsupportedOperationException(); + return subscription; } @Override public boolean isSubscribed() { - throw new UnsupportedOperationException(); + return (subscription != null && subscription.isAlive()); } @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { - throw new UnsupportedOperationException(); - } + String[] stringKeys = RjcUtils.decodeMultiple(patterns); - @Override - public Long publish(byte[] channel, byte[] message) { - throw new UnsupportedOperationException(); + if (isSubscribed()) { + throw new SubscribedRedisConnectionException( + "Connection already subscribed; use the connection Subscription to cancel or add new channels"); + } + + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + if (isPipelined()) { + throw new UnsupportedOperationException(); + } + + BinarysessionPubSub sessionPubSub = RjcUtils.adaptPubSub(listener); + + subscription = new sessionSubscription(listener, sessionPubSub, null, patterns); + session.psubscribe(sessionPubSub, patterns); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } @Override public void subscribe(MessageListener listener, byte[]... channels) { - throw new UnsupportedOperationException(); + String[] stringKeys = RjcUtils.decodeMultiple(channels); + + if (isSubscribed()) { + throw new SubscribedRedisConnectionException( + "Connection already subscribed; use the connection Subscription to cancel or add new channels"); + } + + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + if (isPipelined()) { + throw new UnsupportedOperationException(); + } + + BinarysessionPubSub sessionPubSub = RjcUtils.adaptPubSub(listener); + + subscription = new sessionSubscription(listener, sessionPubSub, channels, null); + session.subscribe(sessionPubSub, channels); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } } -} + private void checkSubscription() { + if (isSubscribed()) { + throw new SubscribedRedisConnectionException("Cannot execute command - connection is subscribed"); + } + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java index 97f1c65cd..5c149f107 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java @@ -87,7 +87,7 @@ public class RjcConnectionFactory implements InitializingBean, DisposableBean, R @Override public RedisConnection getConnection() { - return postProcessConnection(new RjcConnection(dataSource.getConnection(), usePool, dbIndex)); + return postProcessConnection(new RjcConnection(dataSource.getConnection(), dbIndex)); } /** diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java index 9c0370bb0..50c92316f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java @@ -15,10 +15,33 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; +import java.io.StringReader; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.idevlab.rjc.ElementScore; import org.idevlab.rjc.RedisException; +import org.idevlab.rjc.SortingParams; +import org.idevlab.rjc.ZParams; +import org.idevlab.rjc.Client.LIST_POSITION; import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.keyvalue.redis.UncategorizedRedisException; +import org.springframework.data.keyvalue.redis.connection.DataType; +import org.springframework.data.keyvalue.redis.connection.DefaultTuple; +import org.springframework.data.keyvalue.redis.connection.SortParameters; +import org.springframework.data.keyvalue.redis.connection.RedisListCommands.Position; +import org.springframework.data.keyvalue.redis.connection.RedisZSetCommands.Aggregate; +import org.springframework.data.keyvalue.redis.connection.RedisZSetCommands.Tuple; +import org.springframework.data.keyvalue.redis.connection.SortParameters.Order; +import org.springframework.data.keyvalue.redis.connection.SortParameters.Range; +import org.springframework.data.keyvalue.redis.connection.util.DecodeUtils; + /** * Helper class featuring methods for RJC connection handling, providing support for exception translation. @@ -27,6 +50,10 @@ import org.springframework.data.keyvalue.redis.UncategorizedRedisException; */ public abstract class RjcUtils { + private static final String ONE = "1"; + private static final String ZERO = "0"; + + public static DataAccessException convertRjcAccessException(RuntimeException ex) { if (ex instanceof RedisException) { return convertRjcAccessException((RedisException) ex); @@ -38,4 +65,155 @@ public abstract class RjcUtils { public static DataAccessException convertRjcAccessException(RedisException ex) { return new InvalidDataAccessApiUsageException(ex.getMessage(), ex); } -} + + static DataType convertDataType(String type) { + if ("string".equals(type)) { + return DataType.STRING; + } + else if ("list".equals(type)) { + return DataType.LIST; + } + else if ("set".equals(type)) { + return DataType.SET; + } + else if ("zset".equals(type)) { + return DataType.ZSET; + } + else if ("hash".equals(type)) { + return DataType.HASH; + } + else if ("none".equals(type)) { + return DataType.NONE; + } + + return null; + } + + static String decode(byte[] bytes) { + return DecodeUtils.decode(bytes); + } + + static byte[] encode(String string) { + return DecodeUtils.encode(string); + } + + static String[] decodeMultiple(byte[]... bytes) { + return DecodeUtils.decodeMultiple(bytes); + } + + static String[] flatten(Map tuple) { + String[] result = new String[tuple.size() * 2]; + int index = 0; + for (Map.Entry entry : tuple.entrySet()) { + result[index++] = decode(entry.getKey()); + result[index++] = decode(entry.getValue()); + } + return result; + + } + + static Set convertToSet(Collection keys) { + if (keys == null) { + return null; + } + + return DecodeUtils.convertToSet(keys); + } + + static List convertToList(Collection keys) { + if (keys == null) { + return null; + } + return DecodeUtils.convertToList(keys); + } + + static SortingParams convertSortParams(SortParameters params) { + SortingParams rjcSort = null; + + if (params != null) { + rjcSort = new SortingParams(); + + byte[] byPattern = params.getByPattern(); + if (byPattern != null) { + rjcSort.by(DecodeUtils.decode(byPattern)); + } + byte[][] getPattern = params.getGetPattern(); + + if (getPattern != null && getPattern.length > 0) { + for (byte[] bs : getPattern) { + rjcSort.get(DecodeUtils.decode(bs)); + } + } + Range limit = params.getLimit(); + if (limit != null) { + rjcSort.limit((int) limit.getStart(), (int) limit.getCount()); + } + Order order = params.getOrder(); + if (order != null && order.equals(Order.DESC)) { + rjcSort.desc(); + } + Boolean isAlpha = params.isAlphabetic(); + if (isAlpha != null && isAlpha) { + rjcSort.alpha(); + } + } + return rjcSort; + } + + static Properties info(String string) { + Properties info = new Properties(); + StringReader stringReader = new StringReader(string); + try { + info.load(stringReader); + } catch (Exception ex) { + throw new UncategorizedRedisException("Cannot read Redis info", ex); + } finally { + stringReader.close(); + } + return info; + } + + static String asBit(boolean value) { + return (value ? ONE : ZERO); + } + + static LIST_POSITION convertPosition(Position where) { + switch (where) { + case BEFORE: + return LIST_POSITION.BEFORE; + + case AFTER: + return LIST_POSITION.AFTER; + } + return null; + } + + static ZParams toZParams(Aggregate aggregate, int[] weights) { + return new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name())); + } + + static Set convertElementScore(List tuples) { + Set value = new LinkedHashSet(tuples.size()); + for (ElementScore tuple : tuples) { + value.add(new DefaultTuple(encode(tuple.getElement()), Double.valueOf(tuple.getScore()))); + } + + return value; + } + + static Map encodeMap(Map map) { + Map result = new LinkedHashMap(map.size()); + for (Map.Entry entry : map.entrySet()) { + result.put(encode(entry.getKey()), encode(entry.getValue())); + } + return result; + } + + static Map decodeMap(Map map) { + Map result = new LinkedHashMap(map.size()); + for (Map.Entry entry : map.entrySet()) { + result.put(decode(entry.getKey()), decode(entry.getValue())); + } + return result; + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/Base64.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/Base64.java similarity index 99% rename from spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/Base64.java rename to spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/Base64.java index 6feb3a4d6..3e99472d6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/Base64.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/Base64.java @@ -1,4 +1,4 @@ -package org.springframework.data.keyvalue.redis.connection.jredis; +package org.springframework.data.keyvalue.redis.connection.util; import java.util.Arrays; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java new file mode 100644 index 000000000..d3588856c --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java @@ -0,0 +1,82 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Simple class containing various decoding utilities. + * + * @author Costin Leau + */ +public abstract class DecodeUtils { + + public static String decode(byte[] bytes) { + return Base64.encodeToString(bytes, false); + } + + public static String[] decodeMultiple(byte[]... bytes) { + String[] result = new String[bytes.length]; + for (int i = 0; i < bytes.length; i++) { + result[i] = decode(bytes[i]); + } + return result; + } + + public static byte[] encode(String string) { + return Base64.decode(string); + } + + public static Map encodeMap(Map map) { + Map result = new LinkedHashMap(map.size()); + for (Map.Entry entry : map.entrySet()) { + result.put(encode(entry.getKey()), entry.getValue()); + } + return result; + } + + public static Map decodeMap(Map tuple) { + Map result = new LinkedHashMap(tuple.size()); + for (Map.Entry entry : tuple.entrySet()) { + result.put(decode(entry.getKey()), entry.getValue()); + } + return result; + } + + public static Set convertToSet(Collection keys) { + Set set = new LinkedHashSet(keys.size()); + + for (String string : keys) { + set.add(Base64.decode(string)); + } + return set; + } + + public static List convertToList(Collection keys) { + List set = new ArrayList(keys.size()); + + for (String string : keys) { + set.add(Base64.decode(string)); + } + return set; + } +} \ No newline at end of file From f6c223fe1e91a1a750e9f71158b036ef7340f695 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 14:48:49 +0200 Subject: [PATCH 30/68] DATAKV-46 + wrap up RJC connector with pub sub support --- .../redis/connection/rjc/RjcConnection.java | 25 +-- .../connection/rjc/RjcMessageListener.java | 45 ++++++ .../redis/connection/rjc/RjcSubscription.java | 149 ++++++++++++++++++ 3 files changed, 207 insertions(+), 12 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index a95e5a2d3..93e452427 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -27,6 +27,7 @@ import org.idevlab.rjc.Session; import org.idevlab.rjc.SessionFactoryImpl; import org.idevlab.rjc.SortingParams; import org.idevlab.rjc.ZParams; +import org.idevlab.rjc.message.RedisNodeSubscriber; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; import org.springframework.data.keyvalue.redis.SubscribedRedisConnectionException; @@ -50,9 +51,14 @@ public class RjcConnection implements RedisConnection { private final Session session; private volatile Client pipeline; + private volatile RjcSubscription subscription; + private volatile RedisNodeSubscriber subscriber; + public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { - session = new SessionFactoryImpl(new SingleDataSource(connection)).create(); + SingleDataSource connectionDataSource = new SingleDataSource(connection); + session = new SessionFactoryImpl().create(); client = new Client(connection); + subscriber = new RedisNodeSubscriber(connectionDataSource); this.dbIndex = dbIndex; @@ -73,6 +79,7 @@ public class RjcConnection implements RedisConnection { public void close() throws DataAccessException { isClosed = true; try { + subscriber.close(); session.close(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -1969,7 +1976,7 @@ public class RjcConnection implements RedisConnection { if (isPipelined()) { throw new UnsupportedOperationException(); } - return session.publish(channel, message); + return session.publish(RjcUtils.decode(channel), RjcUtils.decode(message)); } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -1987,8 +1994,6 @@ public class RjcConnection implements RedisConnection { @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { - String[] stringKeys = RjcUtils.decodeMultiple(patterns); - if (isSubscribed()) { throw new SubscribedRedisConnectionException( "Connection already subscribed; use the connection Subscription to cancel or add new channels"); @@ -2002,10 +2007,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - BinarysessionPubSub sessionPubSub = RjcUtils.adaptPubSub(listener); + subscription = new RjcSubscription(listener, subscriber); + subscription.pSubscribe(patterns); - subscription = new sessionSubscription(listener, sessionPubSub, null, patterns); - session.psubscribe(sessionPubSub, patterns); } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -2013,8 +2017,6 @@ public class RjcConnection implements RedisConnection { @Override public void subscribe(MessageListener listener, byte[]... channels) { - String[] stringKeys = RjcUtils.decodeMultiple(channels); - if (isSubscribed()) { throw new SubscribedRedisConnectionException( "Connection already subscribed; use the connection Subscription to cancel or add new channels"); @@ -2028,10 +2030,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - BinarysessionPubSub sessionPubSub = RjcUtils.adaptPubSub(listener); + subscription = new RjcSubscription(listener, subscriber); + subscription.pSubscribe(channels); - subscription = new sessionSubscription(listener, sessionPubSub, channels, null); - session.subscribe(sessionPubSub, channels); } catch (Exception ex) { throw convertRjcAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java new file mode 100644 index 000000000..c16a2040f --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java @@ -0,0 +1,45 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.idevlab.rjc.message.MessageListener; +import org.idevlab.rjc.message.PMessageListener; +import org.springframework.data.keyvalue.redis.connection.DefaultMessage; + +/** + * Message listener adapter for RJC library. + * + * @author Costin Leau + */ +class RjcMessageListener implements MessageListener, PMessageListener { + + private final org.springframework.data.keyvalue.redis.connection.MessageListener listener; + + RjcMessageListener(org.springframework.data.keyvalue.redis.connection.MessageListener messageListener) { + this.listener = messageListener; + } + + @Override + public void onMessage(String channel, String message) { + listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), null); + } + + @Override + public void onMessage(String pattern, String channel, String message) { + listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), + RjcUtils.encode(pattern)); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java new file mode 100644 index 000000000..a1075a120 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java @@ -0,0 +1,149 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import java.util.ArrayList; +import java.util.Collection; + +import org.idevlab.rjc.message.RedisSubscriber; +import org.springframework.data.keyvalue.redis.connection.MessageListener; +import org.springframework.data.keyvalue.redis.connection.Subscription; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; + +/** + * Message subscription on top of RJC. + * + * @author Costin Leau + */ +class RjcSubscription implements Subscription { + + private final MessageListener listener; + private final RedisSubscriber subscriber; + private final RjcMessageListener listenerAdapter; + + private final Collection channels = new ArrayList(2); + private final Collection patterns = new ArrayList(2); + + RjcSubscription(MessageListener listener, RedisSubscriber subscriber) { + Assert.notNull(listener); + this.listener = listener; + this.subscriber = subscriber; + this.listenerAdapter = new RjcMessageListener(listener); + } + + @Override + public Collection getChannels() { + synchronized (channels) { + return new ArrayList(channels); + } + } + + @Override + public MessageListener getListener() { + return listener; + } + + @Override + public Collection getPatterns() { + synchronized (patterns) { + return new ArrayList(patterns); + } + } + + @Override + public void pSubscribe(byte[]... patterns) { + Assert.notEmpty(patterns, "at least one pattern required"); + + synchronized (this.patterns) { + for (byte[] bs : patterns) { + this.patterns.add(bs); + } + } + + for (String pattern : RjcUtils.decodeMultiple(patterns)) { + subscriber.psubscribe(pattern, listenerAdapter); + } + } + + @Override + public void pUnsubscribe() { + pUnsubscribe(null); + + synchronized (patterns) { + patterns.clear(); + } + } + + @Override + public void pUnsubscribe(byte[]... patterns) { + if (ObjectUtils.isEmpty(patterns)) { + patterns = this.patterns.toArray(new byte[this.patterns.size()][]); + } + + synchronized (this.patterns) { + for (byte[] bs : patterns) { + this.patterns.remove(bs); + } + } + + subscriber.punsubscribe(RjcUtils.decodeMultiple(patterns)); + } + + @Override + public void subscribe(byte[]... channels) { + Assert.notEmpty(channels, "at least one channel required"); + + synchronized (this.channels) { + for (byte[] bs : channels) { + this.channels.add(bs); + } + } + + for (String channel : RjcUtils.decodeMultiple(channels)) { + subscriber.subscribe(channel, listenerAdapter); + } + } + + @Override + public void unsubscribe() { + unsubscribe(null); + + synchronized (patterns) { + patterns.clear(); + } + } + + @Override + public void unsubscribe(byte[]... channels) { + if (ObjectUtils.isEmpty(channels)) { + channels = this.channels.toArray(new byte[this.channels.size()][]); + } + + synchronized (this.channels) { + for (byte[] bs : channels) { + this.channels.remove(bs); + } + } + + subscriber.punsubscribe(RjcUtils.decodeMultiple(channels)); + } + + @Override + public boolean isAlive() { + return (!channels.isEmpty() || !patterns.isEmpty()); + } +} \ No newline at end of file From 635029205968ac8b3ef836f6897978b20225eb0a Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 15:14:41 +0200 Subject: [PATCH 31/68] DATAKV-46 + first round of bug fixes for SJC + added integration tests + update OSGi template + update get/set method signatures in the process --- .../DefaultStringRedisConnection.java | 10 ++-- .../redis/connection/RedisStringCommands.java | 2 +- .../connection/StringRedisConnection.java | 4 +- .../connection/jedis/JedisConnection.java | 2 +- .../connection/jredis/JredisConnection.java | 2 +- .../redis/connection/rjc/RjcConnection.java | 10 ++-- .../redis/connection/util/DecodeUtils.java | 6 +-- .../redis/core/BoundValueOperations.java | 8 +-- .../core/DefaultBoundValueOperations.java | 6 +-- .../redis/core/DefaultValueOperations.java | 7 +-- .../keyvalue/redis/core/RedisTemplate.java | 2 +- .../keyvalue/redis/core/ValueOperations.java | 4 +- .../AbstractConnectionIntegrationTests.java | 11 ++-- .../rjc/RjcConnectionIntegrationTests.java | 54 +++++++++++++++++++ spring-data-redis/template.mf | 4 +- 15 files changed, 95 insertions(+), 37 deletions(-) create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionIntegrationTests.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index 9db1d2af4..adb2cd1f4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -396,8 +396,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.setNX(key, value); } - public void setRange(byte[] key, long start, byte[] value) { - delegate.setRange(key, start, value); + public void setRange(byte[] key, byte[] value, long start) { + delegate.setRange(key, value, start); } public void shutdown() { @@ -683,7 +683,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } @Override - public String getRange(String key, int start, int end) { + public String getRange(String key, long start, long end) { return deserialize(delegate.getRange(serialize(key), start, end)); } @@ -919,8 +919,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } @Override - public void setRange(String key, int start, int end) { - delegate.setRange(serialize(key), start, end); + public void setRange(String key, long start, String value) { + delegate.setRange(serialize(key), serialize(value), start); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java index d68acd0d6..d763774ae 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisStringCommands.java @@ -54,7 +54,7 @@ public interface RedisStringCommands { byte[] getRange(byte[] key, long begin, long end); - void setRange(byte[] key, long offset, byte[] value); + void setRange(byte[] key, byte[] value, long offset); Boolean getBit(byte[] key, long offset); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java index 7622c3b56..53517c8ea 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java @@ -95,9 +95,9 @@ public interface StringRedisConnection extends RedisConnection { Long append(String key, String value); - String getRange(String key, int start, int end); + String getRange(String key, long start, long end); - void setRange(String key, int start, int end); + void setRange(String key, long offset, String value); Boolean getBit(String key, long offset); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 5fdd3beb2..3cf0a1c08 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -1033,7 +1033,7 @@ public class JedisConnection implements RedisConnection { } @Override - public void setRange(byte[] key, long start, byte[] value) { + public void setRange(byte[] key, byte[] value, long start) { throw new UnsupportedOperationException(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 63072f3ff..4339dcdf5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -518,7 +518,7 @@ public class JredisConnection implements RedisConnection { } @Override - public void setRange(byte[] key, long start, byte[] value) { + public void setRange(byte[] key, byte[] value, long start) { throw new UnsupportedOperationException(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 93e452427..78e5a2dff 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -56,7 +56,7 @@ public class RjcConnection implements RedisConnection { public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { SingleDataSource connectionDataSource = new SingleDataSource(connection); - session = new SessionFactoryImpl().create(); + session = new SessionFactoryImpl(connectionDataSource).create(); client = new Client(connection); subscriber = new RedisNodeSubscriber(connectionDataSource); @@ -638,7 +638,7 @@ public class RjcConnection implements RedisConnection { @Override public void set(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); - String stringValue = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); try { if (isPipelined()) { @@ -655,7 +655,7 @@ public class RjcConnection implements RedisConnection { @Override public byte[] getSet(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); - String stringValue = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); try { if (isPipelined()) { @@ -671,7 +671,7 @@ public class RjcConnection implements RedisConnection { @Override public Long append(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); - String stringValue = RjcUtils.decode(key); + String stringValue = RjcUtils.decode(value); try { if (isPipelined()) { @@ -870,7 +870,7 @@ public class RjcConnection implements RedisConnection { } @Override - public void setRange(byte[] key, long offset, byte[] value) { + public void setRange(byte[] key, byte[] value, long offset) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java index d3588856c..b40867607 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/DecodeUtils.java @@ -43,7 +43,7 @@ public abstract class DecodeUtils { } public static byte[] encode(String string) { - return Base64.decode(string); + return (string == null ? null : Base64.decode(string)); } public static Map encodeMap(Map map) { @@ -66,7 +66,7 @@ public abstract class DecodeUtils { Set set = new LinkedHashSet(keys.size()); for (String string : keys) { - set.add(Base64.decode(string)); + set.add(encode(string)); } return set; } @@ -75,7 +75,7 @@ public abstract class DecodeUtils { List set = new ArrayList(keys.size()); for (String string : keys) { - set.add(Base64.decode(string)); + set.add(encode(string)); } return set; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java index 6e0450465..ae6267bf9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundValueOperations.java @@ -28,21 +28,21 @@ public interface BoundValueOperations extends BoundKeyOperations { void set(V value); + void set(V value, long offset); + void set(V value, long timeout, TimeUnit unit); Boolean setIfAbsent(V value); V get(); + String get(long start, long end); + V getAndSet(V value); Long increment(long delta); Integer append(String value); - String get(int start, int end); - - void set(int start, int end); - Long size(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java index c808847d5..b9ec6b168 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java @@ -58,7 +58,7 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp } @Override - public String get(int start, int end) { + public String get(long start, long end) { return ops.get(getKey(), start, end); } @@ -78,8 +78,8 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp } @Override - public void set(int start, int end) { - ops.set(getKey(), start, end); + public void set(V value, long offset) { + ops.set(getKey(), value, offset); } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java index 37172140a..bc2c13d0d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java @@ -96,7 +96,7 @@ class DefaultValueOperations extends AbstractOperations implements V } @Override - public String get(K key, final int start, final int end) { + public String get(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); byte[] rawReturn = execute(new RedisCallback() { @@ -217,13 +217,14 @@ class DefaultValueOperations extends AbstractOperations implements V @Override - public void set(K key, final int start, final int end) { + public void set(K key, final V value, final long offset) { final byte[] rawKey = rawKey(key); + final byte[] rawValue = rawValue(value); execute(new RedisCallback() { @Override public Object doInRedis(RedisConnection connection) { - connection.setRange(rawKey, start, end); + connection.setRange(rawKey, rawValue, offset); return null; } }, true); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 6358593c5..cf614f956 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -377,7 +377,7 @@ 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}. * - * @see ValueOperations#get(Object, int, int) + * @see ValueOperations#get(Object, long, long) * @param stringSerializer The stringValueSerializer to set. */ public void setStringSerializer(RedisSerializer stringSerializer) { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java index 3fd581ad0..133922952 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/ValueOperations.java @@ -47,9 +47,9 @@ public interface ValueOperations { Integer append(K key, String value); - String get(K key, int start, int end); + String get(K key, long start, long end); - void set(K key, int start, int end); + void set(K key, V value, long offset); Long size(K key); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index afe8e7219..d3056e4bc 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -69,16 +69,19 @@ public abstract class AbstractConnectionIntegrationTests { @Test public void testLPush() throws Exception { - Long index = connection.lPush(listName.getBytes(), "bar".getBytes()); + byte[] val = "bar".getBytes(); + Long index = connection.lPush(listName.getBytes(), val); if (index != null) { - assertEquals((Long) (index + 1), connection.lPush(listName.getBytes(), "bar".getBytes())); + assertEquals((Long) (index + 1), connection.lPush(listName.getBytes(), val)); } } @Test public void testSetAndGet() { - connection.set("foo".getBytes(), "blahblah".getBytes()); - assertEquals("blahblah", new String(connection.get("foo".getBytes()))); + String key = "foo"; + String value = "blabla"; + connection.set(key.getBytes(), value.getBytes()); + assertEquals(value, new String(connection.get(key.getBytes()))); } private boolean isJredis() { diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionIntegrationTests.java new file mode 100644 index 000000000..8bbe97356 --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionIntegrationTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import org.idevlab.rjc.Session; +import org.junit.Test; +import org.springframework.data.keyvalue.redis.SettingsUtils; +import org.springframework.data.keyvalue.redis.connection.AbstractConnectionIntegrationTests; +import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; + +/** + * @author Costin Leau + */ +public class RjcConnectionIntegrationTests extends AbstractConnectionIntegrationTests { + + RjcConnectionFactory factory; + + public RjcConnectionIntegrationTests() { + factory = new RjcConnectionFactory(); + factory.setPort(SettingsUtils.getPort()); + factory.setHostName(SettingsUtils.getHost()); + + factory.setUsePool(true); + factory.afterPropertiesSet(); + } + + @Override + protected RedisConnectionFactory getConnectionFactory() { + return factory; + } + + @Test + public void testRaw() throws Exception { + Session jr = (Session) factory.getConnection().getNativeConnection(); + + System.out.println(jr.dbSize()); + System.out.println(jr.exists("foobar")); + jr.set("foobar", "barfoo"); + System.out.println(jr.get("foobar")); + } +} diff --git a/spring-data-redis/template.mf b/spring-data-redis/template.mf index 6c01d8133..27a5e02c3 100644 --- a/spring-data-redis/template.mf +++ b/spring-data-redis/template.mf @@ -22,7 +22,7 @@ Import-Template: org.jredis.ri.alphazero.*;version="[1.0.0, 2.0.0)", redis.clients.jedis.*;version=${jedis.range}, redis.clients.util.*;version=${jedis.range}, + org.idevlab.rjc.*;version=${rjc.range}, org.apache.commons.pool.impl.*;version="[1.0.0, 3.0.0)", org.codehaus.jackson.*;version=${jackson.range}, - org.apache.commons.beanutils.*;version="[1.8.0, 2.0.0)" - + org.apache.commons.beanutils.*;version=1.8.5 \ No newline at end of file From 3b736216c02f9a0a7c6ab37ef9d6003db79a9fca Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 15:26:02 +0200 Subject: [PATCH 32/68] + update setRange signature --- .../keyvalue/redis/connection/DefaultStringRedisConnection.java | 2 +- .../data/keyvalue/redis/connection/StringRedisConnection.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index adb2cd1f4..ef24430de 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -919,7 +919,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } @Override - public void setRange(String key, long start, String value) { + public void setRange(String key, String value, long start) { delegate.setRange(serialize(key), serialize(value), start); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java index 53517c8ea..48113abab 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java @@ -97,7 +97,7 @@ public interface StringRedisConnection extends RedisConnection { String getRange(String key, long start, long end); - void setRange(String key, long offset, String value); + void setRange(String key, String value, long offset); Boolean getBit(String key, long offset); From 8c55c2e014d226849fd69623d648f99248abcdfa Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 15:41:29 +0200 Subject: [PATCH 33/68] DATAKV-46 + integrate RJC into integration tests --- .../collections/CollectionTestParams.java | 43 +++++++++++++++--- .../support/collections/RedisMapTests.java | 45 ++++++++++++++----- 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/CollectionTestParams.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/CollectionTestParams.java index e3e5c0d73..e320a974e 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/CollectionTestParams.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/CollectionTestParams.java @@ -22,6 +22,7 @@ import org.springframework.data.keyvalue.redis.Person; import org.springframework.data.keyvalue.redis.SettingsUtils; import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.keyvalue.redis.connection.jredis.JredisConnectionFactory; +import org.springframework.data.keyvalue.redis.connection.rjc.RjcConnectionFactory; import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.serializer.JacksonJsonRedisSerializer; import org.springframework.data.keyvalue.redis.serializer.OxmSerializer; @@ -70,6 +71,7 @@ public abstract class CollectionTestParams { RedisTemplate jsonPersonTemplate = new RedisTemplate(jedisConnFactory); jsonPersonTemplate.setValueSerializer(jsonSerializer); + // jredis JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(); jredisConnFactory.setUsePool(true); @@ -88,15 +90,42 @@ public abstract class CollectionTestParams { RedisTemplate xstreamPersonTemplateJR = new RedisTemplate(jredisConnFactory); xstreamPersonTemplateJR.setValueSerializer(serializer); - - // json JR RedisTemplate jsonPersonTemplateJR = new RedisTemplate(jredisConnFactory); jsonPersonTemplate.setValueSerializer(jsonSerializer); - return Arrays.asList(new Object[][] { { stringFactory, stringTemplateJR }, { personFactory, personTemplateJR }, - { stringFactory, stringTemplate }, { personFactory, personTemplate }, - { stringFactory, xstreamStringTemplate }, { personFactory, xstreamPersonTemplate }, - { stringFactory, xstreamStringTemplateJR }, { personFactory, xstreamPersonTemplateJR }, - { personFactory, jsonPersonTemplate }, { personFactory, jsonPersonTemplateJR } }); + + // rjc + RjcConnectionFactory rjcConnFactory = new RjcConnectionFactory(); + rjcConnFactory.setUsePool(true); + rjcConnFactory.setPort(SettingsUtils.getPort()); + rjcConnFactory.setHostName(SettingsUtils.getHost()); + rjcConnFactory.afterPropertiesSet(); + + RedisTemplate stringTemplateRJC = new RedisTemplate(rjcConnFactory); + RedisTemplate personTemplateRJC = new RedisTemplate(rjcConnFactory); + + RedisTemplate xstreamStringTemplateRJC = new RedisTemplate(); + xstreamStringTemplateRJC.setConnectionFactory(rjcConnFactory); + xstreamStringTemplateRJC.setDefaultSerializer(serializer); + xstreamStringTemplateRJC.afterPropertiesSet(); + + RedisTemplate xstreamPersonTemplateRJC = new RedisTemplate(); + xstreamPersonTemplateRJC.setValueSerializer(serializer); + xstreamPersonTemplateRJC.setConnectionFactory(rjcConnFactory); + xstreamPersonTemplateRJC.afterPropertiesSet(); + + RedisTemplate jsonPersonTemplateRJC = new RedisTemplate(); + jsonPersonTemplateRJC.setValueSerializer(jsonSerializer); + jsonPersonTemplateRJC.setConnectionFactory(rjcConnFactory); + jsonPersonTemplateRJC.afterPropertiesSet(); + + return Arrays.asList(new Object[][] { { stringFactory, stringTemplateRJC }, + { personFactory, personTemplateRJC }, { stringFactory, stringTemplateJR }, + { personFactory, personTemplateJR }, { stringFactory, stringTemplate }, + { personFactory, personTemplate }, { stringFactory, xstreamStringTemplate }, + { personFactory, xstreamPersonTemplate }, { stringFactory, xstreamStringTemplateJR }, + { personFactory, xstreamPersonTemplateJR }, { personFactory, jsonPersonTemplate }, + { personFactory, jsonPersonTemplateJR }, { stringFactory, xstreamStringTemplateRJC }, + { personFactory, xstreamPersonTemplateRJC }, { personFactory, jsonPersonTemplateRJC } }); } } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisMapTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisMapTests.java index 462b0669f..12efc9fc9 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisMapTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisMapTests.java @@ -23,6 +23,7 @@ import org.springframework.data.keyvalue.redis.Person; import org.springframework.data.keyvalue.redis.SettingsUtils; import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.keyvalue.redis.connection.jredis.JredisConnectionFactory; +import org.springframework.data.keyvalue.redis.connection.rjc.RjcConnectionFactory; import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.serializer.JacksonJsonRedisSerializer; import org.springframework.data.keyvalue.redis.serializer.OxmSerializer; @@ -77,7 +78,6 @@ public class RedisMapTests extends AbstractRedisMapTests { xstreamGenericTemplate.setDefaultSerializer(serializer); xstreamGenericTemplate.afterPropertiesSet(); - // json RedisTemplate jsonPersonTemplate = new RedisTemplate(); jsonPersonTemplate.setConnectionFactory(jedisConnFactory); jsonPersonTemplate.setDefaultSerializer(jsonSerializer); @@ -85,34 +85,49 @@ public class RedisMapTests extends AbstractRedisMapTests { jsonPersonTemplate.setHashValueSerializer(jsonStringSerializer); jsonPersonTemplate.afterPropertiesSet(); - + // JRedis JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(); jredisConnFactory.setUsePool(true); - jredisConnFactory.setPort(SettingsUtils.getPort()); jredisConnFactory.setHostName(SettingsUtils.getHost()); - - jredisConnFactory.afterPropertiesSet(); RedisTemplate genericTemplateJR = new RedisTemplate(jredisConnFactory); - RedisTemplate xGenericTemplateJR = new RedisTemplate(); xGenericTemplateJR.setConnectionFactory(jredisConnFactory); xGenericTemplateJR.setDefaultSerializer(serializer); xGenericTemplateJR.afterPropertiesSet(); - RedisTemplate xstreamPersonTemplateJR = new RedisTemplate(jredisConnFactory); - xstreamPersonTemplateJR.setValueSerializer(serializer); - - // json JR RedisTemplate jsonPersonTemplateJR = new RedisTemplate(); jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory); jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer); jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer); jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer); jsonPersonTemplateJR.afterPropertiesSet(); - + + // RJC + + // rjc + RjcConnectionFactory rjcConnFactory = new RjcConnectionFactory(); + rjcConnFactory.setUsePool(true); + rjcConnFactory.setPort(SettingsUtils.getPort()); + rjcConnFactory.setHostName(SettingsUtils.getHost()); + rjcConnFactory.afterPropertiesSet(); + + RedisTemplate genericTemplateRJC = new RedisTemplate(jredisConnFactory); + RedisTemplate xGenericTemplateRJC = new RedisTemplate(); + xGenericTemplateRJC.setConnectionFactory(rjcConnFactory); + xGenericTemplateRJC.setDefaultSerializer(serializer); + xGenericTemplateRJC.afterPropertiesSet(); + + RedisTemplate jsonPersonTemplateRJC = new RedisTemplate(); + jsonPersonTemplateRJC.setConnectionFactory(rjcConnFactory); + jsonPersonTemplateRJC.setDefaultSerializer(jsonSerializer); + jsonPersonTemplateRJC.setHashKeySerializer(jsonSerializer); + jsonPersonTemplateRJC.setHashValueSerializer(jsonStringSerializer); + jsonPersonTemplateRJC.afterPropertiesSet(); + + return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate }, { personFactory, personFactory, genericTemplate }, { stringFactory, personFactory, genericTemplate }, { personFactory, stringFactory, genericTemplate }, @@ -123,6 +138,12 @@ public class RedisMapTests extends AbstractRedisMapTests { { personFactory, stringFactory, genericTemplateJR }, { personFactory, stringFactory, xGenericTemplateJR }, { personFactory, stringFactory, jsonPersonTemplate }, - { personFactory, stringFactory, jsonPersonTemplateJR } }); + { personFactory, stringFactory, jsonPersonTemplateJR }, + { stringFactory, stringFactory, genericTemplateRJC }, + { personFactory, personFactory, genericTemplateRJC }, + { stringFactory, personFactory, genericTemplateRJC }, + { personFactory, stringFactory, genericTemplateRJC }, + { personFactory, stringFactory, xGenericTemplateRJC }, + { personFactory, stringFactory, jsonPersonTemplateRJC } }); } } \ No newline at end of file From 3757419ae1eb8ff29ba9a1d801e463c0ddde4f4d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 16 Mar 2011 16:30:37 +0200 Subject: [PATCH 34/68] DATAKV-46 + fix some other minor bugs (pubsub support still doesn't work for RJC) --- .../redis/connection/rjc/RjcConnection.java | 6 ++--- .../redis/connection/rjc/RjcUtils.java | 4 ++++ .../JRedisConnectionIntegrationTests.java | 22 ++++++++++++++++++- .../redis/listener/PubSubTestParams.java | 16 +++++++++++++- .../keyvalue/redis/listener/PubSubTests.java | 19 +++++----------- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 78e5a2dff..c331b00b8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -57,8 +57,8 @@ public class RjcConnection implements RedisConnection { public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { SingleDataSource connectionDataSource = new SingleDataSource(connection); session = new SessionFactoryImpl(connectionDataSource).create(); - client = new Client(connection); subscriber = new RedisNodeSubscriber(connectionDataSource); + client = new Client(connection); this.dbIndex = dbIndex; @@ -1731,7 +1731,7 @@ public class RjcConnection implements RedisConnection { pipeline.zscore(stringKey, stringValue); return null; } - return Double.valueOf(session.zscore(stringKey, stringValue)); + return RjcUtils.convert(session.zscore(stringKey, stringValue)); } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -2031,7 +2031,7 @@ public class RjcConnection implements RedisConnection { } subscription = new RjcSubscription(listener, subscriber); - subscription.pSubscribe(channels); + subscription.subscribe(channels); } catch (Exception ex) { throw convertRjcAccessException(ex); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java index 50c92316f..afbb7cc68 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java @@ -216,4 +216,8 @@ public abstract class RjcUtils { } return result; } + + static Double convert(String zscore) { + return (zscore == null ? null : Double.valueOf(zscore)); + } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java index 09e1c91d8..07cdfcf29 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -54,4 +54,24 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat @Ignore("JRedis does not support pipelining") public void testNullCollections() { } -} + + @Ignore + public void testNullKey() throws Exception { + } + + @Ignore + public void testNullValue() throws Exception { + } + + @Ignore + public void testHashNullKey() throws Exception { + } + + @Ignore + public void testHashNullValue() throws Exception { + } + + @Ignore + public void testNullSerialization() throws Exception { + } +} \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java index 78dd27889..28fd764c3 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java @@ -21,6 +21,7 @@ import java.util.Collection; import org.springframework.data.keyvalue.redis.Person; import org.springframework.data.keyvalue.redis.SettingsUtils; import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.keyvalue.redis.connection.rjc.RjcConnectionFactory; import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.core.StringRedisTemplate; import org.springframework.data.keyvalue.redis.support.collections.ObjectFactory; @@ -48,7 +49,20 @@ public class PubSubTestParams { RedisTemplate stringTemplate = new StringRedisTemplate(jedisConnFactory); RedisTemplate personTemplate = new RedisTemplate(jedisConnFactory); + // create RJC - return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate } }); + RjcConnectionFactory rjcConnFactory = new RjcConnectionFactory(); + rjcConnFactory.setUsePool(false); + rjcConnFactory.setPort(SettingsUtils.getPort()); + rjcConnFactory.setHostName(SettingsUtils.getHost()); + rjcConnFactory.afterPropertiesSet(); + + RedisTemplate stringTemplateRJC = new StringRedisTemplate(rjcConnFactory); + RedisTemplate personTemplateRJC = new RedisTemplate(rjcConnFactory); + + + return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate } + //,{ stringFactory, stringTemplateRJC }, { personFactory, personTemplateRJC } + }); } } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java index 3f9f5a59d..55bb59fb8 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java @@ -32,8 +32,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; +import org.springframework.data.keyvalue.redis.ConnectionFactoryTracker; import org.springframework.data.keyvalue.redis.core.RedisTemplate; import org.springframework.data.keyvalue.redis.listener.adapter.MessageListenerAdapter; import org.springframework.data.keyvalue.redis.support.collections.ObjectFactory; @@ -51,7 +50,6 @@ public class PubSubTests { protected RedisMessageListenerContainer container; protected ObjectFactory factory; protected RedisTemplate template; - private static Set connFactories = new LinkedHashSet(); private final BlockingDeque bag = new LinkedBlockingDeque(99); @@ -84,21 +82,12 @@ public class PubSubTests { public PubSubTests(ObjectFactory factory, RedisTemplate template) { this.factory = factory; this.template = template; - connFactories.add(template.getConnectionFactory()); + ConnectionFactoryTracker.add(template.getConnectionFactory()); } @AfterClass public static void cleanUp() { - if (connFactories != null) { - for (RedisConnectionFactory connectionFactory : connFactories) { - try { - ((DisposableBean) connectionFactory).destroy(); - System.out.println("Succesfully cleaned up factory " + connectionFactory); - } catch (Exception ex) { - System.err.println("Cannot clean factory " + connectionFactory + ex); - } - } - } + ConnectionFactoryTracker.cleanUp(); } @Parameters @@ -126,6 +115,8 @@ public class PubSubTests { set.add(bag.poll(1, TimeUnit.SECONDS)); set.add(bag.poll(1, TimeUnit.SECONDS)); + System.out.println(set); + assertTrue(set.contains(payload1)); assertTrue(set.contains(payload2)); } From 96bd74cb2221bf819b06267a2fd583c1bae47430 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 09:46:16 +0200 Subject: [PATCH 35/68] DATAKV-48 + eliminate some of the Jackson unchecked warnings --- .../data/keyvalue/redis/hash/JacksonHashMapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java index 895e0edfb..1f4d0d105 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java @@ -30,7 +30,7 @@ public class JacksonHashMapper implements HashMapper { private final ObjectMapper mapper; private final JavaType userType; - private final JavaType mapType = TypeFactory.type(Map.class); + private final JavaType mapType = TypeFactory.mapType(Map.class, String.class, Object.class); public JacksonHashMapper(Class type) { this(type, new ObjectMapper()); @@ -47,7 +47,6 @@ public class JacksonHashMapper implements HashMapper { return (T) mapper.convertValue(hash, userType); } - @SuppressWarnings("unchecked") @Override public Map toHash(T object) { return mapper.convertValue(object, mapType); From e49318001f524ad1eaf23d48a034b99fd4a1efe9 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 13:56:53 +0200 Subject: [PATCH 36/68] + rename the exceptions to be more consistent --- ...ception.java => RedisSystemException.java} | 4 +- .../DefaultStringRedisConnection.java | 4 +- .../RedisInvalidSubscriptionException.java | 45 +++++++++++++++++++ .../RedisSubscribedConnectionException.java} | 12 ++--- .../redis/connection/Subscription.java | 9 ++-- .../connection/jedis/JedisConnection.java | 8 ++-- .../redis/connection/jedis/JedisUtils.java | 6 +-- .../connection/jredis/JredisConnection.java | 4 +- .../redis/connection/rjc/RjcConnection.java | 21 ++++++--- .../redis/connection/rjc/RjcUtils.java | 6 +-- .../redis/connection/rjc/package-info.java | 5 +++ .../adapter/MessageListenerAdapter.java | 4 +- ...edisListenerExecutionFailedException.java} | 10 ++--- 13 files changed, 100 insertions(+), 38 deletions(-) rename spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/{UncategorizedRedisException.java => RedisSystemException.java} (85%) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisInvalidSubscriptionException.java rename spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/{SubscribedRedisConnectionException.java => connection/RedisSubscribedConnectionException.java} (74%) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/package-info.java rename spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/{ListenerExecutionFailedException.java => RedisListenerExecutionFailedException.java} (71%) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/UncategorizedRedisException.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/RedisSystemException.java similarity index 85% rename from spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/UncategorizedRedisException.java rename to spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/RedisSystemException.java index 664a23403..b72123868 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/UncategorizedRedisException.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/RedisSystemException.java @@ -23,9 +23,9 @@ import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; * * @author Costin Leau */ -public class UncategorizedRedisException extends UncategorizedKeyvalueStoreException { +public class RedisSystemException extends UncategorizedKeyvalueStoreException { - public UncategorizedRedisException(String msg, Throwable cause) { + public RedisSystemException(String msg, Throwable cause) { super(msg, cause); } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index ef24430de..eb70967f3 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -23,7 +23,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import org.springframework.data.keyvalue.redis.UncategorizedRedisException; +import org.springframework.data.keyvalue.redis.RedisSystemException; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; import org.springframework.data.keyvalue.redis.serializer.SerializationUtils; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; @@ -88,7 +88,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.bRPopLPush(timeout, srcKey, dstKey); } - public void close() throws UncategorizedRedisException { + public void close() throws RedisSystemException { delegate.close(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisInvalidSubscriptionException.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisInvalidSubscriptionException.java new file mode 100644 index 000000000..485a87bae --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisInvalidSubscriptionException.java @@ -0,0 +1,45 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection; + +import org.springframework.dao.InvalidDataAccessResourceUsageException; + +/** + * Exception thrown when subscribing to an expired/dead {@link Subscription}. + * + * @author Costin Leau + */ +public class RedisInvalidSubscriptionException extends InvalidDataAccessResourceUsageException { + + /** + * Constructs a new RedisInvalidSubscriptionException instance. + * + * @param msg + * @param cause + */ + public RedisInvalidSubscriptionException(String msg, Throwable cause) { + super(msg, cause); + } + + /** + * Constructs a new RedisInvalidSubscriptionException instance. + * + * @param msg + */ + public RedisInvalidSubscriptionException(String msg) { + super(msg); + } +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/SubscribedRedisConnectionException.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisSubscribedConnectionException.java similarity index 74% rename from spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/SubscribedRedisConnectionException.java rename to spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisSubscribedConnectionException.java index 2a1945e57..bcc93bab7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/SubscribedRedisConnectionException.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisSubscribedConnectionException.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.keyvalue.redis; +package org.springframework.data.keyvalue.redis.connection; import org.springframework.dao.InvalidDataAccessApiUsageException; @@ -24,24 +24,24 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; * @author Costin Leau * @see org.springframework.data.keyvalue.redis.connection.RedisPubSubCommands */ -public class SubscribedRedisConnectionException extends InvalidDataAccessApiUsageException { +public class RedisSubscribedConnectionException extends InvalidDataAccessApiUsageException { /** - * Constructs a new SubscribedRedisConnectionException instance. + * Constructs a new RedisSubscribedConnectionException instance. * * @param msg * @param cause */ - public SubscribedRedisConnectionException(String msg, Throwable cause) { + public RedisSubscribedConnectionException(String msg, Throwable cause) { super(msg, cause); } /** - * Constructs a new SubscribedRedisConnectionException instance. + * Constructs a new RedisSubscribedConnectionException instance. * * @param msg */ - public SubscribedRedisConnectionException(String msg) { + public RedisSubscribedConnectionException(String msg) { super(msg); } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/Subscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/Subscription.java index 3000820f1..bdad9ae35 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/Subscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/Subscription.java @@ -18,7 +18,10 @@ package org.springframework.data.keyvalue.redis.connection; import java.util.Collection; /** - * Subscription for Redis channels. + * 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 */ @@ -29,14 +32,14 @@ public interface Subscription { * * @param channels channel names */ - void subscribe(byte[]... channels); + void subscribe(byte[]... channels) throws RedisInvalidSubscriptionException; /** * Adds the given channel patterns to the current subscription. * * @param patterns channel patterns */ - void pSubscribe(byte[]... patterns); + void pSubscribe(byte[]... patterns) throws RedisInvalidSubscriptionException; /** * Cancels the current subscription for all channels given by name. diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 3cf0a1c08..41f1c82e5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -26,11 +26,11 @@ import java.util.Set; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; -import org.springframework.data.keyvalue.redis.SubscribedRedisConnectionException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.SortParameters; +import org.springframework.data.keyvalue.redis.connection.RedisSubscribedConnectionException; import org.springframework.data.keyvalue.redis.connection.Subscription; import org.springframework.util.ReflectionUtils; @@ -2205,7 +2205,7 @@ public class JedisConnection implements RedisConnection { @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { - throw new SubscribedRedisConnectionException( + throw new RedisSubscribedConnectionException( "Connection already subscribed; use the connection Subscription to cancel or add new channels"); } @@ -2229,7 +2229,7 @@ public class JedisConnection implements RedisConnection { @Override public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { - throw new SubscribedRedisConnectionException( + throw new RedisSubscribedConnectionException( "Connection already subscribed; use the connection Subscription to cancel or add new channels"); } @@ -2252,7 +2252,7 @@ public class JedisConnection implements RedisConnection { private void checkSubscription() { if (isSubscribed()) { - throw new SubscribedRedisConnectionException("Cannot execute command - connection is subscribed"); + throw new RedisSubscribedConnectionException("Cannot execute command - connection is subscribed"); } } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java index b76e1d08a..06b0011da 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisUtils.java @@ -29,7 +29,7 @@ import java.util.concurrent.TimeoutException; import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.keyvalue.redis.RedisConnectionFailureException; -import org.springframework.data.keyvalue.redis.UncategorizedRedisException; +import org.springframework.data.keyvalue.redis.RedisSystemException; import org.springframework.data.keyvalue.redis.connection.DefaultTuple; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.SortParameters; @@ -87,7 +87,7 @@ public abstract class JedisUtils { return convertJedisAccessException((JedisException) ex); } - return new UncategorizedRedisException("Unknown exception", ex); + return new RedisSystemException("Unknown exception", ex); } static DataAccessException convertJedisAccessException(IOException ex) { @@ -198,7 +198,7 @@ public abstract class JedisUtils { try { info.load(stringReader); } catch (Exception ex) { - throw new UncategorizedRedisException("Cannot read Redis info", ex); + throw new RedisSystemException("Cannot read Redis info", ex); } finally { stringReader.close(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 4339dcdf5..3d28fb2a7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -31,7 +31,7 @@ import org.jredis.Query.Support; import org.jredis.ri.alphazero.JRedisService; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; -import org.springframework.data.keyvalue.redis.UncategorizedRedisException; +import org.springframework.data.keyvalue.redis.RedisSystemException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnection; @@ -75,7 +75,7 @@ public class JredisConnection implements RedisConnection { } @Override - public void close() throws UncategorizedRedisException { + public void close() throws RedisSystemException { isClosed = true; // don't actually close the connection diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index c331b00b8..269456cc3 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -30,11 +30,11 @@ import org.idevlab.rjc.ZParams; import org.idevlab.rjc.message.RedisNodeSubscriber; import org.springframework.dao.DataAccessException; import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; -import org.springframework.data.keyvalue.redis.SubscribedRedisConnectionException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.SortParameters; +import org.springframework.data.keyvalue.redis.connection.RedisSubscribedConnectionException; import org.springframework.data.keyvalue.redis.connection.Subscription; /** @@ -54,6 +54,8 @@ public class RjcConnection implements RedisConnection { private volatile RjcSubscription subscription; private volatile RedisNodeSubscriber subscriber; + private final Object pubSubMonitor = new Object(); + public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { SingleDataSource connectionDataSource = new SingleDataSource(connection); session = new SessionFactoryImpl(connectionDataSource).create(); @@ -1995,7 +1997,7 @@ public class RjcConnection implements RedisConnection { @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { - throw new SubscribedRedisConnectionException( + throw new RedisSubscribedConnectionException( "Connection already subscribed; use the connection Subscription to cancel or add new channels"); } @@ -2007,9 +2009,12 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber); + subscription = new RjcSubscription(listener, subscriber, pubSubMonitor); subscription.pSubscribe(patterns); + synchronized (pubSubMonitor) { + pubSubMonitor.wait(); + } } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -2018,7 +2023,7 @@ public class RjcConnection implements RedisConnection { @Override public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { - throw new SubscribedRedisConnectionException( + throw new RedisSubscribedConnectionException( "Connection already subscribed; use the connection Subscription to cancel or add new channels"); } @@ -2030,8 +2035,12 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber); + subscription = new RjcSubscription(listener, subscriber, pubSubMonitor); subscription.subscribe(channels); + + synchronized (pubSubMonitor) { + pubSubMonitor.wait(); + } } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -2040,7 +2049,7 @@ public class RjcConnection implements RedisConnection { private void checkSubscription() { if (isSubscribed()) { - throw new SubscribedRedisConnectionException("Cannot execute command - connection is subscribed"); + throw new RedisSubscribedConnectionException("Cannot execute command - connection is subscribed"); } } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java index afbb7cc68..817d47589 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java @@ -31,7 +31,7 @@ import org.idevlab.rjc.ZParams; import org.idevlab.rjc.Client.LIST_POSITION; import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.data.keyvalue.redis.UncategorizedRedisException; +import org.springframework.data.keyvalue.redis.RedisSystemException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.DefaultTuple; import org.springframework.data.keyvalue.redis.connection.SortParameters; @@ -59,7 +59,7 @@ public abstract class RjcUtils { return convertRjcAccessException((RedisException) ex); } - return new UncategorizedRedisException("Unknown exception", ex); + return new RedisSystemException("Unknown exception", ex); } public static DataAccessException convertRjcAccessException(RedisException ex) { @@ -166,7 +166,7 @@ public abstract class RjcUtils { try { info.load(stringReader); } catch (Exception ex) { - throw new UncategorizedRedisException("Cannot read Redis info", ex); + throw new RedisSystemException("Cannot read Redis info", ex); } finally { stringReader.close(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/package-info.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/package-info.java new file mode 100644 index 000000000..66a90b8ae --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/package-info.java @@ -0,0 +1,5 @@ +/** + * Connection package for RJC library. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java index 6affa0dc3..8def8aa52 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java @@ -284,11 +284,11 @@ public class MessageListenerAdapter implements MessageListener { throw (DataAccessException) targetEx; } else { - throw new ListenerExecutionFailedException("Listener method '" + methodName + "' threw exception", + throw new RedisListenerExecutionFailedException("Listener method '" + methodName + "' threw exception", targetEx); } } catch (Throwable ex) { - throw new ListenerExecutionFailedException("Failed to invoke target method '" + methodName + throw new RedisListenerExecutionFailedException("Failed to invoke target method '" + methodName + "' with arguments " + ObjectUtils.nullSafeToString(arguments), ex); } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/ListenerExecutionFailedException.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/RedisListenerExecutionFailedException.java similarity index 71% rename from spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/ListenerExecutionFailedException.java rename to spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/RedisListenerExecutionFailedException.java index cb47028bf..8f94a7a95 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/ListenerExecutionFailedException.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/RedisListenerExecutionFailedException.java @@ -23,24 +23,24 @@ import org.springframework.dao.InvalidDataAccessApiUsageException; * @author Costin Leau * @see MessageListenerAdapter */ -public class ListenerExecutionFailedException extends InvalidDataAccessApiUsageException { +public class RedisListenerExecutionFailedException extends InvalidDataAccessApiUsageException { /** - * Constructs a new ListenerExecutionFailedException instance. + * Constructs a new RedisListenerExecutionFailedException instance. * * @param msg * @param cause */ - public ListenerExecutionFailedException(String msg, Throwable cause) { + public RedisListenerExecutionFailedException(String msg, Throwable cause) { super(msg, cause); } /** - * Constructs a new ListenerExecutionFailedException instance. + * Constructs a new RedisListenerExecutionFailedException instance. * * @param msg */ - public ListenerExecutionFailedException(String msg) { + public RedisListenerExecutionFailedException(String msg) { super(msg); } } From 52fe4cd827183faec02974b515866d6706dd4088 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 13:57:40 +0200 Subject: [PATCH 37/68] DATAKV-49 + add more integration tests --- .../AbstractConnectionIntegrationTests.java | 133 ++++++++++++++++++ .../JedisConnectionIntegrationTests.java | 80 ----------- .../JRedisConnectionIntegrationTests.java | 13 ++ .../redis/listener/PubSubTestParams.java | 4 +- .../keyvalue/redis/listener/PubSubTests.java | 2 +- 5 files changed, 149 insertions(+), 83 deletions(-) diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index d3056e4bc..cb8c408ce 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -22,6 +22,9 @@ import java.util.Arrays; import java.util.List; import java.util.Properties; import java.util.UUID; +import java.util.concurrent.BlockingDeque; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.atomic.AtomicBoolean; import org.junit.After; import org.junit.AfterClass; @@ -184,4 +187,134 @@ public abstract class AbstractConnectionIntegrationTests { assertNull(connection.hKeys("~")); connection.closePipeline(); } + + // pub sub test + + @Test + public void testPubSub() throws Exception { + + final BlockingDeque queue = new LinkedBlockingDeque(); + + final MessageListener ml = new MessageListener() { + @Override + public void onMessage(Message message, byte[] pattern) { + queue.add(message); + System.out.println("received message"); + } + }; + + final byte[] channel = "foo.tv".getBytes(); + final RedisConnection subConn = getConnectionFactory().getConnection(); + + assertNotSame(connection, subConn); + + + final AtomicBoolean flag = new AtomicBoolean(true); + + Runnable listener = new Runnable() { + @Override + public void run() { + subConn.subscribe(ml, channel); + System.out.println("Subscribed"); + while (flag.get()) { + try { + Thread.currentThread().wait(2000); + } catch (Exception ex) { + return; + } + } + } + }; + + Thread th = new Thread(listener, "listener"); + th.start(); + + try { + Thread.sleep(1500); + connection.publish(channel, "one".getBytes()); + connection.publish(channel, "two".getBytes()); + connection.publish(channel, "I see you".getBytes()); + System.out.println("Done publishing..."); + Thread.sleep(3000); + } finally { + flag.set(false); + } + assertEquals(3, queue.size()); + } + + @Test + public void testPubSubWithNamedChannels() { + final byte[] expectedChannel = "channel1".getBytes(); + final byte[] expectedMessage = "msg".getBytes(); + + MessageListener listener = new MessageListener() { + + @Override + public void onMessage(Message message, byte[] pattern) { + assertArrayEquals(expectedChannel, message.getChannel()); + assertArrayEquals(expectedMessage, message.getBody()); + } + }; + + Thread th = new Thread(new Runnable() { + @Override + public void run() { + // sleep 1 second to let the registration happen + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException ex) { + throw new RuntimeException(ex); + } + + // open a new connection + RedisConnection connection2 = getConnectionFactory().getConnection(); + connection2.publish(expectedMessage, expectedChannel); + connection2.close(); + // unsubscribe connection + connection.getSubscription().unsubscribe(); + } + }); + + th.start(); + connection.subscribe(listener, expectedChannel); + } + + @Test + public void testPubSubWithPatterns() { + final byte[] expectedPattern = "channel*".getBytes(); + final byte[] expectedMessage = "msg".getBytes(); + + MessageListener listener = new MessageListener() { + + @Override + public void onMessage(Message message, byte[] pattern) { + assertArrayEquals(expectedPattern, pattern); + assertArrayEquals(expectedMessage, message.getBody()); + System.out.println("Received message '" + new String(message.getBody()) + "'"); + } + }; + + Thread th = new Thread(new Runnable() { + @Override + public void run() { + // sleep 1 second to let the registration happen + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException ex) { + throw new RuntimeException(ex); + } + + // open a new connection + RedisConnection connection2 = getConnectionFactory().getConnection(); + connection2.publish(expectedMessage, "channel1".getBytes()); + connection2.publish(expectedMessage, "channel2".getBytes()); + connection2.close(); + // unsubscribe connection + connection.getSubscription().pUnsubscribe(expectedPattern); + } + }); + + th.start(); + connection.pSubscribe(listener, expectedPattern); + } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionIntegrationTests.java index 75a9e7e87..302a94e49 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionIntegrationTests.java @@ -16,13 +16,9 @@ package org.springframework.data.keyvalue.redis.connection.jedis; -import static org.junit.Assert.*; - import org.junit.Test; import org.springframework.data.keyvalue.redis.SettingsUtils; import org.springframework.data.keyvalue.redis.connection.AbstractConnectionIntegrationTests; -import org.springframework.data.keyvalue.redis.connection.Message; -import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import redis.clients.jedis.BinaryJedis; @@ -47,82 +43,6 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati return factory; } - @Test - public void testPubSubWithNamedChannels() { - final byte[] expectedChannel = "channel1".getBytes(); - final byte[] expectedMessage = "msg".getBytes(); - - MessageListener listener = new MessageListener() { - - @Override - public void onMessage(Message message, byte[] pattern) { - assertArrayEquals(expectedChannel, message.getChannel()); - assertArrayEquals(expectedMessage, message.getBody()); - } - }; - - Thread th = new Thread(new Runnable() { - @Override - public void run() { - // sleep 1 second to let the registration happen - try { - Thread.currentThread().sleep(1000); - } catch (InterruptedException ex) { - throw new RuntimeException(ex); - } - - // open a new connection - JedisConnection connection2 = factory.getConnection(); - connection2.publish(expectedMessage, expectedChannel); - connection2.close(); - // unsubscribe connection - connection.getSubscription().unsubscribe(); - } - }); - - th.start(); - connection.subscribe(listener, expectedChannel); - } - - @Test - public void testPubSubWithPatterns() { - final byte[] expectedPattern = "channel*".getBytes(); - final byte[] expectedMessage = "msg".getBytes(); - - MessageListener listener = new MessageListener() { - - @Override - public void onMessage(Message message, byte[] pattern) { - assertArrayEquals(expectedPattern, pattern); - assertArrayEquals(expectedMessage, message.getBody()); - System.out.println("Received message '" + new String(message.getBody()) + "'"); - } - }; - - Thread th = new Thread(new Runnable() { - @Override - public void run() { - // sleep 1 second to let the registration happen - try { - Thread.currentThread().sleep(1000); - } catch (InterruptedException ex) { - throw new RuntimeException(ex); - } - - // open a new connection - JedisConnection connection2 = factory.getConnection(); - connection2.publish(expectedMessage, "channel1".getBytes()); - connection2.publish(expectedMessage, "channel2".getBytes()); - connection2.close(); - // unsubscribe connection - connection.getSubscription().pUnsubscribe(expectedPattern); - } - }); - - th.start(); - connection.pSubscribe(listener, expectedPattern); - } - @Test public void testMulti() throws Exception { byte[] key = "key".getBytes(); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java index 07cdfcf29..ed92f9f63 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -74,4 +74,17 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat @Ignore public void testNullSerialization() throws Exception { } + + @Ignore + public void testPubSub() throws Exception { + } + + @Ignore + public void testPubSubWithPatterns() { + } + + @Ignore + public void testPubSubWithNamedChannels() { + + } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java index 28fd764c3..cba742c7f 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTestParams.java @@ -61,8 +61,8 @@ public class PubSubTestParams { RedisTemplate personTemplateRJC = new RedisTemplate(rjcConnFactory); - return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate } - //,{ stringFactory, stringTemplateRJC }, { personFactory, personTemplateRJC } + return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate }, + { stringFactory, stringTemplateRJC }, { personFactory, personTemplateRJC } }); } } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java index 55bb59fb8..a61f923f0 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/PubSubTests.java @@ -71,7 +71,7 @@ public class PubSubTests { container.addMessageListener(adapter, Arrays.asList(new ChannelTopic(CHANNEL))); container.afterPropertiesSet(); - Thread.sleep(500); + Thread.sleep(1000); } @After From 202686a0757ac619bbbc85a90932adb61942eb25 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 14:47:20 +0200 Subject: [PATCH 38/68] DATAKV-49 DATAKV-46 + improved pubsub connection support + RJC integration still needs some work --- .../connection/jedis/JedisConnection.java | 4 +- .../connection/jedis/JedisSubscription.java | 123 ++------- .../redis/connection/rjc/RjcSubscription.java | 127 ++------- .../connection/util/AbstractSubscription.java | 253 ++++++++++++++++++ .../connection/util/ByteArrayWrapper.java | 57 ++++ .../redis/connection/util/package-info.java | 5 + .../RedisMessageListenerContainer.java | 52 +--- 7 files changed, 371 insertions(+), 250 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/ByteArrayWrapper.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/package-info.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 41f1c82e5..7d184e2cd 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -29,8 +29,8 @@ import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnection; -import org.springframework.data.keyvalue.redis.connection.SortParameters; import org.springframework.data.keyvalue.redis.connection.RedisSubscribedConnectionException; +import org.springframework.data.keyvalue.redis.connection.SortParameters; import org.springframework.data.keyvalue.redis.connection.Subscription; import org.springframework.util.ReflectionUtils; @@ -2221,6 +2221,7 @@ public class JedisConnection implements RedisConnection { subscription = new JedisSubscription(listener, jedisPubSub, null, patterns); jedis.psubscribe(jedisPubSub, patterns); + } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -2245,6 +2246,7 @@ public class JedisConnection implements RedisConnection { subscription = new JedisSubscription(listener, jedisPubSub, channels, null); jedis.subscribe(jedisPubSub, channels); + } catch (Exception ex) { throw convertJedisAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisSubscription.java index 93dfbeeef..a2be1371a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisSubscription.java @@ -15,13 +15,8 @@ */ package org.springframework.data.keyvalue.redis.connection.jedis; -import java.util.ArrayList; -import java.util.Collection; - import org.springframework.data.keyvalue.redis.connection.MessageListener; -import org.springframework.data.keyvalue.redis.connection.Subscription; -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; +import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscription; import redis.clients.jedis.BinaryJedisPubSub; @@ -30,132 +25,48 @@ import redis.clients.jedis.BinaryJedisPubSub; * * @author Costin Leau */ -class JedisSubscription implements Subscription { +class JedisSubscription extends AbstractSubscription { - private final MessageListener listener; private final BinaryJedisPubSub jedisPubSub; - private final Collection channels = new ArrayList(2); - private final Collection patterns = new ArrayList(2); - JedisSubscription(MessageListener listener, BinaryJedisPubSub jedisPubSub, byte[][] channels, byte[][] patterns) { - Assert.notNull(listener); - this.listener = listener; + super(listener, channels, patterns); this.jedisPubSub = jedisPubSub; - - if (!ObjectUtils.isEmpty(channels)) { - synchronized (this.channels) { - for (byte[] bs : channels) { - this.channels.add(bs); - } - } - } - - if (!ObjectUtils.isEmpty(patterns)) { - synchronized (this.patterns) { - for (byte[] bs : patterns) { - this.patterns.add(bs); - } - } - } } @Override - public Collection getChannels() { - synchronized (channels) { - return new ArrayList(channels); - } - } - - @Override - public MessageListener getListener() { - return listener; - } - - @Override - public Collection getPatterns() { - synchronized (patterns) { - return new ArrayList(patterns); - } - } - - @Override - public void pSubscribe(byte[]... patterns) { - Assert.notEmpty(patterns, "at least one pattern required"); - - synchronized (this.patterns) { - for (byte[] bs : patterns) { - this.patterns.add(bs); - } - } - - jedisPubSub.psubscribe(patterns); - } - - @Override - public void pUnsubscribe() { - synchronized (patterns) { - patterns.clear(); - } + protected void doClose() { + jedisPubSub.unsubscribe(); jedisPubSub.punsubscribe(); } @Override - public void pUnsubscribe(byte[]... patterns) { - if (ObjectUtils.isEmpty(patterns)) { - unsubscribe(); + protected void doPsubscribe(byte[]... patterns) { + jedisPubSub.psubscribe(patterns); + } + + @Override + protected void doPUnsubscribe(boolean all, byte[]... patterns) { + if (all) { + jedisPubSub.punsubscribe(); } - else { - synchronized (this.patterns) { - for (byte[] bs : patterns) { - this.patterns.remove(bs); - } - } - jedisPubSub.punsubscribe(patterns); } } @Override - public void subscribe(byte[]... channels) { - Assert.notEmpty(channels, "at least one channel required"); - - synchronized (this.channels) { - for (byte[] bs : channels) { - this.channels.add(bs); - } - } - + protected void doSubscribe(byte[]... channels) { jedisPubSub.subscribe(channels); } @Override - public void unsubscribe() { - synchronized (channels) { - channels.clear(); - } - jedisPubSub.unsubscribe(); - } - - @Override - public void unsubscribe(byte[]... channels) { - if (ObjectUtils.isEmpty(channels)) { - unsubscribe(); + protected void doUnsubscribe(boolean all, byte[]... channels) { + if (all) { + jedisPubSub.unsubscribe(); } else { - synchronized (this.channels) { - for (byte[] bs : channels) { - this.channels.remove(bs); - } - } - jedisPubSub.unsubscribe(channels); } } - - @Override - public boolean isAlive() { - return jedisPubSub.isSubscribed(); - } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java index a1075a120..fa0aa5a1d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java @@ -15,135 +15,58 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; -import java.util.ArrayList; -import java.util.Collection; - -import org.idevlab.rjc.message.RedisSubscriber; +import org.idevlab.rjc.message.RedisNodeSubscriber; import org.springframework.data.keyvalue.redis.connection.MessageListener; -import org.springframework.data.keyvalue.redis.connection.Subscription; -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; +import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscription; /** * Message subscription on top of RJC. * * @author Costin Leau */ -class RjcSubscription implements Subscription { +class RjcSubscription extends AbstractSubscription { - private final MessageListener listener; - private final RedisSubscriber subscriber; + private final RedisNodeSubscriber subscriber; private final RjcMessageListener listenerAdapter; + private final Object pubSubMonitor; - private final Collection channels = new ArrayList(2); - private final Collection patterns = new ArrayList(2); - - RjcSubscription(MessageListener listener, RedisSubscriber subscriber) { - Assert.notNull(listener); - this.listener = listener; + RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber, Object pubSubMonitor) { + super(listener); this.subscriber = subscriber; this.listenerAdapter = new RjcMessageListener(listener); + this.pubSubMonitor = pubSubMonitor; } @Override - public Collection getChannels() { - synchronized (channels) { - return new ArrayList(channels); + protected void doClose() { + subscriber.close(); + } + + @Override + protected void doPsubscribe(byte[]... patterns) { + for (String str : RjcUtils.decodeMultiple(patterns)) { + subscriber.psubscribe(str, listenerAdapter); } } @Override - public MessageListener getListener() { - return listener; - } - - @Override - public Collection getPatterns() { - synchronized (patterns) { - return new ArrayList(patterns); + protected void doPUnsubscribe(boolean all, byte[]... patterns) { + for (String str : RjcUtils.decodeMultiple(patterns)) { + subscriber.punsubscribe(str); } } @Override - public void pSubscribe(byte[]... patterns) { - Assert.notEmpty(patterns, "at least one pattern required"); - - synchronized (this.patterns) { - for (byte[] bs : patterns) { - this.patterns.add(bs); - } - } - - for (String pattern : RjcUtils.decodeMultiple(patterns)) { - subscriber.psubscribe(pattern, listenerAdapter); + protected void doSubscribe(byte[]... channels) { + for (String str : RjcUtils.decodeMultiple(channels)) { + subscriber.subscribe(str, listenerAdapter); } } @Override - public void pUnsubscribe() { - pUnsubscribe(null); - - synchronized (patterns) { - patterns.clear(); + protected void doUnsubscribe(boolean all, byte[]... channels) { + for (String str : RjcUtils.decodeMultiple(channels)) { + subscriber.unsubscribe(str); } } - - @Override - public void pUnsubscribe(byte[]... patterns) { - if (ObjectUtils.isEmpty(patterns)) { - patterns = this.patterns.toArray(new byte[this.patterns.size()][]); - } - - synchronized (this.patterns) { - for (byte[] bs : patterns) { - this.patterns.remove(bs); - } - } - - subscriber.punsubscribe(RjcUtils.decodeMultiple(patterns)); - } - - @Override - public void subscribe(byte[]... channels) { - Assert.notEmpty(channels, "at least one channel required"); - - synchronized (this.channels) { - for (byte[] bs : channels) { - this.channels.add(bs); - } - } - - for (String channel : RjcUtils.decodeMultiple(channels)) { - subscriber.subscribe(channel, listenerAdapter); - } - } - - @Override - public void unsubscribe() { - unsubscribe(null); - - synchronized (patterns) { - patterns.clear(); - } - } - - @Override - public void unsubscribe(byte[]... channels) { - if (ObjectUtils.isEmpty(channels)) { - channels = this.channels.toArray(new byte[this.channels.size()][]); - } - - synchronized (this.channels) { - for (byte[] bs : channels) { - this.channels.remove(bs); - } - } - - subscriber.punsubscribe(RjcUtils.decodeMultiple(channels)); - } - - @Override - public boolean isAlive() { - return (!channels.isEmpty() || !patterns.isEmpty()); - } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java new file mode 100644 index 000000000..76dfbfec1 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java @@ -0,0 +1,253 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.util; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.springframework.data.keyvalue.redis.connection.MessageListener; +import org.springframework.data.keyvalue.redis.connection.RedisInvalidSubscriptionException; +import org.springframework.data.keyvalue.redis.connection.Subscription; +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. + * + * @author Costin Leau + */ +public abstract class AbstractSubscription implements Subscription { + + private final Collection channels = new ArrayList(2); + private final Collection patterns = new ArrayList(2); + private final AtomicBoolean alive = new AtomicBoolean(true); + private final MessageListener listener; + + protected AbstractSubscription(MessageListener listener) { + this(listener, null, null); + } + + /** + * 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 + */ + protected AbstractSubscription(MessageListener listener, byte[][] channels, byte[][] patterns) { + Assert.notNull(listener); + this.listener = listener; + + synchronized (this.channels) { + remove(this.channels, channels); + } + synchronized (this.patterns) { + remove(this.patterns, patterns); + } + } + + /** + * Subscribe to the given channels. + * + * @param channels channels to subscribe to + */ + protected abstract void doSubscribe(byte[]... channels); + + /** + * Channel unsubscribe. + * + * @param all true if all the channels are unsubscribed (used as a hint for the underlying implementation). + * @param channels channels to be unsubscribed + */ + protected abstract void doUnsubscribe(boolean all, byte[]... channels); + + /** + * Subscribe to the given patterns + * + * @param patterns patterns to subscribe to + */ + protected abstract void doPsubscribe(byte[]... patterns); + + /** + * Pattern unsubscribe. + * + * @param all true if all the patterns are unsubscribed (used as a hint for the underlying implementation). + * @param patterns patterns to be unsubscribed + */ + protected abstract void doPUnsubscribe(boolean all, byte[]... patterns); + + /** + * Shutdown the subscription and free any resources held. + */ + protected abstract void doClose(); + + @Override + public MessageListener getListener() { + return listener; + } + + @Override + public Collection getChannels() { + synchronized (channels) { + return clone(channels); + } + } + + @Override + public Collection getPatterns() { + synchronized (patterns) { + return clone(patterns); + } + } + + @Override + public void pSubscribe(byte[]... patterns) { + checkPulse(); + + Assert.notEmpty(patterns, "at least one pattern required"); + + synchronized (this.patterns) { + add(this.patterns, patterns); + } + + doPsubscribe(patterns); + } + + @Override + public void pUnsubscribe() { + pUnsubscribe((byte[][]) null); + } + + + @Override + public void subscribe(byte[]... channels) { + checkPulse(); + + Assert.notEmpty(channels, "at least one channel required"); + + synchronized (this.channels) { + add(this.channels, channels); + } + + doSubscribe(channels); + } + + @Override + public void unsubscribe() { + unsubscribe((byte[][]) null); + } + + @Override + public void pUnsubscribe(byte[]... patts) { + if (!isAlive()) { + return; + } + + // shortcut for unsubscribing all patterns + if (ObjectUtils.isEmpty(patts)) { + if (!this.patterns.isEmpty()) { + patts = getPatterns().toArray(new byte[this.patterns.size()][]); + synchronized (this.patterns) { + this.patterns.clear(); + } + } + } + else { + synchronized (this.patterns) { + remove(this.patterns, patts); + } + } + + if (isWorking()) { + doPUnsubscribe(this.patterns.isEmpty(), patts); + } + } + + @Override + public void unsubscribe(byte[]... chans) { + if (!isAlive()) { + return; + } + + // shortcut for unsubscribing all channels + if (ObjectUtils.isEmpty(chans)) { + if (!this.channels.isEmpty()) { + chans = getPatterns().toArray(new byte[this.channels.size()][]); + synchronized (this.channels) { + this.channels.clear(); + } + } + } + else { + synchronized (this.channels) { + remove(this.channels, chans); + } + } + + if (isWorking()) { + doUnsubscribe(this.channels.isEmpty(), chans); + } + } + + @Override + public boolean isAlive() { + return alive.get(); + } + + private void checkPulse() { + if (!isAlive()) { + throw new RedisInvalidSubscriptionException("Subscription has been unsubscribed and cannot be used anymore"); + } + } + + private boolean isWorking() { + if (channels.isEmpty() && patterns.isEmpty()) { + alive.set(false); + doClose(); + } + return isAlive(); + } + + + private static Collection clone(Collection col) { + Collection list = new ArrayList(col.size()); + for (ByteArrayWrapper wrapper : col) { + list.add(wrapper.getArray().clone()); + } + return list; + } + + + private static void add(Collection col, byte[]... bytes) { + if (!ObjectUtils.isEmpty(bytes)) { + for (byte[] bs : bytes) { + col.add(new ByteArrayWrapper(bs)); + } + } + } + + private static void remove(Collection col, byte[]... bytes) { + if (!ObjectUtils.isEmpty(bytes)) { + for (byte[] bs : bytes) { + col.remove(new ByteArrayWrapper(bs)); + } + } + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/ByteArrayWrapper.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/ByteArrayWrapper.java new file mode 100644 index 000000000..7c708192b --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/ByteArrayWrapper.java @@ -0,0 +1,57 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.util; + +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 { + + private final byte[] array; + private final int hashCode; + + public ByteArrayWrapper(byte[] array) { + this.array = array; + this.hashCode = Arrays.hashCode(array); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ByteArrayWrapper) { + return Arrays.equals(array, ((ByteArrayWrapper) obj).array); + } + + return false; + } + + @Override + public int hashCode() { + return hashCode; + } + + /** + * Returns the array. + * + * @return Returns the array + */ + public byte[] getArray() { + return array; + } +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/package-info.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/package-info.java new file mode 100644 index 000000000..c8f07d8ce --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/package-info.java @@ -0,0 +1,5 @@ +/** + * Internal utility package for encoding/decoding Strings to byte[] (using Base64) library. + */ +package org.springframework.data.keyvalue.redis.connection.util; + diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java index 1c9676e4c..0691b8363 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java @@ -16,7 +16,6 @@ package org.springframework.data.keyvalue.redis.listener; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -39,6 +38,7 @@ import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.data.keyvalue.redis.connection.Subscription; +import org.springframework.data.keyvalue.redis.connection.util.ByteArrayWrapper; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; import org.springframework.scheduling.SchedulingAwareRunnable; @@ -101,9 +101,9 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab // 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>(); + private final Map> patternMapping = new ConcurrentHashMap>(); // lookup map between channels and listeners - private final Map> channelMapping = new ConcurrentHashMap>(); + private final Map> channelMapping = new ConcurrentHashMap>(); private final SubscriptionTask subscriptionTask = new SubscriptionTask(); @@ -448,7 +448,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab for (Topic topic : topics) { - ArrayHolder holder = new ArrayHolder(serializer.serialize(topic.getTopic())); + ByteArrayWrapper holder = new ByteArrayWrapper(serializer.serialize(topic.getTopic())); if (topic instanceof ChannelTopic) { Collection collection = channelMapping.get(holder); @@ -457,7 +457,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab channelMapping.put(holder, collection); } collection.add(listener); - channels.add(holder.array); + channels.add(holder.getArray()); if (trace) logger.trace("Adding listener '" + listener + "' on channel '" + topic.getTopic() + "'"); @@ -470,7 +470,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab patternMapping.put(holder, collection); } collection.add(listener); - patterns.add(holder.array); + patterns.add(holder.getArray()); if (trace) logger.trace("Adding listener '" + listener + "' for pattern '" + topic.getTopic() + "'"); @@ -598,7 +598,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } - private byte[][] unwrap(Collection holders) { + private byte[][] unwrap(Collection holders) { if (CollectionUtils.isEmpty(holders)) { return new byte[0][]; } @@ -606,8 +606,8 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab byte[][] unwrapped = new byte[holders.size()][]; int index = 0; - for (ArrayHolder arrayHolder : holders) { - unwrapped[index++] = arrayHolder.array; + for (ByteArrayWrapper arrayHolder : holders) { + unwrapped[index++] = arrayHolder.getArray(); } return unwrapped; @@ -700,12 +700,12 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab // do channel matching first byte[] channel = message.getChannel(); - Collection ch = channelMapping.get(new ArrayHolder(channel)); + Collection ch = channelMapping.get(new ByteArrayWrapper(channel)); Collection pt = null; // followed by pattern matching if (pattern != null && pattern.length > 0) { - pt = patternMapping.get(new ArrayHolder(pattern)); + pt = patternMapping.get(new ByteArrayWrapper(pattern)); } if (!CollectionUtils.isEmpty(ch)) { @@ -739,34 +739,4 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } } - - /** - * Simple wrapper class used for wrapping arrays so they can be used as keys inside maps. - * - * @author Costin Leau - */ - private class ArrayHolder { - - private final byte[] array; - private final int hashCode; - - ArrayHolder(byte[] array) { - this.array = array; - this.hashCode = Arrays.hashCode(array); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof ArrayHolder) { - return Arrays.equals(array, ((ArrayHolder) obj).array); - } - - return false; - } - - @Override - public int hashCode() { - return hashCode; - } - } } \ No newline at end of file From 188a90e498b82f363c45f411eb93f84ff7a4f727 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 18:18:54 +0200 Subject: [PATCH 39/68] DATAKV-49 DATAKV-46 + finish up the pubsub improvements and fixed last remaining bugs + added blocking behaviour to RJC pubsub --- .../redis/connection/rjc/RjcSubscription.java | 8 +++++++- .../redis/connection/util/AbstractSubscription.java | 12 ++++++++++-- .../keyvalue/redis/ConnectionFactoryTracker.java | 2 +- .../AbstractConnectionIntegrationTests.java | 3 ++- .../rjc/RjcConnectionIntegrationTests.java | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java index fa0aa5a1d..0cd0d48cf 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java @@ -39,7 +39,13 @@ class RjcSubscription extends AbstractSubscription { @Override protected void doClose() { - subscriber.close(); + try { + subscriber.close(); + } finally { + synchronized (pubSubMonitor) { + pubSubMonitor.notifyAll(); + } + } } @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java index 76dfbfec1..6d20a8bf5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java @@ -56,10 +56,10 @@ public abstract class AbstractSubscription implements Subscription { this.listener = listener; synchronized (this.channels) { - remove(this.channels, channels); + add(this.channels, channels); } synchronized (this.patterns) { - remove(this.patterns, patterns); + add(this.patterns, patterns); } } @@ -168,6 +168,10 @@ public abstract class AbstractSubscription implements Subscription { this.patterns.clear(); } } + else { + // nothing to unsubscribe from + return; + } } else { synchronized (this.patterns) { @@ -194,6 +198,10 @@ public abstract class AbstractSubscription implements Subscription { this.channels.clear(); } } + else { + // nothing to unsubscribe from + return; + } } else { synchronized (this.channels) { diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/ConnectionFactoryTracker.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/ConnectionFactoryTracker.java index 9ef6c5e59..634d3448a 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/ConnectionFactoryTracker.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/ConnectionFactoryTracker.java @@ -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/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index cb8c408ce..116908460 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -218,7 +218,7 @@ public abstract class AbstractConnectionIntegrationTests { System.out.println("Subscribed"); while (flag.get()) { try { - Thread.currentThread().wait(2000); + Thread.currentThread().sleep(2000); } catch (Exception ex) { return; } @@ -239,6 +239,7 @@ public abstract class AbstractConnectionIntegrationTests { } finally { flag.set(false); } + System.out.println(queue); assertEquals(3, queue.size()); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionIntegrationTests.java index 8bbe97356..4fa5b3ed8 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionIntegrationTests.java @@ -33,7 +33,7 @@ public class RjcConnectionIntegrationTests extends AbstractConnectionIntegration factory.setPort(SettingsUtils.getPort()); factory.setHostName(SettingsUtils.getHost()); - factory.setUsePool(true); + factory.setUsePool(false); factory.afterPropertiesSet(); } From 2f7bd89c97d1ecb328bbe175d3834c566b8c918a Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 18:26:00 +0200 Subject: [PATCH 40/68] DATAKV-37 + fix builder methods on DefaultSortParam --- .../connection/DefaultSortParameters.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java index 194957054..62a34bba1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; - /** * Default implementation for {@link SortParameters}. * @@ -126,32 +125,42 @@ public class DefaultSortParameters implements SortParameters { // builder like methods // - public SortParameters order(Order order) { + public DefaultSortParameters order(Order order) { setOrder(order); return this; } - public SortParameters alpha() { + public DefaultSortParameters alpha() { setAlphabetic(true); return this; } - public SortParameters numeric() { + public DefaultSortParameters asc() { + setOrder(Order.ASC); + return this; + } + + public DefaultSortParameters desc() { + setOrder(Order.DESC); + return this; + } + + public DefaultSortParameters numeric() { setAlphabetic(false); return this; } - public SortParameters get(byte[] pattern) { + public DefaultSortParameters get(byte[] pattern) { addGetPattern(pattern); return this; } - public SortParameters by(byte[] pattern) { + public DefaultSortParameters by(byte[] pattern) { setByPattern(pattern); return this; } - public SortParameters limit(long start, long count) { + public DefaultSortParameters limit(long start, long count) { setLimit(new Range(start, count)); return this; } From 5f2875fda642ed79d231dfab4915fe1f4b47bbb0 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 19:40:29 +0200 Subject: [PATCH 41/68] + add move command + extract RedisKeyCommands and RedisConnectionCommands interfaces to map RedisConnection to the Redis docs --- .../DefaultStringRedisConnection.java | 9 ++++ .../redis/connection/RedisCommands.java | 40 ++------------ .../connection/RedisConnectionCommands.java | 28 ++++++++++ .../redis/connection/RedisKeyCommands.java | 54 +++++++++++++++++++ .../connection/StringRedisConnection.java | 2 + .../connection/jedis/JedisConnection.java | 17 ++++++ .../connection/jredis/JredisConnection.java | 10 ++++ .../redis/connection/rjc/RjcConnection.java | 19 ++++++- 8 files changed, 140 insertions(+), 39 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnectionCommands.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisKeyCommands.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index eb70967f3..a3cfd7104 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -308,6 +308,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.persist(key); } + public Boolean move(byte[] key, int dbIndex) { + return delegate.move(key, dbIndex); + } + public String ping() { return delegate.ping(); } @@ -838,6 +842,11 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.persist(serialize(key)); } + @Override + public Boolean move(String key, int dbIndex) { + return delegate.move(serialize(key), dbIndex); + } + @Override public void pSubscribe(MessageListener listener, String... patterns) { delegate.pSubscribe(listener, serializeMulti(patterns)); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java index 61a7d9a80..072439633 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisCommands.java @@ -16,47 +16,13 @@ package org.springframework.data.keyvalue.redis.connection; -import java.util.List; -import java.util.Set; /** * Interface for the commands supported by Redis. * * @author Costin Leau */ -public interface RedisCommands extends RedisTxCommands, RedisStringCommands, RedisListCommands, RedisSetCommands, - RedisZSetCommands, RedisHashCommands, RedisServerCommands, RedisPubSubCommands { - - Boolean exists(byte[] key); - - Long del(byte[]... keys); - - DataType type(byte[] key); - - Set keys(byte[] pattern); - - byte[] randomKey(); - - void rename(byte[] oldName, byte[] newName); - - Boolean renameNX(byte[] oldName, byte[] newName); - - Boolean expire(byte[] key, long seconds); - - Boolean expireAt(byte[] key, long unixTime); - - Boolean persist(byte[] key); - - Long ttl(byte[] key); - - void select(int dbIndex); - - byte[] echo(byte[] message); - - String ping(); - - // sort commands - List sort(byte[] key, SortParameters params); - - Long sort(byte[] key, SortParameters params, byte[] storeKey); +public interface RedisCommands extends RedisKeyCommands, RedisStringCommands, RedisListCommands, RedisSetCommands, + RedisZSetCommands, RedisHashCommands, RedisTxCommands, RedisPubSubCommands, RedisConnectionCommands, + RedisServerCommands { } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnectionCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnectionCommands.java new file mode 100644 index 000000000..bc1709991 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnectionCommands.java @@ -0,0 +1,28 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection; + + + +public interface RedisConnectionCommands { + + public abstract void select(int dbIndex); + + public abstract byte[] echo(byte[] message); + + public abstract String ping(); + +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisKeyCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisKeyCommands.java new file mode 100644 index 000000000..03907d6e7 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisKeyCommands.java @@ -0,0 +1,54 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection; + +import java.util.List; +import java.util.Set; + + + +public interface RedisKeyCommands { + + public abstract Boolean exists(byte[] key); + + public abstract Long del(byte[]... keys); + + public abstract DataType type(byte[] key); + + public abstract Set keys(byte[] pattern); + + public abstract byte[] randomKey(); + + public abstract void rename(byte[] oldName, byte[] newName); + + public abstract Boolean renameNX(byte[] oldName, byte[] newName); + + public abstract Boolean expire(byte[] key, long seconds); + + public abstract Boolean expireAt(byte[] key, long unixTime); + + public abstract Boolean persist(byte[] key); + + public abstract Boolean move(byte[] key, int dbIndex); + + public abstract Long ttl(byte[] key); + + // sort commands + public abstract List sort(byte[] key, SortParameters params); + + public abstract Long sort(byte[] key, SortParameters params, byte[] storeKey); + +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java index 48113abab..28886d595 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/StringRedisConnection.java @@ -60,6 +60,8 @@ public interface StringRedisConnection extends RedisConnection { Boolean persist(String key); + Boolean move(String key, int dbIndex); + Long ttl(String key); String echo(String message); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 7d184e2cd..52899ea4d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -625,6 +625,23 @@ public class JedisConnection implements RedisConnection { } } + @Override + public Boolean move(byte[] key, int dbIndex) { + try { + if (isQueueing()) { + client.move(key, dbIndex); + return null; + } + if (isPipelined()) { + client.move(key, dbIndex); + return null; + } + return (jedis.move(key, dbIndex) == 1); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + @Override public byte[] randomKey() { try { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 3d28fb2a7..d0421cdf6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -321,6 +321,16 @@ public class JredisConnection implements RedisConnection { throw new UnsupportedOperationException(); } + + @Override + public Boolean move(byte[] key, int dbIndex) { + try { + return jredis.move(JredisUtils.decode(key), dbIndex); + } catch (Exception ex) { + throw convertJredisAccessException(ex); + } + } + @Override public byte[] randomKey() { try { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 269456cc3..77d3a576b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -33,8 +33,8 @@ import org.springframework.data.keyvalue.UncategorizedKeyvalueStoreException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.RedisConnection; -import org.springframework.data.keyvalue.redis.connection.SortParameters; import org.springframework.data.keyvalue.redis.connection.RedisSubscribedConnectionException; +import org.springframework.data.keyvalue.redis.connection.SortParameters; import org.springframework.data.keyvalue.redis.connection.Subscription; /** @@ -495,6 +495,21 @@ public class RjcConnection implements RedisConnection { } } + @Override + public Boolean move(byte[] key, int dbIndex) { + String stringKey = RjcUtils.decode(key); + + try { + if (isPipelined()) { + pipeline.move(stringKey, dbIndex); + return null; + } + return session.move(stringKey, dbIndex); + } catch (Exception ex) { + throw convertRjcAccessException(ex); + } + } + @Override public byte[] randomKey() { try { @@ -2037,7 +2052,7 @@ public class RjcConnection implements RedisConnection { subscription = new RjcSubscription(listener, subscriber, pubSubMonitor); subscription.subscribe(channels); - + synchronized (pubSubMonitor) { pubSubMonitor.wait(); } From 29f58db6bee8865af9967ffa0bcc5b64833bd32e Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 19:46:03 +0200 Subject: [PATCH 42/68] + add move operation to RedisTemplate --- .../data/keyvalue/redis/core/RedisOperations.java | 2 ++ .../data/keyvalue/redis/core/RedisTemplate.java | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index dbae2dbba..b88114d7f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -97,6 +97,8 @@ public interface RedisOperations { Boolean persist(K key); + Boolean move(K key, int dbIndex); + Long getExpire(K key); void watch(K keys); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index e91bfc499..6bce83673 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -562,6 +562,18 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @Override + public Boolean move(K key, final int dbIndex) { + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback() { + @Override + public Boolean doInRedis(RedisConnection connection) { + return connection.move(rawKey, dbIndex); + } + }, true); + } + @Override public K randomKey() { byte[] rawKey = execute(new RedisCallback() { From b62abeec505b47b666b3206ad65f908ccf37121e Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Mar 2011 20:33:24 +0200 Subject: [PATCH 43/68] + add select() to RedisOperations --- .../data/keyvalue/redis/core/RedisOperations.java | 2 ++ .../data/keyvalue/redis/core/RedisTemplate.java | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index b88114d7f..a25b6cfda 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -87,6 +87,8 @@ public interface RedisOperations { K randomKey(); + void select(int dbIndex); + void rename(K oldKey, K newKey); Boolean renameIfAbsent(K oldKey, K newKey); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 6bce83673..1b75bf916 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -574,6 +574,18 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + + @Override + public void select(final int dbIndex) { + execute(new RedisCallback() { + @Override + public Object doInRedis(RedisConnection connection) { + connection.select(dbIndex); + return null; + } + }, true); + } + @Override public K randomKey() { byte[] rawKey = execute(new RedisCallback() { From e9d582b15c138c84d556669fe0cc1fdaa2a44a16 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 18 Mar 2011 19:08:43 +0200 Subject: [PATCH 44/68] DATAKV-44 + add missing key operations --- .../redis/core/BoundKeyOperations.java | 25 +++++++++++++++++-- .../redis/core/DefaultBoundKeyOperations.java | 10 ++++++++ .../support/atomic/RedisAtomicInteger.java | 10 ++++++++ .../redis/support/atomic/RedisAtomicLong.java | 10 ++++++++ .../collections/AbstractRedisCollection.java | 10 ++++++++ .../support/collections/DefaultRedisMap.java | 6 +++++ .../support/atomic/RedisAtomicTests.java | 14 +++++++++++ 7 files changed, 83 insertions(+), 2 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java index f2eb1fb4b..3a7ef851b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java @@ -19,12 +19,19 @@ import java.util.Date; import java.util.concurrent.TimeUnit; import org.springframework.data.keyvalue.redis.connection.DataType; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; /** - * Operations over a Redis key. + * 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. In such scenarios, to prevent any data inconsistencies, mutative + * methods that query the store (such as {@link #renameIfAbsent(Object)} or {@link #move(int)}) will throw + * an exception. + * + *

* @author Costin Leau */ public interface BoundKeyOperations { @@ -89,4 +96,18 @@ public interface BoundKeyOperations { * @return true if rename was successful, false otherwise */ Boolean renameIfAbsent(K newKey); + + /** + * Moves the key (if it exists) to the specified database. If the key already exists in the + * destination database, or it does not exist in the source database, it does nothing. + *

+ * As opposed to the raw move command, the database of the underlying connection is switched as well + * to the new database. + * + * @see RedisConnection#select(int) + * @see RedisConnection#move(byte[], int) + * @param dbIndex database index + * @return true if the operation succeed, false otherwise + */ + Boolean move(int dbIndex); } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java index b33c3f234..a290f3da4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java @@ -79,4 +79,14 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { } return result; } + + @Override + public Boolean move(int dbIndex) { + Boolean move = ops.move(key, dbIndex); + + if (Boolean.TRUE.equals(move)) { + ops.select(dbIndex); + } + return move; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index c9a6e5172..e6653d7ad 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -301,6 +301,16 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey return result; } + @Override + public Boolean move(int dbIndex) { + Boolean move = generalOps.move(key, dbIndex); + + if (Boolean.TRUE.equals(move)) { + generalOps.select(dbIndex); + } + return move; + } + @Override public DataType getType() { return DataType.STRING; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 4ef22ed70..18665c3bd 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -304,6 +304,16 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe return result; } + @Override + public Boolean move(int dbIndex) { + Boolean move = generalOps.move(key, dbIndex); + + if (Boolean.TRUE.equals(move)) { + generalOps.select(dbIndex); + } + return move; + } + @Override public DataType getType() { return DataType.STRING; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java index d37640671..3be9392de 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java @@ -154,4 +154,14 @@ public abstract class AbstractRedisCollection extends AbstractCollection i } return result; } + + @Override + public Boolean move(int dbIndex) { + Boolean move = operations.move(key, dbIndex); + + if (Boolean.TRUE.equals(move)) { + operations.select(dbIndex); + } + return move; + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java index 79bef39c7..4397577b7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java @@ -330,6 +330,12 @@ public class DefaultRedisMap implements RedisMap { return hashOps.renameIfAbsent(newKey); } + + @Override + public Boolean move(int dbIndex) { + return hashOps.move(dbIndex); + } + @Override public DataType getType() { return hashOps.getType(); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java index 25c0a93dc..a4818353c 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java @@ -105,4 +105,18 @@ public class RedisAtomicTests { int delta = 5; assertEquals(delta, intCounter.addAndGet(delta)); } + + @Test + public void testIntMove() throws Exception { + intCounter.set(5); + intCounter.move(1); + assertEquals(5, intCounter.get()); + } + + @Test + public void testLongMove() throws Exception { + longCounter.set(5); + longCounter.move(2); + assertEquals(5, longCounter.get()); + } } \ No newline at end of file From e118bbf98aace8ef74fb93704e8d774265c8489d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 18 Mar 2011 19:24:25 +0200 Subject: [PATCH 45/68] DATAKV-44 DATAKV-45 DATAKV-52 + remove move and removeIfAbsent methods, as their semantics are too 'slippery' in some situations --- .../redis/core/BoundKeyOperations.java | 30 +------------------ .../redis/core/DefaultBoundKeyOperations.java | 20 ------------- .../keyvalue/redis/core/RedisOperations.java | 8 ++--- .../keyvalue/redis/core/RedisTemplate.java | 12 -------- .../support/atomic/RedisAtomicInteger.java | 20 ------------- .../redis/support/atomic/RedisAtomicLong.java | 20 ------------- .../collections/AbstractRedisCollection.java | 20 ------------- .../support/collections/DefaultRedisMap.java | 11 ------- .../redis/support/BoundKeyOperationsTest.java | 12 -------- .../support/atomic/RedisAtomicTests.java | 14 --------- 10 files changed, 5 insertions(+), 162 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java index 3a7ef851b..d6791ea0f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundKeyOperations.java @@ -19,7 +19,6 @@ import java.util.Date; import java.util.concurrent.TimeUnit; import org.springframework.data.keyvalue.redis.connection.DataType; -import org.springframework.data.keyvalue.redis.connection.RedisConnection; /** * Operations over a Redis key. @@ -27,10 +26,7 @@ import org.springframework.data.keyvalue.redis.connection.RedisConnection; * 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. In such scenarios, to prevent any data inconsistencies, mutative - * methods that query the store (such as {@link #renameIfAbsent(Object)} or {@link #move(int)}) will throw - * an exception. - * + * all methods will return null. *

* @author Costin Leau */ @@ -86,28 +82,4 @@ public interface BoundKeyOperations { * @param newKey new key */ void rename(K newKey); - - /** - * Renames the key (if the new key does not exist). Note that the underlying key - * changes only if the operation returns true (which does not happen if the connection - * is pipelined or in multi mode). - * - * @param newKey new key - * @return true if rename was successful, false otherwise - */ - Boolean renameIfAbsent(K newKey); - - /** - * Moves the key (if it exists) to the specified database. If the key already exists in the - * destination database, or it does not exist in the source database, it does nothing. - *

- * As opposed to the raw move command, the database of the underlying connection is switched as well - * to the new database. - * - * @see RedisConnection#select(int) - * @see RedisConnection#move(byte[], int) - * @param dbIndex database index - * @return true if the operation succeed, false otherwise - */ - Boolean move(int dbIndex); } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java index a290f3da4..105c6e48b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java @@ -69,24 +69,4 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { ops.rename(key, newKey); key = newKey; } - - @Override - public Boolean renameIfAbsent(K newKey) { - Boolean result = ops.renameIfAbsent(key, newKey); - - if (Boolean.TRUE.equals(result)) { - key = newKey; - } - return result; - } - - @Override - public Boolean move(int dbIndex) { - Boolean move = ops.move(key, dbIndex); - - if (Boolean.TRUE.equals(move)) { - ops.select(dbIndex); - } - return move; - } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index a25b6cfda..c57ed1d1c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -87,8 +87,6 @@ public interface RedisOperations { K randomKey(); - void select(int dbIndex); - void rename(K oldKey, K newKey); Boolean renameIfAbsent(K oldKey, K newKey); @@ -207,13 +205,15 @@ public interface RedisOperations { List sort(SortQuery query); - List sort(SortQuery query, RedisSerializer resultSerializer); - List sort(SortQuery query, BulkMapper bulkMapper); List sort(SortQuery query, BulkMapper bulkMapper, RedisSerializer resultSerializer); Long sort(SortQuery query, K storeKey); + + RedisSerializer getValueSerializer(); + + RedisSerializer getKeySerializer(); } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 1b75bf916..6bce83673 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -574,18 +574,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - - @Override - public void select(final int dbIndex) { - execute(new RedisCallback() { - @Override - public Object doInRedis(RedisConnection connection) { - connection.select(dbIndex); - return null; - } - }, true); - } - @Override public K randomKey() { byte[] rawKey = execute(new RedisCallback() { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index e6653d7ad..bb4b19ba4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -291,26 +291,6 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey key = newKey; } - @Override - public Boolean renameIfAbsent(String newKey) { - Boolean result = generalOps.renameIfAbsent(key, newKey); - - if (Boolean.TRUE.equals(result)) { - key = newKey; - } - return result; - } - - @Override - public Boolean move(int dbIndex) { - Boolean move = generalOps.move(key, dbIndex); - - if (Boolean.TRUE.equals(move)) { - generalOps.select(dbIndex); - } - return move; - } - @Override public DataType getType() { return DataType.STRING; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 18665c3bd..5550b382d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -294,26 +294,6 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe key = newKey; } - @Override - public Boolean renameIfAbsent(String newKey) { - Boolean result = generalOps.renameIfAbsent(key, newKey); - - if (Boolean.TRUE.equals(result)) { - key = newKey; - } - return result; - } - - @Override - public Boolean move(int dbIndex) { - Boolean move = generalOps.move(key, dbIndex); - - if (Boolean.TRUE.equals(move)) { - generalOps.select(dbIndex); - } - return move; - } - @Override public DataType getType() { return DataType.STRING; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java index 3be9392de..cb7c0c5df 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java @@ -144,24 +144,4 @@ public abstract class AbstractRedisCollection extends AbstractCollection i CollectionUtils.rename(key, newKey, operations); key = newKey; } - - @Override - public Boolean renameIfAbsent(final String newKey) { - Boolean result = CollectionUtils.renameIfAbsent(key, newKey, operations); - - if (Boolean.TRUE.equals(result)) { - key = newKey; - } - return result; - } - - @Override - public Boolean move(int dbIndex) { - Boolean move = operations.move(key, dbIndex); - - if (Boolean.TRUE.equals(move)) { - operations.select(dbIndex); - } - return move; - } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java index 4397577b7..291b6b00c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java @@ -325,17 +325,6 @@ public class DefaultRedisMap implements RedisMap { hashOps.rename(newKey); } - @Override - public Boolean renameIfAbsent(String newKey) { - return hashOps.renameIfAbsent(newKey); - } - - - @Override - public Boolean move(int dbIndex) { - return hashOps.move(dbIndex); - } - @Override public DataType getType() { return hashOps.getType(); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java index 8f36bad53..a7626125f 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/BoundKeyOperationsTest.java @@ -72,18 +72,6 @@ public class BoundKeyOperationsTest { keyOps.rename(key); assertEquals(key, keyOps.getKey()); } - - @Test - public void testRenameIfAbsent() throws Exception { - Object key = keyOps.getKey(); - assertNotNull(key); - Object newName = objFactory.instance(); - assertFalse(template.hasKey(newName)); - assertTrue("cannot rename to key " + newName, keyOps.renameIfAbsent(newName)); - assertEquals(newName, keyOps.getKey()); - keyOps.rename(key); - } - @Test public void testExpire() throws Exception { assertEquals(Long.valueOf(-1), keyOps.getExpire()); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java index a4818353c..25c0a93dc 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java @@ -105,18 +105,4 @@ public class RedisAtomicTests { int delta = 5; assertEquals(delta, intCounter.addAndGet(delta)); } - - @Test - public void testIntMove() throws Exception { - intCounter.set(5); - intCounter.move(1); - assertEquals(5, intCounter.get()); - } - - @Test - public void testLongMove() throws Exception { - longCounter.set(5); - longCounter.move(2); - assertEquals(5, longCounter.get()); - } } \ No newline at end of file From 14a1d64b3970a822ad254744857cf54bd0cc70f8 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 30 Mar 2011 20:05:52 +0300 Subject: [PATCH 46/68] + upgrade to latest RJC (0.6.3) + still left with some issues regarding the pubsub support --- spring-data-redis/pom.xml | 4 +- .../redis/connection/rjc/RjcConnection.java | 21 +++---- .../redis/connection/rjc/RjcSubscription.java | 55 +++++++++++-------- .../redis/connection/rjc/RjcUtils.java | 16 ++++++ .../AbstractConnectionIntegrationTests.java | 3 +- 5 files changed, 62 insertions(+), 37 deletions(-) diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index c0fe69d97..0c33106f1 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -16,10 +16,10 @@ "[3.0.0, 4.0.0)" 03122010 1.5.2 - 0.6.2 + 0.6.3 "[1.0.0,2.0.0)" "[1.6, 2.0.0)" - "[0.6.2, 0.6.2]" + "[0.6.3, 0.6.3]" diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 77d3a576b..dfbaf20ec 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -54,12 +54,11 @@ public class RjcConnection implements RedisConnection { private volatile RjcSubscription subscription; private volatile RedisNodeSubscriber subscriber; - private final Object pubSubMonitor = new Object(); - public RjcConnection(org.idevlab.rjc.ds.RedisConnection connection, int dbIndex) { SingleDataSource connectionDataSource = new SingleDataSource(connection); session = new SessionFactoryImpl(connectionDataSource).create(); - subscriber = new RedisNodeSubscriber(connectionDataSource); + subscriber = new RedisNodeSubscriber(); + subscriber.setDataSource(connectionDataSource); client = new Client(connection); this.dbIndex = dbIndex; @@ -82,6 +81,11 @@ public class RjcConnection implements RedisConnection { isClosed = true; try { subscriber.close(); + } catch (Exception ex) { + // ignore + } + + try { session.close(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -2024,12 +2028,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber, pubSubMonitor); + subscription = new RjcSubscription(listener, subscriber, client); subscription.pSubscribe(patterns); - synchronized (pubSubMonitor) { - pubSubMonitor.wait(); - } } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -2050,13 +2051,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber, pubSubMonitor); + subscription = new RjcSubscription(listener, subscriber, client); subscription.subscribe(channels); - synchronized (pubSubMonitor) { - pubSubMonitor.wait(); - } - } catch (Exception ex) { throw convertRjcAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java index 0cd0d48cf..64d8bc959 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java @@ -15,6 +15,7 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; +import org.idevlab.rjc.Client; import org.idevlab.rjc.message.RedisNodeSubscriber; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscription; @@ -27,52 +28,62 @@ import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscript class RjcSubscription extends AbstractSubscription { private final RedisNodeSubscriber subscriber; - private final RjcMessageListener listenerAdapter; - private final Object pubSubMonitor; + private final Client client; + // rjc does not support subscription while listening + // so we have to handle this ourselves through the client + private volatile boolean subscribed = false; - RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber, Object pubSubMonitor) { + RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber, Client client) { super(listener); this.subscriber = subscriber; - this.listenerAdapter = new RjcMessageListener(listener); - this.pubSubMonitor = pubSubMonitor; + subscriber.setMessageListener(new RjcMessageListener(listener)); + subscriber.setPMessageListener(new RjcMessageListener(listener)); + this.client = client; } @Override protected void doClose() { - try { - subscriber.close(); - } finally { - synchronized (pubSubMonitor) { - pubSubMonitor.notifyAll(); - } - } + subscribed = false; + client.unsubscribe(); + client.punsubscribe(); + client.rollbackTimeout(); } @Override protected void doPsubscribe(byte[]... patterns) { - for (String str : RjcUtils.decodeMultiple(patterns)) { - subscriber.psubscribe(str, listenerAdapter); + String[] pats = RjcUtils.decodeMultiple(patterns); + + if (subscribed) { + client.psubscribe(pats); + } + else { + subscriber.setPatterns(RjcUtils.addArray(subscriber.getPatterns(), pats)); + subscribed = true; + subscriber.subscribe(); } } @Override protected void doPUnsubscribe(boolean all, byte[]... patterns) { - for (String str : RjcUtils.decodeMultiple(patterns)) { - subscriber.punsubscribe(str); - } + client.punsubscribe(RjcUtils.decodeMultiple(patterns)); } @Override protected void doSubscribe(byte[]... channels) { - for (String str : RjcUtils.decodeMultiple(channels)) { - subscriber.subscribe(str, listenerAdapter); + String[] chs = RjcUtils.decodeMultiple(channels); + + if (subscribed) { + client.subscribe(chs); + } + else { + subscriber.setPatterns(RjcUtils.addArray(subscriber.getChannels(), chs)); + subscribed = true; + subscriber.subscribe(); } } @Override protected void doUnsubscribe(boolean all, byte[]... channels) { - for (String str : RjcUtils.decodeMultiple(channels)) { - subscriber.unsubscribe(str); - } + client.punsubscribe(RjcUtils.decodeMultiple(channels)); } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java index 817d47589..e373fe469 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcUtils.java @@ -16,6 +16,7 @@ package org.springframework.data.keyvalue.redis.connection.rjc; import java.io.StringReader; +import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -41,6 +42,7 @@ import org.springframework.data.keyvalue.redis.connection.RedisZSetCommands.Tupl import org.springframework.data.keyvalue.redis.connection.SortParameters.Order; import org.springframework.data.keyvalue.redis.connection.SortParameters.Range; import org.springframework.data.keyvalue.redis.connection.util.DecodeUtils; +import org.springframework.util.ObjectUtils; /** @@ -220,4 +222,18 @@ public abstract class RjcUtils { static Double convert(String zscore) { return (zscore == null ? null : Double.valueOf(zscore)); } + + + static String[] addArray(String[] one, String[] two) { + if (ObjectUtils.isEmpty(one)) { + return two; + } + if (ObjectUtils.isEmpty(two)) { + return one; + } + + String[] result = Arrays.copyOf(one, one.length + two.length); + System.arraycopy(two, 0, result, one.length, two.length); + return result; + } } \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index 116908460..875d65b79 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -235,7 +235,8 @@ public abstract class AbstractConnectionIntegrationTests { connection.publish(channel, "two".getBytes()); connection.publish(channel, "I see you".getBytes()); System.out.println("Done publishing..."); - Thread.sleep(3000); + Thread.sleep(5000); + System.out.println("Done waiting ..."); } finally { flag.set(false); } From db0522429aa9c25c0f808b19adf973de054c9237 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 31 Mar 2011 10:13:42 +0300 Subject: [PATCH 47/68] + upgrade to Rjc 0.6.4 (snapshot for now) --- spring-data-redis/pom.xml | 4 +- .../rjc/CloseSuppressingRjcConnection.java | 125 ++++++++++++++++++ .../redis/connection/rjc/RjcConnection.java | 14 +- .../redis/connection/rjc/RjcSubscription.java | 39 +----- 4 files changed, 139 insertions(+), 43 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index 0c33106f1..f3527e3e2 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -16,10 +16,10 @@ "[3.0.0, 4.0.0)" 03122010 1.5.2 - 0.6.3 + 0.6.4-SNAPSHOT "[1.0.0,2.0.0)" "[1.6, 2.0.0)" - "[0.6.3, 0.6.3]" + "[0.6.4, 0.6.4]" diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java new file mode 100644 index 000000000..c902cdf98 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java @@ -0,0 +1,125 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.List; + +import org.idevlab.rjc.ds.RedisConnection; +import org.idevlab.rjc.message.RedisNodeSubscriber; +import org.idevlab.rjc.protocol.Protocol.Command; + +/** + * Basic decorator suppressing close() calls to the underlying connection. + * Used for reusing arbitrary connections with {@link RedisNodeSubscriber} without + * resorting to connection pooling. + * + * @author Costin Leau + */ +class CloseSuppressingRjcConnection implements RedisConnection { + + private final RedisConnection delegate; + + /** + * Constructs a new CloseSuppressingRjcConnection instance. + * + * @param delegate + */ + CloseSuppressingRjcConnection(RedisConnection delegate) { + this.delegate = delegate; + } + + public void close() { + // no-op + } + + public void connect() throws UnknownHostException, IOException { + delegate.connect(); + } + + public List getAll() { + return delegate.getAll(); + } + + public byte[] getBinaryBulkReply() { + return delegate.getBinaryBulkReply(); + } + + public List getBinaryMultiBulkReply() { + return delegate.getBinaryMultiBulkReply(); + } + + public String getBulkReply() { + return delegate.getBulkReply(); + } + + public String getHost() { + return delegate.getHost(); + } + + public Long getIntegerReply() { + return delegate.getIntegerReply(); + } + + public List getMultiBulkReply() { + return delegate.getMultiBulkReply(); + } + + public List getObjectMultiBulkReply() { + return delegate.getObjectMultiBulkReply(); + } + + public Object getOne() { + return delegate.getOne(); + } + + public int getPort() { + return delegate.getPort(); + } + + public String getStatusCodeReply() { + return delegate.getStatusCodeReply(); + } + + public int getTimeout() { + return delegate.getTimeout(); + } + + public boolean isConnected() { + return delegate.isConnected(); + } + + public void rollbackTimeout() { + delegate.rollbackTimeout(); + } + + public void sendCommand(Command arg0, byte[]... arg1) { + delegate.sendCommand(arg0, arg1); + } + + public void sendCommand(Command arg0, String... arg1) { + delegate.sendCommand(arg0, arg1); + } + + public void sendCommand(Command arg0) { + delegate.sendCommand(arg0); + } + + public void setTimeoutInfinite() { + delegate.setTimeoutInfinite(); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index dfbaf20ec..b2683db75 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -58,7 +58,7 @@ public class RjcConnection implements RedisConnection { SingleDataSource connectionDataSource = new SingleDataSource(connection); session = new SessionFactoryImpl(connectionDataSource).create(); subscriber = new RedisNodeSubscriber(); - subscriber.setDataSource(connectionDataSource); + subscriber.setDataSource(new SingleDataSource(new CloseSuppressingRjcConnection(connection))); client = new Client(connection); this.dbIndex = dbIndex; @@ -79,13 +79,9 @@ public class RjcConnection implements RedisConnection { @Override public void close() throws DataAccessException { isClosed = true; - try { - subscriber.close(); - } catch (Exception ex) { - // ignore - } try { + subscriber.close(); session.close(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -2028,8 +2024,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber, client); + subscription = new RjcSubscription(listener, subscriber); subscription.pSubscribe(patterns); + subscriber.runSubscription(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -2051,8 +2048,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber, client); + subscription = new RjcSubscription(listener, subscriber); subscription.subscribe(channels); + subscriber.runSubscription(); } catch (Exception ex) { throw convertRjcAccessException(ex); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java index 64d8bc959..78c5f2277 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java @@ -15,7 +15,6 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; -import org.idevlab.rjc.Client; import org.idevlab.rjc.message.RedisNodeSubscriber; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscription; @@ -28,62 +27,36 @@ import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscript class RjcSubscription extends AbstractSubscription { private final RedisNodeSubscriber subscriber; - private final Client client; - // rjc does not support subscription while listening - // so we have to handle this ourselves through the client - private volatile boolean subscribed = false; - RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber, Client client) { + RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber) { super(listener); this.subscriber = subscriber; subscriber.setMessageListener(new RjcMessageListener(listener)); subscriber.setPMessageListener(new RjcMessageListener(listener)); - this.client = client; } @Override protected void doClose() { - subscribed = false; - client.unsubscribe(); - client.punsubscribe(); - client.rollbackTimeout(); + subscriber.close(); } @Override protected void doPsubscribe(byte[]... patterns) { - String[] pats = RjcUtils.decodeMultiple(patterns); - - if (subscribed) { - client.psubscribe(pats); - } - else { - subscriber.setPatterns(RjcUtils.addArray(subscriber.getPatterns(), pats)); - subscribed = true; - subscriber.subscribe(); - } + subscriber.psubscribe(RjcUtils.decodeMultiple(patterns)); } @Override protected void doPUnsubscribe(boolean all, byte[]... patterns) { - client.punsubscribe(RjcUtils.decodeMultiple(patterns)); + subscriber.punsubscribe(RjcUtils.decodeMultiple(patterns)); } @Override protected void doSubscribe(byte[]... channels) { - String[] chs = RjcUtils.decodeMultiple(channels); - - if (subscribed) { - client.subscribe(chs); - } - else { - subscriber.setPatterns(RjcUtils.addArray(subscriber.getChannels(), chs)); - subscribed = true; - subscriber.subscribe(); - } + subscriber.subscribe(RjcUtils.decodeMultiple(channels)); } @Override protected void doUnsubscribe(boolean all, byte[]... channels) { - client.punsubscribe(RjcUtils.decodeMultiple(channels)); + subscriber.punsubscribe(RjcUtils.decodeMultiple(channels)); } } \ No newline at end of file From 0284e8e97fa56dd9498d12f88c46115b296923f0 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 5 Apr 2011 20:12:04 +0300 Subject: [PATCH 48/68] fix minor typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 408c26a59..66b67f0b0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ For those in a hurry: org.springframework.data spring-data-redis - 1.0.0-BUILD-SNAPSHOT + 1.0.0.BUILD-SNAPSHOT @@ -65,7 +65,7 @@ For those in a hurry: org.springframework.data spring-data-riak - 1.0.0-BUILD-SNAPSHOT + 1.0.0.BUILD-SNAPSHOT From fe7057efb1ed25d2f13498f1a282c0054cc0ad09 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 5 Apr 2011 20:13:59 +0300 Subject: [PATCH 49/68] + update readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 66b67f0b0..58c290258 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ Spring Data - Key Value The primary goal of the [Spring Data](http://www.springsource.org/spring-data) project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services. As the name implies, the **Key Value** modules provides integration with key value stores such as [Redis](http://code.google.com/p/redis/) and [Riak](http://www.basho.com/Riak.html). +Examples +-------- +For examples on using the Spring Data Key Value, see the dedicated project, also available on [GitHub](https://github.com/SpringSource/spring-data-keyvalue-examples) + Getting Help ------------ From 6e76662f90fa22625c72c4f642be90d342e2a2eb Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 5 Apr 2011 20:29:46 +0300 Subject: [PATCH 50/68] + update changelog for upcoming M3 --- src/main/resources/changelog.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index 94d51f782..f0d4f2066 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -2,6 +2,31 @@ SPRING DATA KEY/VALUE INTEGRATION CHANGELOG =========================================== http://www.springsource.org/spring-data +Changes in version 1.0.0.M3 (2011-04-06) +---------------------------------------- + +Redis +----- + +General +* Added support for RJC (new Redis client) +* Added dedicated SORT and SORT/GET support +* Introduced HashMapper feature for mapping objects to and from maps +* Improved exception hierarchy to be more consistent with Spring DAO + +Package o.s.d.k.redis.connection +* Added support for indexes to RedisConnectionFactories +* Added new key operations to KeyOperations (formerly KeyBound) +* Improved handling of Jedis exceptions + +Package o.s.d.k.redis.core +* Serializers are exposed to RedisCallback +* Added missing operations (move, select) to RedisTemplate +* Fixed the signature of various method + +Package o.s.d.k.redis.support.atomic +* Fixed incorrect serialization leading to error for RedisAtomicInteger & RedisAtomicLong + Changes in version 1.0.0.M2 (2011-02-10) ---------------------------------------- From 9d691957996c6120b86c264e03c078b032aa2f1c Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 5 Apr 2011 20:33:18 +0300 Subject: [PATCH 51/68] + remove pipeline support for now since none of the drivers support it properly --- .../DefaultStringRedisConnection.java | 2 +- .../redis/connection/RedisConnection.java | 2 +- .../connection/jedis/JedisConnection.java | 4 +- .../connection/jredis/JredisConnection.java | 2 +- .../redis/connection/rjc/RjcConnection.java | 4 +- .../keyvalue/redis/core/RedisOperations.java | 18 ++--- .../keyvalue/redis/core/RedisTemplate.java | 74 +++++++++---------- 7 files changed, 52 insertions(+), 54 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index a3cfd7104..04484b29f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -1123,7 +1123,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } @Override - public List closePipeline() { + public List closePipeline() { return delegate.closePipeline(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnection.java index d61fe1287..6f9f0a2fd 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnection.java @@ -95,5 +95,5 @@ public interface RedisConnection extends RedisCommands { * * @return the result of the executed commands. */ - List closePipeline(); + List closePipeline(); } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 52899ea4d..410f5fef8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -187,11 +187,11 @@ public class JedisConnection implements RedisConnection { @SuppressWarnings("unchecked") @Override - public List closePipeline() { + public List closePipeline() { if (pipeline != null) { List execute = pipeline.execute(); if (execute != null && !execute.isEmpty()) { - return (List) execute; + return execute; } } return Collections.emptyList(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index d0421cdf6..ada3441e1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -115,7 +115,7 @@ public class JredisConnection implements RedisConnection { } @Override - public List closePipeline() { + public List closePipeline() { return Collections.emptyList(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index b2683db75..50d5f78f0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -118,11 +118,11 @@ public class RjcConnection implements RedisConnection { @SuppressWarnings("unchecked") @Override - public List closePipeline() { + public List closePipeline() { if (pipeline != null) { List execute = client.getAll(); if (execute != null && !execute.isEmpty()) { - return (List) execute; + return execute; } } return Collections.emptyList(); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index c57ed1d1c..57e51fd1e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -64,15 +64,15 @@ 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. - * - * @param list element return type - * @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. Note that the callback cannot + // * return a non-null value as it gets overwritten by the pipeline. + // * + // * @param list element return type + // * @param action callback object to execute + // * @return list of objects returned by the pipeline + // */ + // List executePipelined(RedisCallback action); Boolean hasKey(K key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index 6bce83673..d3565d996 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -25,7 +25,6 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.springframework.dao.DataAccessException; -import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.keyvalue.redis.connection.DataType; import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; @@ -205,43 +204,42 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } } - @Override - @SuppressWarnings("unchecked") - public List executePipelined(final RedisCallback action) { - return executePipelined(action, valueSerializer); - } - - /** - * 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 - * @return list of objects returned by the pipeline - */ - public List executePipelined(final RedisCallback action, final RedisSerializer resultSerializer) { - return execute(new RedisCallback>() { - public List doInRedis(RedisConnection connection) throws DataAccessException { - connection.openPipeline(); - boolean pipelinedClosed = false; - try { - Object result = action.doInRedis(connection); - if (result != null) { - throw new InvalidDataAccessApiUsageException( - "Callback cannot returned a non-null value as it gets overwritten by the pipeline"); - } - List pipeline = connection.closePipeline(); - pipelinedClosed = true; - return SerializationUtils.deserialize(pipeline, resultSerializer); - - } finally { - if (!pipelinedClosed) { - connection.closePipeline(); - } - } - } - }); - } + // @SuppressWarnings("unchecked") + // public List executePipelined(final RedisCallback action) { + // return executePipelined(action, valueSerializer); + // } + // + // /** + // * 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 + // * @return list of objects returned by the pipeline + // */ + // public List executePipelined(final RedisCallback action, final RedisSerializer resultSerializer) { + // return execute(new RedisCallback>() { + // public List doInRedis(RedisConnection connection) throws DataAccessException { + // connection.openPipeline(); + // boolean pipelinedClosed = false; + // try { + // Object result = action.doInRedis(connection); + // if (result != null) { + // throw new InvalidDataAccessApiUsageException( + // "Callback cannot returned a non-null value as it gets overwritten by the pipeline"); + // } + // List closePipeline = connection.closePipeline(); + // pipelinedClosed = true; + // //return SerializationUtils.deserialize(pipeline, resultSerializer); + // + // } finally { + // if (!pipelinedClosed) { + // connection.closePipeline(); + // } + // } + // } + // }); + // } protected RedisConnection createRedisConnectionProxy(RedisConnection pm) { Class[] ifcs = ClassUtils.getAllInterfacesForClass(pm.getClass(), getClass().getClassLoader()); From a15ddf0fad4c4dddc45526cf1d2de66abe2be570 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 5 Apr 2011 20:44:13 +0300 Subject: [PATCH 52/68] DATAKV-56 DATAKV-59 --- spring-data-redis/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index f3527e3e2..d67f0874d 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -93,10 +93,12 @@ org.codehaus.jackson jackson-core-asl + true org.codehaus.jackson jackson-mapper-asl + true @@ -122,11 +124,13 @@ commons-beanutils commons-beanutils-core 1.8.3 + true junit junit + test @@ -142,12 +146,14 @@ jredis-anthonylauzon ${jredis.ver} compile + true org.idevlab rjc ${rjc.ver} compile + true From f98805a6ce94daac32f68af5501eaea66ad2c670 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 5 Apr 2011 20:44:24 +0300 Subject: [PATCH 53/68] + add RJC to the docs --- src/docbkx/reference/redis.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/docbkx/reference/redis.xml b/src/docbkx/reference/redis.xml index 4e0e7858c..57f27b13a 100644 --- a/src/docbkx/reference/redis.xml +++ b/src/docbkx/reference/redis.xml @@ -19,9 +19,9 @@
Redis Requirements SDKV requires Redis 2.0 or above (Redis 2.2 is recommended) and Java SE 6.0 or above. - In terms of language bindings (or connectors), SDKV integrates with Jedis and - JRedis, two popular open source Java libraries for Redis. If you are aware of - any other connector that we should be integrating is, please send us feedback. + In terms of language bindings (or connectors), SDKV integrates with Jedis, + JRedis and RJC, three popular open source Java libraries for Redis. + If you are aware of any other connector that we should be integrating is, please send us feedback.
From 6cf1a58606344d52eedfafe280ab5f9323e98e7e Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 5 Apr 2011 21:51:13 +0300 Subject: [PATCH 54/68] Revert "+ upgrade to Rjc 0.6.4 (snapshot for now)" This reverts commit db0522429aa9c25c0f808b19adf973de054c9237. + Downgrading RJC dependency to 0.6.3 since 0.6.4 is not yet released --- spring-data-keyvalue-parent/pom.xml | 4 +- spring-data-redis/pom.xml | 4 +- .../rjc/CloseSuppressingRjcConnection.java | 125 ------------------ .../redis/connection/rjc/RjcConnection.java | 14 +- .../redis/connection/rjc/RjcSubscription.java | 39 +++++- 5 files changed, 45 insertions(+), 141 deletions(-) delete mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java diff --git a/spring-data-keyvalue-parent/pom.xml b/spring-data-keyvalue-parent/pom.xml index 45e6f69bd..b0a7cece1 100644 --- a/spring-data-keyvalue-parent/pom.xml +++ b/spring-data-keyvalue-parent/pom.xml @@ -314,8 +314,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.5 - 1.5 + 1.6 + 1.6 -Xlint:all true false diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index d67f0874d..2c95966af 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -16,10 +16,10 @@ "[3.0.0, 4.0.0)" 03122010 1.5.2 - 0.6.4-SNAPSHOT + 0.6.3 "[1.0.0,2.0.0)" "[1.6, 2.0.0)" - "[0.6.4, 0.6.4]" + "[0.6.3, 0.6.3]" diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java deleted file mode 100644 index c902cdf98..000000000 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.keyvalue.redis.connection.rjc; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.List; - -import org.idevlab.rjc.ds.RedisConnection; -import org.idevlab.rjc.message.RedisNodeSubscriber; -import org.idevlab.rjc.protocol.Protocol.Command; - -/** - * Basic decorator suppressing close() calls to the underlying connection. - * Used for reusing arbitrary connections with {@link RedisNodeSubscriber} without - * resorting to connection pooling. - * - * @author Costin Leau - */ -class CloseSuppressingRjcConnection implements RedisConnection { - - private final RedisConnection delegate; - - /** - * Constructs a new CloseSuppressingRjcConnection instance. - * - * @param delegate - */ - CloseSuppressingRjcConnection(RedisConnection delegate) { - this.delegate = delegate; - } - - public void close() { - // no-op - } - - public void connect() throws UnknownHostException, IOException { - delegate.connect(); - } - - public List getAll() { - return delegate.getAll(); - } - - public byte[] getBinaryBulkReply() { - return delegate.getBinaryBulkReply(); - } - - public List getBinaryMultiBulkReply() { - return delegate.getBinaryMultiBulkReply(); - } - - public String getBulkReply() { - return delegate.getBulkReply(); - } - - public String getHost() { - return delegate.getHost(); - } - - public Long getIntegerReply() { - return delegate.getIntegerReply(); - } - - public List getMultiBulkReply() { - return delegate.getMultiBulkReply(); - } - - public List getObjectMultiBulkReply() { - return delegate.getObjectMultiBulkReply(); - } - - public Object getOne() { - return delegate.getOne(); - } - - public int getPort() { - return delegate.getPort(); - } - - public String getStatusCodeReply() { - return delegate.getStatusCodeReply(); - } - - public int getTimeout() { - return delegate.getTimeout(); - } - - public boolean isConnected() { - return delegate.isConnected(); - } - - public void rollbackTimeout() { - delegate.rollbackTimeout(); - } - - public void sendCommand(Command arg0, byte[]... arg1) { - delegate.sendCommand(arg0, arg1); - } - - public void sendCommand(Command arg0, String... arg1) { - delegate.sendCommand(arg0, arg1); - } - - public void sendCommand(Command arg0) { - delegate.sendCommand(arg0); - } - - public void setTimeoutInfinite() { - delegate.setTimeoutInfinite(); - } -} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 50d5f78f0..a52af61d5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -58,7 +58,7 @@ public class RjcConnection implements RedisConnection { SingleDataSource connectionDataSource = new SingleDataSource(connection); session = new SessionFactoryImpl(connectionDataSource).create(); subscriber = new RedisNodeSubscriber(); - subscriber.setDataSource(new SingleDataSource(new CloseSuppressingRjcConnection(connection))); + subscriber.setDataSource(connectionDataSource); client = new Client(connection); this.dbIndex = dbIndex; @@ -79,9 +79,13 @@ public class RjcConnection implements RedisConnection { @Override public void close() throws DataAccessException { isClosed = true; - try { subscriber.close(); + } catch (Exception ex) { + // ignore + } + + try { session.close(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -2024,9 +2028,8 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber); + subscription = new RjcSubscription(listener, subscriber, client); subscription.pSubscribe(patterns); - subscriber.runSubscription(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -2048,9 +2051,8 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber); + subscription = new RjcSubscription(listener, subscriber, client); subscription.subscribe(channels); - subscriber.runSubscription(); } catch (Exception ex) { throw convertRjcAccessException(ex); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java index 78c5f2277..64d8bc959 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java @@ -15,6 +15,7 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; +import org.idevlab.rjc.Client; import org.idevlab.rjc.message.RedisNodeSubscriber; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscription; @@ -27,36 +28,62 @@ import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscript class RjcSubscription extends AbstractSubscription { private final RedisNodeSubscriber subscriber; + private final Client client; + // rjc does not support subscription while listening + // so we have to handle this ourselves through the client + private volatile boolean subscribed = false; - RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber) { + RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber, Client client) { super(listener); this.subscriber = subscriber; subscriber.setMessageListener(new RjcMessageListener(listener)); subscriber.setPMessageListener(new RjcMessageListener(listener)); + this.client = client; } @Override protected void doClose() { - subscriber.close(); + subscribed = false; + client.unsubscribe(); + client.punsubscribe(); + client.rollbackTimeout(); } @Override protected void doPsubscribe(byte[]... patterns) { - subscriber.psubscribe(RjcUtils.decodeMultiple(patterns)); + String[] pats = RjcUtils.decodeMultiple(patterns); + + if (subscribed) { + client.psubscribe(pats); + } + else { + subscriber.setPatterns(RjcUtils.addArray(subscriber.getPatterns(), pats)); + subscribed = true; + subscriber.subscribe(); + } } @Override protected void doPUnsubscribe(boolean all, byte[]... patterns) { - subscriber.punsubscribe(RjcUtils.decodeMultiple(patterns)); + client.punsubscribe(RjcUtils.decodeMultiple(patterns)); } @Override protected void doSubscribe(byte[]... channels) { - subscriber.subscribe(RjcUtils.decodeMultiple(channels)); + String[] chs = RjcUtils.decodeMultiple(channels); + + if (subscribed) { + client.subscribe(chs); + } + else { + subscriber.setPatterns(RjcUtils.addArray(subscriber.getChannels(), chs)); + subscribed = true; + subscriber.subscribe(); + } } @Override protected void doUnsubscribe(boolean all, byte[]... channels) { - subscriber.punsubscribe(RjcUtils.decodeMultiple(channels)); + client.punsubscribe(RjcUtils.decodeMultiple(channels)); } } \ No newline at end of file From da64919b6878ed285dc0609b8b22898472b92a2f Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 6 Apr 2011 09:16:24 +0300 Subject: [PATCH 55/68] Revert "Revert "+ upgrade to Rjc 0.6.4 (snapshot for now)"" This reverts commit 6cf1a58606344d52eedfafe280ab5f9323e98e7e. Upgrade back to RJC 0.6.4 now that it has been released (just in time for M3) --- spring-data-keyvalue-parent/pom.xml | 4 +- spring-data-redis/pom.xml | 4 +- .../rjc/CloseSuppressingRjcConnection.java | 117 ++++++++++++++++++ .../redis/connection/rjc/RjcConnection.java | 14 +-- .../redis/connection/rjc/RjcSubscription.java | 39 +----- 5 files changed, 133 insertions(+), 45 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java diff --git a/spring-data-keyvalue-parent/pom.xml b/spring-data-keyvalue-parent/pom.xml index b0a7cece1..45e6f69bd 100644 --- a/spring-data-keyvalue-parent/pom.xml +++ b/spring-data-keyvalue-parent/pom.xml @@ -314,8 +314,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.5 + 1.5 -Xlint:all true false diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index 2c95966af..df79d0267 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -16,10 +16,10 @@ "[3.0.0, 4.0.0)" 03122010 1.5.2 - 0.6.3 + 0.6.4 "[1.0.0,2.0.0)" "[1.6, 2.0.0)" - "[0.6.3, 0.6.3]" + "[0.6.4, 0.6.4]" diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java new file mode 100644 index 000000000..f5adba611 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/CloseSuppressingRjcConnection.java @@ -0,0 +1,117 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.connection.rjc; + +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.List; + +import org.idevlab.rjc.ds.RedisConnection; +import org.idevlab.rjc.message.RedisNodeSubscriber; +import org.idevlab.rjc.protocol.Protocol.Command; + +/** + * Basic decorator suppressing close() calls to the underlying connection. + * Used for reusing arbitrary connections with {@link RedisNodeSubscriber} without + * resorting to connection pooling. + * + * @author Costin Leau + */ +class CloseSuppressingRjcConnection implements RedisConnection { + + private final RedisConnection delegate; + + /** + * Constructs a new CloseSuppressingRjcConnection instance. + * + * @param delegate + */ + CloseSuppressingRjcConnection(RedisConnection delegate) { + this.delegate = delegate; + } + + public void close() { + // no-op + } + + public void connect() throws UnknownHostException, IOException { + delegate.connect(); + } + + public List getAll() { + return delegate.getAll(); + } + + public String getBulkReply() { + return delegate.getBulkReply(); + } + + public String getHost() { + return delegate.getHost(); + } + + public Long getIntegerReply() { + return delegate.getIntegerReply(); + } + + public List getMultiBulkReply() { + return delegate.getMultiBulkReply(); + } + + public List getObjectMultiBulkReply() { + return delegate.getObjectMultiBulkReply(); + } + + public Object getOne() { + return delegate.getOne(); + } + + public int getPort() { + return delegate.getPort(); + } + + public String getStatusCodeReply() { + return delegate.getStatusCodeReply(); + } + + public int getTimeout() { + return delegate.getTimeout(); + } + + public boolean isConnected() { + return delegate.isConnected(); + } + + public void rollbackTimeout() { + delegate.rollbackTimeout(); + } + + public void sendCommand(Command arg0, byte[]... arg1) { + delegate.sendCommand(arg0, arg1); + } + + public void sendCommand(Command arg0, String... arg1) { + delegate.sendCommand(arg0, arg1); + } + + public void sendCommand(Command arg0) { + delegate.sendCommand(arg0); + } + + public void setTimeoutInfinite() { + delegate.setTimeoutInfinite(); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index a52af61d5..50d5f78f0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -58,7 +58,7 @@ public class RjcConnection implements RedisConnection { SingleDataSource connectionDataSource = new SingleDataSource(connection); session = new SessionFactoryImpl(connectionDataSource).create(); subscriber = new RedisNodeSubscriber(); - subscriber.setDataSource(connectionDataSource); + subscriber.setDataSource(new SingleDataSource(new CloseSuppressingRjcConnection(connection))); client = new Client(connection); this.dbIndex = dbIndex; @@ -79,13 +79,9 @@ public class RjcConnection implements RedisConnection { @Override public void close() throws DataAccessException { isClosed = true; - try { - subscriber.close(); - } catch (Exception ex) { - // ignore - } try { + subscriber.close(); session.close(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -2028,8 +2024,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber, client); + subscription = new RjcSubscription(listener, subscriber); subscription.pSubscribe(patterns); + subscriber.runSubscription(); } catch (Exception ex) { throw convertRjcAccessException(ex); @@ -2051,8 +2048,9 @@ public class RjcConnection implements RedisConnection { throw new UnsupportedOperationException(); } - subscription = new RjcSubscription(listener, subscriber, client); + subscription = new RjcSubscription(listener, subscriber); subscription.subscribe(channels); + subscriber.runSubscription(); } catch (Exception ex) { throw convertRjcAccessException(ex); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java index 64d8bc959..78c5f2277 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcSubscription.java @@ -15,7 +15,6 @@ */ package org.springframework.data.keyvalue.redis.connection.rjc; -import org.idevlab.rjc.Client; import org.idevlab.rjc.message.RedisNodeSubscriber; import org.springframework.data.keyvalue.redis.connection.MessageListener; import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscription; @@ -28,62 +27,36 @@ import org.springframework.data.keyvalue.redis.connection.util.AbstractSubscript class RjcSubscription extends AbstractSubscription { private final RedisNodeSubscriber subscriber; - private final Client client; - // rjc does not support subscription while listening - // so we have to handle this ourselves through the client - private volatile boolean subscribed = false; - RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber, Client client) { + RjcSubscription(MessageListener listener, RedisNodeSubscriber subscriber) { super(listener); this.subscriber = subscriber; subscriber.setMessageListener(new RjcMessageListener(listener)); subscriber.setPMessageListener(new RjcMessageListener(listener)); - this.client = client; } @Override protected void doClose() { - subscribed = false; - client.unsubscribe(); - client.punsubscribe(); - client.rollbackTimeout(); + subscriber.close(); } @Override protected void doPsubscribe(byte[]... patterns) { - String[] pats = RjcUtils.decodeMultiple(patterns); - - if (subscribed) { - client.psubscribe(pats); - } - else { - subscriber.setPatterns(RjcUtils.addArray(subscriber.getPatterns(), pats)); - subscribed = true; - subscriber.subscribe(); - } + subscriber.psubscribe(RjcUtils.decodeMultiple(patterns)); } @Override protected void doPUnsubscribe(boolean all, byte[]... patterns) { - client.punsubscribe(RjcUtils.decodeMultiple(patterns)); + subscriber.punsubscribe(RjcUtils.decodeMultiple(patterns)); } @Override protected void doSubscribe(byte[]... channels) { - String[] chs = RjcUtils.decodeMultiple(channels); - - if (subscribed) { - client.subscribe(chs); - } - else { - subscriber.setPatterns(RjcUtils.addArray(subscriber.getChannels(), chs)); - subscribed = true; - subscriber.subscribe(); - } + subscriber.subscribe(RjcUtils.decodeMultiple(channels)); } @Override protected void doUnsubscribe(boolean all, byte[]... channels) { - client.punsubscribe(RjcUtils.decodeMultiple(channels)); + subscriber.punsubscribe(RjcUtils.decodeMultiple(channels)); } } \ No newline at end of file From 63f3f27cae6bee974e76c7d6f2c32569ff7024ed Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 6 Apr 2011 16:49:57 +0300 Subject: [PATCH 56/68] + prepare 1.0.0.M3 release + add missing javadocs + update some copyrights/dates --- pom.xml | 8 ++++---- spring-data-keyvalue-core/pom.xml | 2 +- spring-data-keyvalue-parent/pom.xml | 2 +- spring-data-redis/pom.xml | 4 ++-- .../redis/connection/RedisConnectionCommands.java | 6 +++++- .../data/keyvalue/redis/connection/RedisKeyCommands.java | 6 +++++- .../data/keyvalue/redis/core/query/package-info.java | 5 +++++ .../data/keyvalue/redis/hash/package-info.java | 7 +++++++ spring-data-riak/pom.xml | 2 +- src/docbkx/resources/xsl/fopdf.xsl | 4 ++-- 10 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/package-info.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/package-info.java diff --git a/pom.xml b/pom.xml index 3026ac2d1..45c0bb734 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-keyvalue-dist Spring Data Key-Value Distribution - 1.0.0.BUILD-SNAPSHOT + 1.0.0.M3 pom @@ -52,9 +52,9 @@ jbrisbin Jon Brisbin - jon at jbrisbin.com - NPC International - http://www.npcinternational.com + jbrisbin at vmware.com + SpringSource + http://www.SpringSource.com Developer diff --git a/spring-data-keyvalue-core/pom.xml b/spring-data-keyvalue-core/pom.xml index 7de8c18a6..ff77e89c3 100644 --- a/spring-data-keyvalue-core/pom.xml +++ b/spring-data-keyvalue-core/pom.xml @@ -4,7 +4,7 @@ org.springframework.data spring-data-keyvalue-parent - 1.0.0.BUILD-SNAPSHOT + 1.0.0.M3 ../spring-data-keyvalue-parent/pom.xml spring-data-keyvalue-core diff --git a/spring-data-keyvalue-parent/pom.xml b/spring-data-keyvalue-parent/pom.xml index 45e6f69bd..d0ce8cd03 100644 --- a/spring-data-keyvalue-parent/pom.xml +++ b/spring-data-keyvalue-parent/pom.xml @@ -7,7 +7,7 @@ spring-data-keyvalue-parent Spring Data Key-Value Parent http://www.springsource.org/spring-data/data-keyvalue - 1.0.0.BUILD-SNAPSHOT + 1.0.0.M3 pom diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index df79d0267..1150dd984 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-keyvalue-parent ../spring-data-keyvalue-parent/pom.xml - 1.0.0.BUILD-SNAPSHOT + 1.0.0.M3 spring-data-redis jar @@ -41,7 +41,7 @@ org.springframework.data spring-data-keyvalue-core - 1.0.0.BUILD-SNAPSHOT + 1.0.0.M3 diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnectionCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnectionCommands.java index bc1709991..f3a3ac104 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnectionCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisConnectionCommands.java @@ -16,7 +16,11 @@ package org.springframework.data.keyvalue.redis.connection; - +/** + * Connection-specific commands supported by Redis. + * + * @author Costin Leau + */ public interface RedisConnectionCommands { public abstract void select(int dbIndex); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisKeyCommands.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisKeyCommands.java index 03907d6e7..41d047c35 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisKeyCommands.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/RedisKeyCommands.java @@ -19,7 +19,11 @@ import java.util.List; import java.util.Set; - +/** + * Key-specific commands supported by Redis. + * + * @author Costin Leau + */ public interface RedisKeyCommands { public abstract Boolean exists(byte[] key); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/package-info.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/package-info.java new file mode 100644 index 000000000..3a0c87b28 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/package-info.java @@ -0,0 +1,5 @@ +/** + * Query package for Redis template. + */ +package org.springframework.data.keyvalue.redis.core.query; + diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/package-info.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/package-info.java new file mode 100644 index 000000000..3209d57ca --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/package-info.java @@ -0,0 +1,7 @@ +/** + * Dedicated support package for Redis hashes. + * + * Provides mapping of objects to hashes/maps (and vice versa). + */ +package org.springframework.data.keyvalue.redis.hash; + diff --git a/spring-data-riak/pom.xml b/spring-data-riak/pom.xml index 76ed4999e..5f6130d46 100644 --- a/spring-data-riak/pom.xml +++ b/spring-data-riak/pom.xml @@ -6,7 +6,7 @@ org.springframework.data spring-data-keyvalue-parent ../spring-data-keyvalue-parent/pom.xml - 1.0.0.BUILD-SNAPSHOT + 1.0.0.M3 spring-data-riak jar diff --git a/src/docbkx/resources/xsl/fopdf.xsl b/src/docbkx/resources/xsl/fopdf.xsl index 62539d30d..4b3692f19 100644 --- a/src/docbkx/resources/xsl/fopdf.xsl +++ b/src/docbkx/resources/xsl/fopdf.xsl @@ -62,7 +62,7 @@ - Copyright © 2006-2009 + Copyright © 2010-2011 @@ -106,7 +106,7 @@ - Spring Data Redis () + Spring Data Key Value () From 87d7401ae8fc908dd45369ec796a2b4a61422e3d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 6 Apr 2011 17:04:16 +0300 Subject: [PATCH 57/68] + update changelog --- src/main/resources/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index f0d4f2066..d2d5c4626 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -13,6 +13,7 @@ General * Added dedicated SORT and SORT/GET support * Introduced HashMapper feature for mapping objects to and from maps * Improved exception hierarchy to be more consistent with Spring DAO +* Made several Redis dependencies optional to eliminate unnecessary jars from the classpath Package o.s.d.k.redis.connection * Added support for indexes to RedisConnectionFactories From 98b66ec6ae82dc717c616c98bf176fd68607603a Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 7 Apr 2011 08:47:37 +0300 Subject: [PATCH 58/68] + bump up version --- pom.xml | 2 +- spring-data-keyvalue-core/pom.xml | 2 +- spring-data-keyvalue-parent/pom.xml | 2 +- spring-data-redis/pom.xml | 4 ++-- spring-data-riak/pom.xml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 45c0bb734..08d81a185 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-keyvalue-dist Spring Data Key-Value Distribution - 1.0.0.M3 + 1.0.0.BUILD-SNAPSHOT pom diff --git a/spring-data-keyvalue-core/pom.xml b/spring-data-keyvalue-core/pom.xml index ff77e89c3..7de8c18a6 100644 --- a/spring-data-keyvalue-core/pom.xml +++ b/spring-data-keyvalue-core/pom.xml @@ -4,7 +4,7 @@ org.springframework.data spring-data-keyvalue-parent - 1.0.0.M3 + 1.0.0.BUILD-SNAPSHOT ../spring-data-keyvalue-parent/pom.xml spring-data-keyvalue-core diff --git a/spring-data-keyvalue-parent/pom.xml b/spring-data-keyvalue-parent/pom.xml index d0ce8cd03..45e6f69bd 100644 --- a/spring-data-keyvalue-parent/pom.xml +++ b/spring-data-keyvalue-parent/pom.xml @@ -7,7 +7,7 @@ spring-data-keyvalue-parent Spring Data Key-Value Parent http://www.springsource.org/spring-data/data-keyvalue - 1.0.0.M3 + 1.0.0.BUILD-SNAPSHOT pom diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index 1150dd984..df79d0267 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-keyvalue-parent ../spring-data-keyvalue-parent/pom.xml - 1.0.0.M3 + 1.0.0.BUILD-SNAPSHOT spring-data-redis jar @@ -41,7 +41,7 @@ org.springframework.data spring-data-keyvalue-core - 1.0.0.M3 + 1.0.0.BUILD-SNAPSHOT diff --git a/spring-data-riak/pom.xml b/spring-data-riak/pom.xml index 5f6130d46..76ed4999e 100644 --- a/spring-data-riak/pom.xml +++ b/spring-data-riak/pom.xml @@ -6,7 +6,7 @@ org.springframework.data spring-data-keyvalue-parent ../spring-data-keyvalue-parent/pom.xml - 1.0.0.M3 + 1.0.0.BUILD-SNAPSHOT spring-data-riak jar From 41c5f7e0bcde5ceda4857bb5c70fa0fc0905c50a Mon Sep 17 00:00:00 2001 From: Burt Beckwith Date: Thu, 7 Apr 2011 22:08:54 -0400 Subject: [PATCH 59/68] removed @Override annotations that cause problems in JDK 5 on interface methods --- .../redis/config/RedisNamespaceHandler.java | 2 - .../redis/connection/DefaultMessage.java | 2 - .../connection/DefaultSortParameters.java | 5 - .../DefaultStringRedisConnection.java | 103 -------------- .../redis/connection/DefaultStringTuple.java | 1 - .../redis/connection/DefaultTuple.java | 2 - .../connection/jedis/JedisConnection.java | 129 ------------------ .../jedis/JedisConnectionFactory.java | 2 - .../connection/jredis/JredisConnection.java | 129 ------------------ .../jredis/JredisConnectionFactory.java | 4 - .../redis/connection/rjc/RjcConnection.java | 129 ------------------ .../connection/rjc/RjcConnectionFactory.java | 2 - .../connection/rjc/RjcMessageListener.java | 2 - .../connection/rjc/SingleDataSource.java | 1 - .../connection/util/AbstractSubscription.java | 10 -- .../redis/core/AbstractOperations.java | 1 - .../core/DefaultBoundHashOperations.java | 14 -- .../redis/core/DefaultBoundKeyOperations.java | 6 - .../core/DefaultBoundListOperations.java | 18 --- .../redis/core/DefaultBoundSetOperations.java | 22 --- .../core/DefaultBoundValueOperations.java | 12 -- .../core/DefaultBoundZSetOperations.java | 19 --- .../redis/core/DefaultHashOperations.java | 24 ---- .../redis/core/DefaultListOperations.java | 28 ---- .../redis/core/DefaultSetOperations.java | 36 ----- .../redis/core/DefaultValueOperations.java | 24 ---- .../redis/core/DefaultZSetOperations.java | 35 ----- .../redis/core/RedisConnectionUtils.java | 3 - .../keyvalue/redis/core/RedisTemplate.java | 59 -------- .../core/query/DefaultSortCriterion.java | 6 - .../redis/core/query/DefaultSortQuery.java | 6 - .../redis/hash/BeanUtilsHashMapper.java | 2 - .../hash/DecoratingStringHashMapper.java | 2 - .../redis/hash/JacksonHashMapper.java | 2 - .../RedisMessageListenerContainer.java | 16 --- .../adapter/MessageListenerAdapter.java | 3 - .../serializer/GenericToStringSerializer.java | 3 - .../JacksonJsonRedisSerializer.java | 2 - .../JdkSerializationRedisSerializer.java | 2 - .../redis/serializer/OxmSerializer.java | 3 - .../serializer/StringRedisSerializer.java | 2 - .../support/atomic/RedisAtomicInteger.java | 29 ++-- .../redis/support/atomic/RedisAtomicLong.java | 21 ++- .../collections/AbstractRedisCollection.java | 11 +- .../support/collections/CollectionUtils.java | 2 - .../support/collections/DefaultRedisList.java | 52 ------- .../support/collections/DefaultRedisMap.java | 28 ---- .../support/collections/DefaultRedisSet.java | 15 +- .../support/collections/DefaultRedisZSet.java | 17 --- .../redis/config/StubErrorHandler.java | 2 - .../AbstractConnectionIntegrationTests.java | 12 +- .../data/keyvalue/redis/core/SessionTest.java | 3 - .../adapter/ThrowableMessageListener.java | 1 - .../AbstractRedisCollectionTests.java | 2 - .../collections/AbstractRedisMapTests.java | 2 - .../collections/PersonObjectFactory.java | 1 - .../collections/StringObjectFactory.java | 1 - 57 files changed, 30 insertions(+), 1042 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java index c2cc323e7..36e901697 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java @@ -15,7 +15,6 @@ */ package org.springframework.data.keyvalue.redis.config; -import org.springframework.beans.factory.xml.NamespaceHandler; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; /** @@ -25,7 +24,6 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport; */ class RedisNamespaceHandler extends NamespaceHandlerSupport { - @Override public void init() { registerBeanDefinitionParser("listener-container", new RedisListenerContainerParser()); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultMessage.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultMessage.java index 1fd622577..86e2305b4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultMessage.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultMessage.java @@ -32,12 +32,10 @@ public class DefaultMessage implements Message { this.channel = channel; } - @Override public byte[] getChannel() { return (channel != null ? channel.clone() : null); } - @Override public byte[] getBody() { return (body != null ? body.clone() : null); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java index 62a34bba1..e6b8b3c1f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java @@ -68,7 +68,6 @@ public class DefaultSortParameters implements SortParameters { setGetPattern(getPattern); } - @Override public byte[] getByPattern() { return byPattern; } @@ -77,7 +76,6 @@ public class DefaultSortParameters implements SortParameters { this.byPattern = byPattern; } - @Override public Range getLimit() { return limit; } @@ -86,7 +84,6 @@ public class DefaultSortParameters implements SortParameters { this.limit = limit; } - @Override public byte[][] getGetPattern() { return getPattern.toArray(new byte[getPattern.size()][]); } @@ -103,7 +100,6 @@ public class DefaultSortParameters implements SortParameters { } } - @Override public Order getOrder() { return order; } @@ -112,7 +108,6 @@ public class DefaultSortParameters implements SortParameters { this.order = order; } - @Override public Boolean isAlphabetic() { return alphabetic; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index 04484b29f..a6681fa91 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -621,518 +621,415 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return result; } - @Override public Long append(String key, String value) { return delegate.append(serialize(key), serialize(value)); } - @Override public List bLPop(int timeout, String... keys) { return deserialize(delegate.bLPop(timeout, serializeMulti(keys))); } - @Override public List bRPop(int timeout, String... keys) { return deserialize(delegate.bRPop(timeout, serializeMulti(keys))); } - @Override public String bRPopLPush(int timeout, String srcKey, String dstKey) { return deserialize(delegate.bRPopLPush(timeout, serialize(srcKey), serialize(dstKey))); } - @Override public Long decr(String key) { return delegate.decr(serialize(key)); } - @Override public Long decrBy(String key, long value) { return delegate.decrBy(serialize(key), value); } - @Override public Long del(String... keys) { return delegate.del(serializeMulti(keys)); } - @Override public String echo(String message) { return deserialize(delegate.echo(serialize(message))); } - @Override public Boolean exists(String key) { return delegate.exists(serialize(key)); } - @Override public Boolean expire(String key, long seconds) { return delegate.expire(serialize(key), seconds); } - @Override public Boolean expireAt(String key, long unixTime) { return delegate.expireAt(serialize(key), unixTime); } - @Override public String get(String key) { return deserialize(delegate.get(serialize(key))); } - @Override public Boolean getBit(String key, long offset) { return delegate.getBit(serialize(key), offset); } - @Override public String getRange(String key, long start, long end) { return deserialize(delegate.getRange(serialize(key), start, end)); } - @Override public String getSet(String key, String value) { return deserialize(delegate.getSet(serialize(key), serialize(value))); } - @Override public Boolean hDel(String key, String field) { return delegate.hDel(serialize(key), serialize(field)); } - @Override public Boolean hExists(String key, String field) { return delegate.hExists(serialize(key), serialize(field)); } - @Override public String hGet(String key, String field) { return deserialize(delegate.hGet(serialize(key), serialize(field))); } - @Override public Map hGetAll(String key) { throw new UnsupportedOperationException(); } - @Override public Long hIncrBy(String key, String field, long delta) { return delegate.hIncrBy(serialize(key), serialize(field), delta); } - @Override public Set hKeys(String key) { return deserialize(delegate.hKeys(serialize(key))); } - @Override public Long hLen(String key) { return delegate.hLen(serialize(key)); } - @Override public List hMGet(String key, String... fields) { return deserialize(delegate.hMGet(serialize(key), serializeMulti(fields))); } - @Override public void hMSet(String key, Map hashes) { delegate.hMSet(serialize(key), serialize(hashes)); } - @Override public Boolean hSet(String key, String field, String value) { return delegate.hSet(serialize(key), serialize(field), serialize(value)); } - @Override public Boolean hSetNX(String key, String field, String value) { return delegate.hSetNX(serialize(key), serialize(field), serialize(value)); } - @Override public List hVals(String key) { return deserialize(delegate.hVals(serialize(key))); } - @Override public Long incr(String key) { return delegate.incr(serialize(key)); } - @Override public Long incrBy(String key, long value) { return delegate.incrBy(serialize(key), value); } - @Override public Collection keys(String pattern) { return deserialize(delegate.keys(serialize(pattern))); } - @Override public String lIndex(String key, long index) { return deserialize(delegate.lIndex(serialize(key), index)); } - @Override public Long lInsert(String key, Position where, String pivot, String value) { return delegate.lInsert(serialize(key), where, serialize(pivot), serialize(value)); } - @Override public Long lLen(String key) { return delegate.lLen(serialize(key)); } - @Override public String lPop(String key) { return deserialize(delegate.lPop(serialize(key))); } - @Override public Long lPush(String key, String value) { return delegate.lPush(serialize(key), serialize(value)); } - @Override public Long lPushX(String key, String value) { return delegate.lPushX(serialize(key), serialize(value)); } - @Override public List lRange(String key, long start, long end) { return deserialize(delegate.lRange(serialize(key), start, end)); } - @Override public Long lRem(String key, long count, String value) { return delegate.lRem(serialize(key), count, serialize(value)); } - @Override public void lSet(String key, long index, String value) { delegate.lSet(serialize(key), index, serialize(value)); } - @Override public void lTrim(String key, long start, long end) { delegate.lTrim(serialize(key), start, end); } - @Override public List mGet(String... keys) { return deserialize(delegate.mGet(serializeMulti(keys))); } - @Override public void mSetNXString(Map tuple) { delegate.mSetNX(serialize(tuple)); } - @Override public void mSetString(Map tuple) { delegate.mSet(serialize(tuple)); } - @Override public Boolean persist(String key) { return delegate.persist(serialize(key)); } - @Override public Boolean move(String key, int dbIndex) { return delegate.move(serialize(key), dbIndex); } - @Override public void pSubscribe(MessageListener listener, String... patterns) { delegate.pSubscribe(listener, serializeMulti(patterns)); } - @Override public Long publish(String channel, String message) { return delegate.publish(serialize(channel), serialize(message)); } - @Override public void rename(String oldName, String newName) { delegate.rename(serialize(oldName), serialize(newName)); } - @Override public Boolean renameNX(String oldName, String newName) { return delegate.renameNX(serialize(oldName), serialize(newName)); } - @Override public String rPop(String key) { return deserialize(delegate.rPop(serialize(key))); } - @Override public String rPopLPush(String srcKey, String dstKey) { return deserialize(delegate.rPopLPush(serialize(srcKey), serialize(dstKey))); } - @Override public Long rPush(String key, String value) { return delegate.rPush(serialize(key), serialize(value)); } - @Override public Long rPushX(String key, String value) { return delegate.rPushX(serialize(key), serialize(value)); } - @Override public Boolean sAdd(String key, String value) { return delegate.sAdd(serialize(key), serialize(value)); } - @Override public Long sCard(String key) { return delegate.sCard(serialize(key)); } - @Override public Set sDiff(String... keys) { return deserialize(delegate.sDiff(serializeMulti(keys))); } - @Override public void sDiffStore(String destKey, String... keys) { delegate.sDiffStore(serialize(destKey), serializeMulti(keys)); } - @Override public void set(String key, String value) { delegate.set(serialize(key), serialize(value)); } - @Override public void setBit(String key, long offset, boolean value) { delegate.setBit(serialize(key), offset, value); } - @Override public void setEx(String key, long seconds, String value) { delegate.setEx(serialize(key), seconds, serialize(value)); } - @Override public Boolean setNX(String key, String value) { return delegate.setNX(serialize(key), serialize(value)); } - @Override public void setRange(String key, String value, long start) { delegate.setRange(serialize(key), serialize(value), start); } - @Override public Set sInter(String... keys) { return deserialize(delegate.sInter(serializeMulti(keys))); } - @Override public void sInterStore(String destKey, String... keys) { delegate.sInterStore(serialize(destKey), serializeMulti(keys)); } - @Override public Boolean sIsMember(String key, String value) { return delegate.sIsMember(serialize(key), serialize(value)); } - @Override public Set sMembers(String key) { return deserialize(delegate.sMembers(serialize(key))); } - @Override public Boolean sMove(String srcKey, String destKey, String value) { return delegate.sMove(serialize(srcKey), serialize(destKey), serialize(value)); } - @Override public Long sort(String key, SortParameters params, String storeKey) { return delegate.sort(serialize(key), params, serialize(storeKey)); } - @Override public List sort(String key, SortParameters params) { return deserialize(delegate.sort(serialize(key), params)); } - @Override public String sPop(String key) { return deserialize(delegate.sPop(serialize(key))); } - @Override public String sRandMember(String key) { return deserialize(delegate.sRandMember(serialize(key))); } - @Override public Boolean sRem(String key, String value) { return delegate.sRem(serialize(key), serialize(value)); } - @Override public Long strLen(String key) { return delegate.strLen(serialize(key)); } - @Override public void subscribe(MessageListener listener, String... channels) { delegate.subscribe(listener, serializeMulti(channels)); } - @Override public Set sUnion(String... keys) { return deserialize(delegate.sUnion(serializeMulti(keys))); } - @Override public void sUnionStore(String destKey, String... keys) { delegate.sUnionStore(serialize(destKey), serializeMulti(keys)); } - @Override public Long ttl(String key) { return delegate.ttl(serialize(key)); } - @Override public DataType type(String key) { return delegate.type(serialize(key)); } - @Override public Boolean zAdd(String key, double score, String value) { return delegate.zAdd(serialize(key), score, serialize(value)); } - @Override public Long zCard(String key) { return delegate.zCard(serialize(key)); } - @Override public Long zCount(String key, double min, double max) { return delegate.zCount(serialize(key), min, max); } - @Override public Double zIncrBy(String key, double increment, String value) { return delegate.zIncrBy(serialize(key), increment, serialize(value)); } - @Override public Long zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets) { return delegate.zInterStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); } - @Override public Long zInterStore(String destKey, String... sets) { return delegate.zInterStore(serialize(destKey), serializeMulti(sets)); } - @Override public Set zRange(String key, long start, long end) { return deserialize(delegate.zRange(serialize(key), start, end)); } - @Override public Set zRangeByScore(String key, double min, double max, long offset, long count) { return deserialize(delegate.zRangeByScore(serialize(key), min, max, offset, count)); } - @Override public Set zRangeByScore(String key, double min, double max) { return deserialize(delegate.zRangeByScore(serialize(key), min, max)); } - @Override public Set zRangeByScoreWithScore(String key, double min, double max, long offset, long count) { return deserializeTuple(delegate.zRangeByScoreWithScore(serialize(key), min, max, offset, count)); } - @Override public Set zRangeByScoreWithScore(String key, double min, double max) { return deserializeTuple(delegate.zRangeByScoreWithScore(serialize(key), min, max)); } - @Override public Set zRangeWithScore(String key, long start, long end) { return deserializeTuple(delegate.zRangeWithScore(serialize(key), start, end)); } - @Override public Long zRank(String key, String value) { return delegate.zRank(serialize(key), serialize(value)); } - @Override public Boolean zRem(String key, String value) { return delegate.zRem(serialize(key), serialize(value)); } - @Override public Long zRemRange(String key, long start, long end) { return delegate.zRemRange(serialize(key), start, end); } - @Override public Long zRemRangeByScore(String key, double min, double max) { return delegate.zRemRangeByScore(serialize(key), min, max); } - @Override public Set zRevRange(String key, long start, long end) { return deserialize(delegate.zRevRange(serialize(key), start, end)); } - @Override public Set zRevRangeWithScore(String key, long start, long end) { return deserializeTuple(delegate.zRevRangeWithScore(serialize(key), start, end)); } - @Override public Long zRevRank(String key, String value) { return delegate.zRevRank(serialize(key), serialize(value)); } - @Override public Double zScore(String key, String value) { return delegate.zScore(serialize(key), serialize(value)); } - @Override public Long zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets) { return delegate.zUnionStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); } - @Override public Long zUnionStore(String destKey, String... sets) { return delegate.zUnionStore(serialize(destKey), serializeMulti(sets)); } - @Override public List closePipeline() { return delegate.closePipeline(); } - @Override public boolean isPipelined() { return delegate.isPipelined(); } - @Override public void openPipeline() { delegate.openPipeline(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringTuple.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringTuple.java index 9ed234216..8e281f108 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringTuple.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringTuple.java @@ -50,7 +50,6 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple { this.valueAsString = valueAsString; } - @Override public String getValueAsString() { return valueAsString; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultTuple.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultTuple.java index e9c366fda..f623f7d76 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultTuple.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultTuple.java @@ -39,12 +39,10 @@ public class DefaultTuple implements Tuple { this.value = value; } - @Override public Double getScore() { return score; } - @Override public byte[] getValue() { return value; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 410f5fef8..1eac23abb 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -120,7 +120,6 @@ public class JedisConnection implements RedisConnection { return new UncategorizedKeyvalueStoreException("Unknown jedis exception", ex); } - @Override public void close() throws DataAccessException { // return the connection to the pool try { @@ -154,12 +153,10 @@ public class JedisConnection implements RedisConnection { } } - @Override public Jedis getNativeConnection() { return jedis; } - @Override public boolean isClosed() { try { return !jedis.isConnected(); @@ -168,17 +165,14 @@ public class JedisConnection implements RedisConnection { } } - @Override public boolean isQueueing() { return client.isInMulti(); } - @Override public boolean isPipelined() { return (pipeline != null); } - @Override public void openPipeline() { if (pipeline == null) { pipeline = jedis.pipelined(); @@ -186,7 +180,6 @@ public class JedisConnection implements RedisConnection { } @SuppressWarnings("unchecked") - @Override public List closePipeline() { if (pipeline != null) { List execute = pipeline.execute(); @@ -197,7 +190,6 @@ public class JedisConnection implements RedisConnection { return Collections.emptyList(); } - @Override public List sort(byte[] key, SortParameters params) { SortingParams sortParams = JedisUtils.convertSortParams(params); @@ -229,7 +221,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long sort(byte[] key, SortParameters params, byte[] sortKey) { SortingParams sortParams = JedisUtils.convertSortParams(params); @@ -261,7 +252,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long dbSize() { try { if (isQueueing()) { @@ -278,7 +268,6 @@ public class JedisConnection implements RedisConnection { } - @Override public void flushDb() { try { if (isQueueing()) { @@ -294,7 +283,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void flushAll() { try { if (isQueueing()) { @@ -310,7 +298,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void bgSave() { try { if (isQueueing()) { @@ -326,7 +313,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void bgWriteAof() { try { if (isQueueing()) { @@ -342,7 +328,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void save() { try { if (isQueueing()) { @@ -358,7 +343,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public List getConfig(String param) { try { if (isQueueing()) { @@ -374,7 +358,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Properties info() { try { if (isQueueing()) { @@ -389,7 +372,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long lastSave() { try { if (isQueueing()) { @@ -405,7 +387,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void setConfig(String param, String value) { try { if (isQueueing()) { @@ -422,7 +403,6 @@ public class JedisConnection implements RedisConnection { } - @Override public void resetConfigStats() { try { if (isQueueing()) { @@ -438,7 +418,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void shutdown() { try { if (isQueueing()) { @@ -453,7 +432,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] echo(byte[] message) { try { if (isQueueing()) { @@ -469,7 +447,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public String ping() { try { if (isQueueing()) { @@ -485,7 +462,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long del(byte[]... keys) { try { if (isQueueing()) { @@ -502,7 +478,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void discard() { try { client.discard(); @@ -511,7 +486,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public List exec() { try { if (isPipelined()) { @@ -524,7 +498,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean exists(byte[] key) { try { if (isQueueing()) { @@ -541,7 +514,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean expire(byte[] key, long seconds) { try { if (isQueueing()) { @@ -558,7 +530,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean expireAt(byte[] key, long unixTime) { try { if (isQueueing()) { @@ -575,7 +546,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set keys(byte[] pattern) { try { if (isQueueing()) { @@ -592,7 +562,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void multi() { if (isQueueing()) { return; @@ -608,7 +577,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean persist(byte[] key) { try { if (isQueueing()) { @@ -625,7 +593,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean move(byte[] key, int dbIndex) { try { if (isQueueing()) { @@ -642,7 +609,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] randomKey() { try { if (isQueueing()) { @@ -658,7 +624,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void rename(byte[] oldName, byte[] newName) { try { if (isQueueing()) { @@ -675,7 +640,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean renameNX(byte[] oldName, byte[] newName) { try { if (isQueueing()) { @@ -692,7 +656,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void select(int dbIndex) { try { if (isQueueing()) { @@ -708,7 +671,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long ttl(byte[] key) { try { if (isQueueing()) { @@ -725,7 +687,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public DataType type(byte[] key) { try { if (isQueueing()) { @@ -742,7 +703,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void unwatch() { try { jedis.unwatch(); @@ -751,7 +711,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void watch(byte[]... keys) { if (isQueueing()) { // ignore (as watch not allowed in multi) @@ -775,7 +734,6 @@ public class JedisConnection implements RedisConnection { // String commands // - @Override public byte[] get(byte[] key) { try { if (isQueueing()) { @@ -793,7 +751,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void set(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -811,7 +768,6 @@ public class JedisConnection implements RedisConnection { } - @Override public byte[] getSet(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -828,7 +784,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long append(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -845,7 +800,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public List mGet(byte[]... keys) { try { if (isQueueing()) { @@ -862,7 +816,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void mSet(Map tuples) { try { if (isQueueing()) { @@ -879,7 +832,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void mSetNX(Map tuples) { try { if (isQueueing()) { @@ -896,7 +848,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void setEx(byte[] key, long time, byte[] value) { try { if (isQueueing()) { @@ -913,7 +864,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean setNX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -930,7 +880,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] getRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -947,7 +896,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long decr(byte[] key) { try { if (isQueueing()) { @@ -964,7 +912,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long decrBy(byte[] key, long value) { try { if (isQueueing()) { @@ -981,7 +928,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long incr(byte[] key) { try { if (isQueueing()) { @@ -998,7 +944,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long incrBy(byte[] key, long value) { try { if (isQueueing()) { @@ -1015,7 +960,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean getBit(byte[] key, long offset) { try { if (isQueueing()) { @@ -1032,7 +976,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void setBit(byte[] key, long offset, boolean value) { try { if (isQueueing()) { @@ -1049,12 +992,10 @@ public class JedisConnection implements RedisConnection { } } - @Override public void setRange(byte[] key, byte[] value, long start) { throw new UnsupportedOperationException(); } - @Override public Long strLen(byte[] key) { try { if (isQueueing()) { @@ -1074,7 +1015,6 @@ public class JedisConnection implements RedisConnection { // List commands // - @Override public Long lPush(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1091,7 +1031,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long rPush(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1108,7 +1047,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public List bLPop(int timeout, byte[]... keys) { try { if (isQueueing()) { @@ -1129,7 +1067,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public List bRPop(int timeout, byte[]... keys) { try { if (isQueueing()) { @@ -1150,7 +1087,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] lIndex(byte[] key, long index) { try { if (isQueueing()) { @@ -1167,7 +1103,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { try { if (isQueueing()) { @@ -1185,7 +1120,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long lLen(byte[] key) { try { if (isQueueing()) { @@ -1202,7 +1136,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] lPop(byte[] key) { try { if (isQueueing()) { @@ -1219,7 +1152,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public List lRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1236,7 +1168,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long lRem(byte[] key, long count, byte[] value) { try { if (isQueueing()) { @@ -1253,7 +1184,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void lSet(byte[] key, long index, byte[] value) { try { if (isQueueing()) { @@ -1270,7 +1200,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void lTrim(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1287,7 +1216,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] rPop(byte[] key) { try { if (isQueueing()) { @@ -1304,7 +1232,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { if (isQueueing()) { @@ -1321,7 +1248,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { try { if (isQueueing()) { @@ -1337,7 +1263,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long lPushX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1353,7 +1278,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long rPushX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1374,7 +1298,6 @@ public class JedisConnection implements RedisConnection { // Set commands // - @Override public Boolean sAdd(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1391,7 +1314,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long sCard(byte[] key) { try { if (isQueueing()) { @@ -1408,7 +1330,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set sDiff(byte[]... keys) { try { if (isQueueing()) { @@ -1425,7 +1346,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void sDiffStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1442,7 +1362,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set sInter(byte[]... keys) { try { if (isQueueing()) { @@ -1459,7 +1378,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void sInterStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1476,7 +1394,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean sIsMember(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1493,7 +1410,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set sMembers(byte[] key) { try { if (isQueueing()) { @@ -1510,7 +1426,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { if (isQueueing()) { @@ -1527,7 +1442,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] sPop(byte[] key) { try { if (isQueueing()) { @@ -1544,7 +1458,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] sRandMember(byte[] key) { try { if (isQueueing()) { @@ -1561,7 +1474,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean sRem(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1578,7 +1490,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set sUnion(byte[]... keys) { try { if (isQueueing()) { @@ -1595,7 +1506,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void sUnionStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1616,7 +1526,6 @@ public class JedisConnection implements RedisConnection { // ZSet commands // - @Override public Boolean zAdd(byte[] key, double score, byte[] value) { try { if (isQueueing()) { @@ -1633,7 +1542,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zCard(byte[] key) { try { if (isQueueing()) { @@ -1650,7 +1558,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zCount(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1666,7 +1573,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Double zIncrBy(byte[] key, double increment, byte[] value) { try { if (isQueueing()) { @@ -1683,7 +1589,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { if (isQueueing()) { @@ -1701,7 +1606,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zInterStore(byte[] destKey, byte[]... sets) { try { if (isQueueing()) { @@ -1717,7 +1621,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set zRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1734,7 +1637,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set zRangeWithScore(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1751,7 +1653,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set zRangeByScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1767,7 +1668,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1783,7 +1683,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set zRevRangeWithScore(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1799,7 +1698,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { @@ -1815,7 +1713,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { @@ -1831,7 +1728,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zRank(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1848,7 +1744,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean zRem(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1865,7 +1760,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zRemRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1881,7 +1775,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zRemRangeByScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1897,7 +1790,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set zRevRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1914,7 +1806,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zRevRank(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1931,7 +1822,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Double zScore(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1948,7 +1838,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { if (isQueueing()) { @@ -1966,7 +1855,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long zUnionStore(byte[] destKey, byte[]... sets) { try { if (isQueueing()) { @@ -1986,7 +1874,6 @@ public class JedisConnection implements RedisConnection { // Hash commands // - @Override public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { if (isQueueing()) { @@ -2003,7 +1890,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { try { if (isQueueing()) { @@ -2020,7 +1906,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean hDel(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -2037,7 +1922,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Boolean hExists(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -2054,7 +1938,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public byte[] hGet(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -2071,7 +1954,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Map hGetAll(byte[] key) { try { if (isQueueing()) { @@ -2088,7 +1970,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long hIncrBy(byte[] key, byte[] field, long delta) { try { if (isQueueing()) { @@ -2105,7 +1986,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Set hKeys(byte[] key) { try { if (isQueueing()) { @@ -2122,7 +2002,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public Long hLen(byte[] key) { try { if (isQueueing()) { @@ -2139,7 +2018,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public List hMGet(byte[] key, byte[]... fields) { try { if (isQueueing()) { @@ -2156,7 +2034,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void hMSet(byte[] key, Map tuple) { try { if (isQueueing()) { @@ -2173,7 +2050,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public List hVals(byte[] key) { try { if (isQueueing()) { @@ -2194,7 +2070,6 @@ public class JedisConnection implements RedisConnection { // // Pub/Sub functionality // - @Override public Long publish(byte[] channel, byte[] message) { try { if (isQueueing()) { @@ -2209,17 +2084,14 @@ public class JedisConnection implements RedisConnection { } } - @Override public Subscription getSubscription() { return subscription; } - @Override public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } - @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( @@ -2244,7 +2116,6 @@ public class JedisConnection implements RedisConnection { } } - @Override public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java index 51f326a39..acee611dc 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java @@ -22,7 +22,6 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -150,7 +149,6 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, null, dbIndex))); } - @Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return JedisUtils.convertJedisAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index ada3441e1..329ab8f97 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -74,7 +74,6 @@ public class JredisConnection implements RedisConnection { return new UncategorizedKeyvalueStoreException("Unknown JRedis exception", ex); } - @Override public void close() throws RedisSystemException { isClosed = true; @@ -89,37 +88,30 @@ public class JredisConnection implements RedisConnection { } } - @Override public JRedis getNativeConnection() { return jredis; } - @Override public boolean isClosed() { return isClosed; } - @Override public boolean isQueueing() { return false; } - @Override public boolean isPipelined() { return false; } - @Override public void openPipeline() { throw new UnsupportedOperationException("Pipelining not supported by JRedis"); } - @Override public List closePipeline() { return Collections.emptyList(); } - @Override public List sort(byte[] key, SortParameters params) { Sort sort = jredis.sort(JredisUtils.decode(key)); JredisUtils.applySortingParams(sort, params, null); @@ -130,7 +122,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long sort(byte[] key, SortParameters params, byte[] storeKey) { Sort sort = jredis.sort(JredisUtils.decode(key)); JredisUtils.applySortingParams(sort, params, null); @@ -141,7 +132,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long dbSize() { try { return jredis.dbsize(); @@ -150,7 +140,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void flushDb() { try { jredis.flushdb(); @@ -159,7 +148,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void flushAll() { try { jredis.flushall(); @@ -168,7 +156,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] echo(byte[] message) { try { return jredis.echo(message); @@ -177,7 +164,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public String ping() { try { jredis.ping(); @@ -187,7 +173,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void bgSave() { try { jredis.bgsave(); @@ -196,7 +181,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void bgWriteAof() { try { jredis.bgrewriteaof(); @@ -205,7 +189,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void save() { try { jredis.save(); @@ -214,12 +197,10 @@ public class JredisConnection implements RedisConnection { } } - @Override public List getConfig(String pattern) { throw new UnsupportedOperationException(); } - @Override public Properties info() { try { return JredisUtils.info(jredis.info()); @@ -228,7 +209,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long lastSave() { try { return jredis.lastsave(); @@ -237,22 +217,18 @@ public class JredisConnection implements RedisConnection { } } - @Override public void setConfig(String param, String value) { throw new UnsupportedOperationException(); } - @Override public void resetConfigStats() { throw new UnsupportedOperationException(); } - @Override public void shutdown() { throw new UnsupportedOperationException(); } - @Override public Long del(byte[]... keys) { try { return jredis.del(JredisUtils.decodeMultiple(keys)); @@ -261,7 +237,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void discard() { try { jredis.discard(); @@ -270,12 +245,10 @@ public class JredisConnection implements RedisConnection { } } - @Override public List exec() { throw new UnsupportedOperationException(); } - @Override public Boolean exists(byte[] key) { try { return jredis.exists(JredisUtils.decode(key)); @@ -284,7 +257,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean expire(byte[] key, long seconds) { try { return jredis.expire(JredisUtils.decode(key), (int) seconds); @@ -293,7 +265,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean expireAt(byte[] key, long unixTime) { try { return jredis.expireat(JredisUtils.decode(key), unixTime); @@ -302,7 +273,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set keys(byte[] pattern) { try { return JredisUtils.convertToSet(jredis.keys(JredisUtils.decode(pattern))); @@ -311,18 +281,15 @@ public class JredisConnection implements RedisConnection { } } - @Override public void multi() { throw new UnsupportedOperationException(); } - @Override public Boolean persist(byte[] key) { throw new UnsupportedOperationException(); } - @Override public Boolean move(byte[] key, int dbIndex) { try { return jredis.move(JredisUtils.decode(key), dbIndex); @@ -331,7 +298,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] randomKey() { try { return JredisUtils.encode(jredis.randomkey()); @@ -340,7 +306,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void rename(byte[] oldName, byte[] newName) { try { jredis.rename(JredisUtils.decode(oldName), JredisUtils.decode(newName)); @@ -349,7 +314,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean renameNX(byte[] oldName, byte[] newName) { try { return jredis.renamenx(JredisUtils.decode(oldName), JredisUtils.decode(newName)); @@ -358,12 +322,10 @@ public class JredisConnection implements RedisConnection { } } - @Override public void select(int dbIndex) { throw new UnsupportedOperationException(); } - @Override public Long ttl(byte[] key) { try { return jredis.ttl(JredisUtils.decode(key)); @@ -372,7 +334,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public DataType type(byte[] key) { try { return JredisUtils.convertDataType(jredis.type(JredisUtils.decode(key))); @@ -381,12 +342,10 @@ public class JredisConnection implements RedisConnection { } } - @Override public void unwatch() { throw new UnsupportedOperationException(); } - @Override public void watch(byte[]... keys) { throw new UnsupportedOperationException(); } @@ -395,7 +354,6 @@ public class JredisConnection implements RedisConnection { // String operations // - @Override public byte[] get(byte[] key) { try { return jredis.get(JredisUtils.decode(key)); @@ -404,7 +362,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void set(byte[] key, byte[] value) { try { jredis.set(JredisUtils.decode(key), value); @@ -413,7 +370,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] getSet(byte[] key, byte[] value) { try { return jredis.getset(JredisUtils.decode(key), value); @@ -422,7 +378,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long append(byte[] key, byte[] value) { try { return jredis.append(JredisUtils.decode(key), value); @@ -431,7 +386,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public List mGet(byte[]... keys) { try { return jredis.mget(JredisUtils.decodeMultiple(keys)); @@ -440,7 +394,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void mSet(Map tuple) { try { jredis.mset(JredisUtils.decodeMap(tuple)); @@ -449,7 +402,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void mSetNX(Map tuple) { try { jredis.msetnx(JredisUtils.decodeMap(tuple)); @@ -458,12 +410,10 @@ public class JredisConnection implements RedisConnection { } } - @Override public void setEx(byte[] key, long seconds, byte[] value) { throw new UnsupportedOperationException(); } - @Override public Boolean setNX(byte[] key, byte[] value) { try { return jredis.setnx(JredisUtils.decode(key), value); @@ -472,7 +422,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] getRange(byte[] key, long start, long end) { try { return jredis.substr(JredisUtils.decode(key), start, end); @@ -481,7 +430,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long decr(byte[] key) { try { return jredis.decr(JredisUtils.decode(key)); @@ -490,7 +438,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long decrBy(byte[] key, long value) { try { return jredis.decrby(JredisUtils.decode(key), (int) value); @@ -499,7 +446,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long incr(byte[] key) { try { return jredis.incr(JredisUtils.decode(key)); @@ -508,7 +454,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long incrBy(byte[] key, long value) { try { return jredis.incrby(JredisUtils.decode(key), (int) value); @@ -517,22 +462,18 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean getBit(byte[] key, long offset) { throw new UnsupportedOperationException(); } - @Override public void setBit(byte[] key, long offset, boolean value) { throw new UnsupportedOperationException(); } - @Override public void setRange(byte[] key, byte[] value, long start) { throw new UnsupportedOperationException(); } - @Override public Long strLen(byte[] key) { throw new UnsupportedOperationException(); } @@ -541,17 +482,14 @@ public class JredisConnection implements RedisConnection { // List commands // - @Override public List bLPop(int timeout, byte[]... keys) { throw new UnsupportedOperationException(); } - @Override public List bRPop(int timeout, byte[]... keys) { throw new UnsupportedOperationException(); } - @Override public byte[] lIndex(byte[] key, long index) { try { return jredis.lindex(JredisUtils.decode(key), index); @@ -560,7 +498,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long lLen(byte[] key) { try { return jredis.llen(JredisUtils.decode(key)); @@ -569,7 +506,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] lPop(byte[] key) { try { return jredis.lpop(JredisUtils.decode(key)); @@ -578,7 +514,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long lPush(byte[] key, byte[] value) { try { jredis.lpush(JredisUtils.decode(key), value); @@ -588,7 +523,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public List lRange(byte[] key, long start, long end) { try { List lrange = jredis.lrange(JredisUtils.decode(key), start, end); @@ -599,7 +533,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long lRem(byte[] key, long count, byte[] value) { try { return jredis.lrem(JredisUtils.decode(key), value, (int) count); @@ -608,7 +541,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void lSet(byte[] key, long index, byte[] value) { try { jredis.lset(JredisUtils.decode(key), index, value); @@ -617,7 +549,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void lTrim(byte[] key, long start, long end) { try { jredis.ltrim(JredisUtils.decode(key), start, end); @@ -626,7 +557,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] rPop(byte[] key) { try { return jredis.rpop(JredisUtils.decode(key)); @@ -635,7 +565,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { return jredis.rpoplpush(JredisUtils.decode(srcKey), JredisUtils.decode(dstKey)); @@ -644,7 +573,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long rPush(byte[] key, byte[] value) { try { jredis.rpush(JredisUtils.decode(key), value); @@ -654,22 +582,18 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { throw new UnsupportedOperationException(); } - @Override public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { throw new UnsupportedOperationException(); } - @Override public Long lPushX(byte[] key, byte[] value) { throw new UnsupportedOperationException(); } - @Override public Long rPushX(byte[] key, byte[] value) { throw new UnsupportedOperationException(); } @@ -679,7 +603,6 @@ public class JredisConnection implements RedisConnection { // Set commands // - @Override public Boolean sAdd(byte[] key, byte[] value) { try { return jredis.sadd(JredisUtils.decode(key), value); @@ -688,7 +611,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long sCard(byte[] key) { try { return jredis.scard(JredisUtils.decode(key)); @@ -697,7 +619,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set sDiff(byte[]... keys) { String destKey = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -710,7 +631,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void sDiffStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -722,7 +642,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set sInter(byte[]... keys) { String set1 = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -735,7 +654,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void sInterStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -747,7 +665,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean sIsMember(byte[] key, byte[] value) { try { return jredis.sismember(JredisUtils.decode(key), value); @@ -756,7 +673,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set sMembers(byte[] key) { try { return new LinkedHashSet(jredis.smembers(JredisUtils.decode(key))); @@ -765,7 +681,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { return jredis.smove(JredisUtils.decode(srcKey), JredisUtils.decode(destKey), value); @@ -774,7 +689,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] sPop(byte[] key) { try { return jredis.spop(JredisUtils.decode(key)); @@ -783,7 +697,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] sRandMember(byte[] key) { try { return jredis.srandmember(JredisUtils.decode(key)); @@ -792,7 +705,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean sRem(byte[] key, byte[] value) { try { return jredis.srem(JredisUtils.decode(key), value); @@ -801,7 +713,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set sUnion(byte[]... keys) { String set1 = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -813,7 +724,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public void sUnionStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -830,7 +740,6 @@ public class JredisConnection implements RedisConnection { // ZSet commands // - @Override public Boolean zAdd(byte[] key, double score, byte[] value) { try { return jredis.zadd(JredisUtils.decode(key), score, value); @@ -839,7 +748,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long zCard(byte[] key) { try { return jredis.zcard(JredisUtils.decode(key)); @@ -848,7 +756,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long zCount(byte[] key, double min, double max) { try { return jredis.zcount(JredisUtils.decode(key), min, max); @@ -857,7 +764,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Double zIncrBy(byte[] key, double increment, byte[] value) { try { return jredis.zincrby(JredisUtils.decode(key), increment, value); @@ -866,17 +772,14 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } - @Override public Long zInterStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } - @Override public Set zRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrange(JredisUtils.decode(key), start, end)); @@ -885,13 +788,11 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set zRangeWithScore(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } - @Override public Set zRangeByScore(byte[] key, double min, double max) { try { return new LinkedHashSet(jredis.zrangebyscore(JredisUtils.decode(key), min, max)); @@ -900,22 +801,18 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max) { throw new UnsupportedOperationException(); } - @Override public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - @Override public Long zRank(byte[] key, byte[] value) { try { return jredis.zrank(JredisUtils.decode(key), value); @@ -924,7 +821,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean zRem(byte[] key, byte[] value) { try { return jredis.zrem(JredisUtils.decode(key), value); @@ -933,7 +829,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long zRemRange(byte[] key, long start, long end) { try { return jredis.zremrangebyrank(JredisUtils.decode(key), start, end); @@ -942,7 +837,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long zRemRangeByScore(byte[] key, double min, double max) { try { return jredis.zremrangebyscore(JredisUtils.decode(key), min, max); @@ -951,7 +845,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set zRevRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrevrange(JredisUtils.decode(key), start, end)); @@ -960,12 +853,10 @@ public class JredisConnection implements RedisConnection { } } - @Override public Set zRevRangeWithScore(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } - @Override public Long zRevRank(byte[] key, byte[] value) { try { return jredis.zrevrank(JredisUtils.decode(key), value); @@ -974,7 +865,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Double zScore(byte[] key, byte[] value) { try { return jredis.zscore(JredisUtils.decode(key), value); @@ -988,17 +878,14 @@ public class JredisConnection implements RedisConnection { // Hash commands // - @Override public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } - @Override public Long zUnionStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } - @Override public Boolean hDel(byte[] key, byte[] field) { try { return jredis.hdel(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -1007,7 +894,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean hExists(byte[] key, byte[] field) { try { return jredis.hexists(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -1016,7 +902,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public byte[] hGet(byte[] key, byte[] field) { try { return jredis.hget(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -1025,7 +910,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Map hGetAll(byte[] key) { try { return JredisUtils.encodeMap(jredis.hgetall(JredisUtils.decode(key))); @@ -1034,12 +918,10 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long hIncrBy(byte[] key, byte[] field, long delta) { throw new UnsupportedOperationException(); } - @Override public Set hKeys(byte[] key) { try { return new LinkedHashSet(JredisUtils.convertToSet(jredis.hkeys(JredisUtils.decode(key)))); @@ -1048,7 +930,6 @@ public class JredisConnection implements RedisConnection { } } - @Override public Long hLen(byte[] key) { try { return jredis.hlen(JredisUtils.decode(key)); @@ -1057,17 +938,14 @@ public class JredisConnection implements RedisConnection { } } - @Override public List hMGet(byte[] key, byte[]... fields) { throw new UnsupportedOperationException(); } - @Override public void hMSet(byte[] key, Map values) { throw new UnsupportedOperationException(); } - @Override public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { return jredis.hset(JredisUtils.decode(key), JredisUtils.decode(field), value); @@ -1076,12 +954,10 @@ public class JredisConnection implements RedisConnection { } } - @Override public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { throw new UnsupportedOperationException(); } - @Override public List hVals(byte[] key) { try { return jredis.hvals(JredisUtils.decode(key)); @@ -1094,27 +970,22 @@ public class JredisConnection implements RedisConnection { // PubSub commands // - @Override public Subscription getSubscription() { return null; } - @Override public boolean isSubscribed() { return false; } - @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { throw new UnsupportedOperationException(); } - @Override public Long publish(byte[] channel, byte[] message) { throw new UnsupportedOperationException(); } - @Override public void subscribe(MessageListener listener, byte[]... channels) { throw new UnsupportedOperationException(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java index 87ae5c1a5..852c184a2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java @@ -72,7 +72,6 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean this.connectionSpec = connectionSpec; } - @Override public void afterPropertiesSet() { if (connectionSpec == null) { Assert.hasText(hostName); @@ -95,7 +94,6 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean } - @Override public void destroy() { if (usePool && pool != null) { pool.quit(); @@ -104,7 +102,6 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean } - @Override public RedisConnection getConnection() { return postProcessConnection(new JredisConnection((usePool ? pool : new JRedisClient(connectionSpec)))); } @@ -122,7 +119,6 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean return connection; } - @Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof ClientRuntimeException) { return JredisUtils.convertJredisAccessException((ClientRuntimeException) ex); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 50d5f78f0..71743571f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -76,7 +76,6 @@ public class RjcConnection implements RedisConnection { return new UncategorizedKeyvalueStoreException("Unknown rjc exception", ex); } - @Override public void close() throws DataAccessException { isClosed = true; @@ -89,27 +88,22 @@ public class RjcConnection implements RedisConnection { } - @Override public boolean isClosed() { return isClosed; } - @Override public Session getNativeConnection() { return session; } - @Override public boolean isQueueing() { return client.isInMulti(); } - @Override public boolean isPipelined() { return (pipeline != null); } - @Override public void openPipeline() { if (pipeline == null) { pipeline = client; @@ -117,7 +111,6 @@ public class RjcConnection implements RedisConnection { } @SuppressWarnings("unchecked") - @Override public List closePipeline() { if (pipeline != null) { List execute = client.getAll(); @@ -128,7 +121,6 @@ public class RjcConnection implements RedisConnection { return Collections.emptyList(); } - @Override public List sort(byte[] key, SortParameters params) { SortingParams sortParams = RjcUtils.convertSortParams(params); @@ -152,7 +144,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long sort(byte[] key, SortParameters params, byte[] sortKey) { SortingParams sortParams = RjcUtils.convertSortParams(params); @@ -177,7 +168,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long dbSize() { try { if (isPipelined()) { @@ -191,7 +181,6 @@ public class RjcConnection implements RedisConnection { } - @Override public void flushDb() { try { if (isPipelined()) { @@ -204,7 +193,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void flushAll() { try { if (isPipelined()) { @@ -217,7 +205,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void bgSave() { try { if (isPipelined()) { @@ -230,7 +217,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void bgWriteAof() { try { if (isPipelined()) { @@ -243,7 +229,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void save() { try { if (isPipelined()) { @@ -256,7 +241,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public List getConfig(String param) { try { if (isPipelined()) { @@ -269,7 +253,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Properties info() { try { if (isPipelined()) { @@ -282,7 +265,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long lastSave() { try { if (isPipelined()) { @@ -295,7 +277,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void setConfig(String param, String value) { try { if (isPipelined()) { @@ -309,7 +290,6 @@ public class RjcConnection implements RedisConnection { } - @Override public void resetConfigStats() { try { if (isPipelined()) { @@ -323,7 +303,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void shutdown() { try { if (isPipelined()) { @@ -336,7 +315,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] echo(byte[] message) { String stringMsg = RjcUtils.decode(message); try { @@ -350,7 +328,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public String ping() { try { if (isPipelined()) { @@ -362,7 +339,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long del(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -377,7 +353,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void discard() { try { if (isPipelined()) { @@ -391,7 +366,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public List exec() { try { if (isPipelined()) { @@ -404,7 +378,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean exists(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -419,7 +392,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean expire(byte[] key, long seconds) { String stringKey = RjcUtils.decode(key); @@ -434,7 +406,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean expireAt(byte[] key, long unixTime) { String stringKey = RjcUtils.decode(key); @@ -449,7 +420,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set keys(byte[] pattern) { String stringKey = RjcUtils.decode(pattern); @@ -464,7 +434,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void multi() { if (isQueueing()) { return; @@ -480,7 +449,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean persist(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -495,7 +463,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean move(byte[] key, int dbIndex) { String stringKey = RjcUtils.decode(key); @@ -510,7 +477,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] randomKey() { try { if (isPipelined()) { @@ -523,7 +489,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void rename(byte[] oldName, byte[] newName) { String stringOldKey = RjcUtils.decode(oldName); String stringNewKey = RjcUtils.decode(newName); @@ -539,7 +504,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean renameNX(byte[] oldName, byte[] newName) { String stringOldKey = RjcUtils.decode(oldName); String stringNewKey = RjcUtils.decode(newName); @@ -555,7 +519,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void select(int dbIndex) { try { if (isPipelined()) { @@ -568,7 +531,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long ttl(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -583,7 +545,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public DataType type(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -598,7 +559,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void unwatch() { try { if (isPipelined()) { @@ -612,7 +572,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void watch(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -636,7 +595,6 @@ public class RjcConnection implements RedisConnection { // String commands // - @Override public byte[] get(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -652,7 +610,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void set(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -669,7 +626,6 @@ public class RjcConnection implements RedisConnection { } - @Override public byte[] getSet(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -685,7 +641,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long append(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -701,7 +656,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public List mGet(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -716,7 +670,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void mSet(Map tuples) { String[] decodeMap = RjcUtils.flatten(tuples); @@ -731,7 +684,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void mSetNX(Map tuples) { String[] decodeMap = RjcUtils.flatten(tuples); @@ -747,7 +699,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void setEx(byte[] key, long time, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -763,7 +714,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean setNX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -779,7 +729,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] getRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -794,7 +743,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long decr(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -809,7 +757,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long decrBy(byte[] key, long value) { String stringKey = RjcUtils.decode(key); try { @@ -824,7 +771,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long incr(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -840,7 +786,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long incrBy(byte[] key, long value) { String stringKey = RjcUtils.decode(key); @@ -856,7 +801,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean getBit(byte[] key, long offset) { String stringKey = RjcUtils.decode(key); @@ -871,7 +815,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void setBit(byte[] key, long offset, boolean value) { String stringKey = RjcUtils.decode(key); @@ -886,7 +829,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void setRange(byte[] key, byte[] value, long offset) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -902,7 +844,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long strLen(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -921,7 +862,6 @@ public class RjcConnection implements RedisConnection { // List commands // - @Override public Long lPush(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -937,7 +877,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long rPush(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -954,7 +893,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public List bLPop(int timeout, byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -969,7 +907,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public List bRPop(int timeout, byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -984,7 +921,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] lIndex(byte[] key, long index) { String stringKey = RjcUtils.decode(key); @@ -1000,7 +936,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1018,7 +953,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long lLen(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1034,7 +968,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] lPop(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1050,7 +983,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public List lRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -1066,7 +998,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long lRem(byte[] key, long count, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1083,7 +1014,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void lSet(byte[] key, long index, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1099,7 +1029,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void lTrim(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -1115,7 +1044,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] rPop(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1131,7 +1059,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { String stringKey = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(dstKey); @@ -1148,7 +1075,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { String stringKey = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(dstKey); @@ -1164,7 +1090,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long lPushX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1179,7 +1104,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long rPushX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1199,7 +1123,6 @@ public class RjcConnection implements RedisConnection { // Set commands // - @Override public Boolean sAdd(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1216,7 +1139,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long sCard(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1232,7 +1154,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set sDiff(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1248,7 +1169,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void sDiffStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1265,7 +1185,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set sInter(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); try { @@ -1280,7 +1199,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void sInterStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1296,7 +1214,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean sIsMember(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1313,7 +1230,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set sMembers(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1328,7 +1244,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { String stringSrc = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(destKey); @@ -1346,7 +1261,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] sPop(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1361,7 +1275,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] sRandMember(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1376,7 +1289,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean sRem(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1393,7 +1305,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set sUnion(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1409,7 +1320,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void sUnionStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1430,7 +1340,6 @@ public class RjcConnection implements RedisConnection { // ZSet commands // - @Override public Boolean zAdd(byte[] key, double score, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1446,7 +1355,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zCard(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1461,7 +1369,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zCount(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); try { @@ -1476,7 +1383,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Double zIncrBy(byte[] key, double increment, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1492,7 +1398,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1510,7 +1415,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zInterStore(byte[] destKey, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1526,7 +1430,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set zRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1541,7 +1444,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set zRangeWithScore(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1556,7 +1458,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set zRangeByScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1573,7 +1474,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1590,7 +1490,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set zRevRangeWithScore(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); String minString = Long.toString(start); @@ -1608,7 +1507,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1626,7 +1524,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1644,7 +1541,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zRank(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1660,7 +1556,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean zRem(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1676,7 +1571,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zRemRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1690,7 +1584,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zRemRangeByScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1707,7 +1600,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set zRevRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1722,7 +1614,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zRevRank(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1738,7 +1629,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Double zScore(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1754,7 +1644,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(destKey); @@ -1772,7 +1661,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long zUnionStore(byte[] destKey, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1792,7 +1680,6 @@ public class RjcConnection implements RedisConnection { // Hash commands // - @Override public Boolean hSet(byte[] key, byte[] field, byte[] value) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1809,7 +1696,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1826,7 +1712,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean hDel(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1842,7 +1727,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Boolean hExists(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1858,7 +1742,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public byte[] hGet(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1874,7 +1757,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Map hGetAll(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1889,7 +1771,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long hIncrBy(byte[] key, byte[] field, long delta) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1905,7 +1786,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Set hKeys(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1919,7 +1799,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public Long hLen(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1933,7 +1812,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public List hMGet(byte[] key, byte[]... fields) { String stringKey = RjcUtils.decode(key); String[] stringKeys = RjcUtils.decodeMultiple(fields); @@ -1949,7 +1827,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void hMSet(byte[] key, Map tuple) { String stringKey = RjcUtils.decode(key); Map stringTuple = RjcUtils.decodeMap(tuple); @@ -1965,7 +1842,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public List hVals(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1984,7 +1860,6 @@ public class RjcConnection implements RedisConnection { // // Pub/Sub functionality // - @Override public Long publish(byte[] channel, byte[] message) { try { if (isQueueing()) { @@ -1999,17 +1874,14 @@ public class RjcConnection implements RedisConnection { } } - @Override public Subscription getSubscription() { return subscription; } - @Override public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } - @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( @@ -2033,7 +1905,6 @@ public class RjcConnection implements RedisConnection { } } - @Override public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java index 5c149f107..aceaaf3ab 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java @@ -85,7 +85,6 @@ public class RjcConnectionFactory implements InitializingBean, DisposableBean, R } } - @Override public RedisConnection getConnection() { return postProcessConnection(new RjcConnection(dataSource.getConnection(), dbIndex)); } @@ -102,7 +101,6 @@ public class RjcConnectionFactory implements InitializingBean, DisposableBean, R return connection; } - @Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return RjcUtils.convertRjcAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java index c16a2040f..06f238ec7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java @@ -32,12 +32,10 @@ class RjcMessageListener implements MessageListener, PMessageListener { this.listener = messageListener; } - @Override public void onMessage(String channel, String message) { listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), null); } - @Override public void onMessage(String pattern, String channel, String message) { listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), RjcUtils.encode(pattern)); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java index db152b72c..0f9397eee 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java @@ -31,7 +31,6 @@ class SingleDataSource implements DataSource { this.connection = connection; } - @Override public RedisConnection getConnection() { return connection; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java index 6d20a8bf5..b9be9485b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java @@ -98,26 +98,22 @@ public abstract class AbstractSubscription implements Subscription { */ protected abstract void doClose(); - @Override public MessageListener getListener() { return listener; } - @Override public Collection getChannels() { synchronized (channels) { return clone(channels); } } - @Override public Collection getPatterns() { synchronized (patterns) { return clone(patterns); } } - @Override public void pSubscribe(byte[]... patterns) { checkPulse(); @@ -130,13 +126,11 @@ public abstract class AbstractSubscription implements Subscription { doPsubscribe(patterns); } - @Override public void pUnsubscribe() { pUnsubscribe((byte[][]) null); } - @Override public void subscribe(byte[]... channels) { checkPulse(); @@ -149,12 +143,10 @@ public abstract class AbstractSubscription implements Subscription { doSubscribe(channels); } - @Override public void unsubscribe() { unsubscribe((byte[][]) null); } - @Override public void pUnsubscribe(byte[]... patts) { if (!isAlive()) { return; @@ -184,7 +176,6 @@ public abstract class AbstractSubscription implements Subscription { } } - @Override public void unsubscribe(byte[]... chans) { if (!isAlive()) { return; @@ -214,7 +205,6 @@ public abstract class AbstractSubscription implements Subscription { } } - @Override public boolean isAlive() { return alive.get(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java index ccaeedfe4..bb7c26e3b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java @@ -41,7 +41,6 @@ abstract class AbstractOperations { this.key = key; } - @Override public final V doInRedis(RedisConnection connection) { byte[] result = inRedis(rawKey(key), connection); return deserializeValue(result); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java index c8e6a531e..c4bda0c69 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java @@ -41,72 +41,58 @@ class DefaultBoundHashOperations extends DefaultBoundKeyOperations this.ops = operations.opsForHash(); } - @Override public void delete(Object key) { ops.delete(getKey(), key); } - @Override public HV get(Object key) { return ops.get(getKey(), key); } - @Override public Collection multiGet(Collection hashKeys) { return ops.multiGet(getKey(), hashKeys); } - @Override public RedisOperations getOperations() { return ops.getOperations(); } - @Override public boolean hasKey(Object key) { return ops.hasKey(getKey(), key); } - @Override public Long increment(HK key, long delta) { return ops.increment(getKey(), key, delta); } - @Override public Set keys() { return ops.keys(getKey()); } - @Override public Long size() { return ops.size(getKey()); } - @Override public void putAll(Map m) { ops.putAll(getKey(), m); } - @Override public void put(HK key, HV value) { ops.put(getKey(), key, value); } - @Override public Boolean putIfAbsent(HK key, HV value) { return ops.putIfAbsent(getKey(), key, value); } - @Override public Collection values() { return ops.values(getKey()); } - @Override public Map entries() { return ops.entries(getKey()); } - @Override public DataType getType() { return DataType.HASH; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java index 105c6e48b..f0b59e444 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java @@ -35,7 +35,6 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { this.ops = operations; } - @Override public K getKey() { return key; } @@ -44,27 +43,22 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { this.key = key; } - @Override public Boolean expire(long timeout, TimeUnit unit) { return ops.expire(key, timeout, unit); } - @Override public Boolean expireAt(Date date) { return ops.expireAt(key, date); } - @Override public Long getExpire() { return ops.getExpire(key); } - @Override public Boolean persist() { return ops.persist(key); } - @Override public void rename(K newKey) { ops.rename(key, newKey); key = newKey; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java index 45a34511c..b8610cf7c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java @@ -42,92 +42,74 @@ class DefaultBoundListOperations extends DefaultBoundKeyOperations impl } - @Override public RedisOperations getOperations() { return ops.getOperations(); } - @Override public V index(long index) { return ops.index(getKey(), index); } - @Override public V leftPop() { return ops.leftPop(getKey()); } - @Override public V leftPop(long timeout, TimeUnit unit) { return ops.leftPop(getKey(), timeout, unit); } - @Override public Long leftPush(V value) { return ops.leftPush(getKey(), value); } - @Override public Long leftPushIfPresent(V value) { return ops.leftPushIfPresent(getKey(), value); } - @Override public Long leftPush(V pivot, V value) { return ops.leftPush(getKey(), pivot, value); } - @Override public Long size() { return ops.size(getKey()); } - @Override public List range(long start, long end) { return ops.range(getKey(), start, end); } - @Override public Long remove(long i, Object value) { return ops.remove(getKey(), i, value); } - @Override public V rightPop() { return ops.rightPop(getKey()); } - @Override public V rightPop(long timeout, TimeUnit unit) { return ops.rightPop(getKey(), timeout, unit); } - @Override public Long rightPushIfPresent(V value) { return ops.rightPushIfPresent(getKey(), value); } - @Override public Long rightPush(V value) { return ops.rightPush(getKey(), value); } - @Override public Long rightPush(V pivot, V value) { return ops.rightPush(getKey(), pivot, value); } - @Override public void trim(long start, long end) { ops.trim(getKey(), start, end); } - @Override public void set(long index, V value) { ops.set(getKey(), index, value); } - @Override public DataType getType() { return DataType.LIST; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java index d0010b63a..2ae41a5d5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java @@ -42,114 +42,92 @@ class DefaultBoundSetOperations extends DefaultBoundKeyOperations imple this.ops = operations.opsForSet(); } - @Override public Boolean add(V value) { return ops.add(getKey(), value); } - @Override public Set diff(K key) { return ops.difference(getKey(), key); } - @Override public Set diff(Collection keys) { return ops.difference(getKey(), keys); } - @Override public void diffAndStore(K key, K destKey) { ops.differenceAndStore(getKey(), key, destKey); } - @Override public void diffAndStore(Collection keys, K destKey) { ops.differenceAndStore(getKey(), keys, destKey); } - @Override public RedisOperations getOperations() { return ops.getOperations(); } - @Override public Set intersect(K key) { return ops.intersect(getKey(), key); } - @Override public Set intersect(Collection keys) { return ops.intersect(getKey(), keys); } - @Override public void intersectAndStore(K key, K destKey) { ops.intersectAndStore(getKey(), key, destKey); } - @Override public void intersectAndStore(Collection keys, K destKey) { ops.intersectAndStore(getKey(), keys, destKey); } - @Override public Boolean isMember(Object o) { return ops.isMember(getKey(), o); } - @Override public Set members() { return ops.members(getKey()); } - @Override public Boolean move(K destKey, V value) { return ops.move(getKey(), value, destKey); } - @Override public V randomMember() { return ops.randomMember(getKey()); } - @Override public Boolean remove(Object o) { return ops.remove(getKey(), o); } - @Override public V pop() { return ops.pop(getKey()); } - @Override public Long size() { return ops.size(getKey()); } - @Override public Set union(K key) { return ops.union(getKey(), key); } - @Override public Set union(Collection keys) { return ops.union(getKey(), keys); } - @Override public void unionAndStore(K key, K destKey) { ops.unionAndStore(getKey(), key, destKey); } - @Override public void unionAndStore(Collection keys, K destKey) { ops.unionAndStore(getKey(), keys, destKey); } - @Override public DataType getType() { return DataType.SET; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java index b9ec6b168..69a80fce6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java @@ -37,62 +37,50 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp this.ops = operations.opsForValue(); } - @Override public V get() { return ops.get(getKey()); } - @Override public V getAndSet(V value) { return ops.getAndSet(getKey(), value); } - @Override public Long increment(long delta) { return ops.increment(getKey(), delta); } - @Override public Integer append(String value) { return ops.append(getKey(), value); } - @Override public String get(long start, long end) { return ops.get(getKey(), start, end); } - @Override public void set(V value, long timeout, TimeUnit unit) { ops.set(getKey(), value, timeout, unit); } - @Override public void set(V value) { ops.set(getKey(), value); } - @Override public Boolean setIfAbsent(V value) { return ops.setIfAbsent(getKey(), value); } - @Override public void set(V value, long offset) { ops.set(getKey(), value, offset); } - @Override public Long size() { return ops.size(getKey()); } - @Override public RedisOperations getOperations() { return ops.getOperations(); } - @Override public DataType getType() { return DataType.STRING; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java index 71590d863..6adf9d4b6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java @@ -41,97 +41,78 @@ class DefaultBoundZSetOperations extends DefaultBoundKeyOperations impl this.ops = operations.opsForZSet(); } - @Override public Boolean add(V value, double score) { return ops.add(getKey(), value, score); } - @Override public Double incrementScore(V value, double delta) { return ops.incrementScore(getKey(), value, delta); } - @Override public RedisOperations getOperations() { return ops.getOperations(); } - @Override public void intersectAndStore(K destKey, K otherKey) { ops.intersectAndStore(getKey(), otherKey, destKey); } - @Override public void intersectAndStore(Collection otherKeys, K destKey) { ops.intersectAndStore(getKey(), otherKeys, destKey); } - @Override public Set range(long start, long end) { return ops.range(getKey(), start, end); } - @Override public Set rangeByScore(double min, double max) { return ops.rangeByScore(getKey(), min, max); } - @Override public Long rank(Object o) { return ops.rank(getKey(), o); } - @Override public Long reverseRank(Object o) { return ops.reverseRank(getKey(), o); } - @Override public Double score(Object o) { return ops.score(getKey(), o); } - @Override public Boolean remove(Object o) { return ops.remove(getKey(), o); } - @Override public void removeRange(long start, long end) { ops.removeRange(getKey(), start, end); } - @Override public void removeRangeByScore(double min, double max) { ops.removeRangeByScore(getKey(), min, max); } - @Override public Set reverseRange(long start, long end) { return ops.reverseRange(getKey(), start, end); } - @Override public Long count(double min, double max) { return ops.count(getKey(), min, max); } - @Override public Long size() { return ops.size(getKey()); } - @Override public void unionAndStore(K otherKey, K destKey) { ops.unionAndStore(getKey(), otherKey, destKey); } - @Override public void unionAndStore(Collection otherKeys, K destKey) { ops.unionAndStore(getKey(), otherKeys, destKey); } - @Override public DataType getType() { return DataType.ZSET; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java index afe1def4f..ab62fe1bf 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java @@ -37,13 +37,11 @@ class DefaultHashOperations extends AbstractOperations imp } @SuppressWarnings("unchecked") - @Override public HV get(K key, Object hashKey) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); byte[] rawHashValue = execute(new RedisCallback() { - @Override public byte[] doInRedis(RedisConnection connection) { return connection.hGet(rawKey, rawHashKey); } @@ -52,26 +50,22 @@ class DefaultHashOperations extends AbstractOperations imp return (HV) deserializeHashValue(rawHashValue); } - @Override public Boolean hasKey(K key, Object hashKey) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.hExists(rawKey, rawHashKey); } }, true); } - @Override public Long increment(K key, HK hashKey, final long delta) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.hIncrBy(rawKey, rawHashKey, delta); } @@ -79,12 +73,10 @@ class DefaultHashOperations extends AbstractOperations imp } - @Override public Set keys(K key) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { - @Override public Set doInRedis(RedisConnection connection) { return connection.hKeys(rawKey); } @@ -93,19 +85,16 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashKeys(rawValues); } - @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.hLen(rawKey); } }, true); } - @Override public void putAll(K key, Map m) { if (m.isEmpty()) { return; @@ -120,7 +109,6 @@ class DefaultHashOperations extends AbstractOperations imp } execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.hMSet(rawKey, hashes); return null; @@ -129,7 +117,6 @@ class DefaultHashOperations extends AbstractOperations imp } - @Override public Collection multiGet(K key, Collection fields) { if (fields.isEmpty()) { return Collections.emptyList(); @@ -145,7 +132,6 @@ class DefaultHashOperations extends AbstractOperations imp } List rawValues = execute(new RedisCallback>() { - @Override public List doInRedis(RedisConnection connection) { return connection.hMGet(rawKey, rawHashKeys); } @@ -154,14 +140,12 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashValues(rawValues); } - @Override 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() { - @Override public Object doInRedis(RedisConnection connection) { connection.hSet(rawKey, rawHashKey, rawHashValue); return null; @@ -169,14 +153,12 @@ class DefaultHashOperations extends AbstractOperations imp }, true); } - @Override 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() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.hSetNX(rawKey, rawHashKey, rawHashValue); } @@ -184,12 +166,10 @@ class DefaultHashOperations extends AbstractOperations imp } - @Override public List values(K key) { final byte[] rawKey = rawKey(key); List rawValues = execute(new RedisCallback>() { - @Override public List doInRedis(RedisConnection connection) { return connection.hVals(rawKey); } @@ -198,13 +178,11 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashValues(rawValues); } - @Override public void delete(K key, Object hashKey) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.hDel(rawKey, rawHashKey); return null; @@ -212,12 +190,10 @@ class DefaultHashOperations extends AbstractOperations imp }, true); } - @Override public Map entries(K key) { final byte[] rawKey = rawKey(key); Map entries = execute(new RedisCallback>() { - @Override public Map doInRedis(RedisConnection connection) { return connection.hGetAll(rawKey); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java index b6c67936f..7c397b4e9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java @@ -32,7 +32,6 @@ class DefaultListOperations extends AbstractOperations implements Li super(template); } - @Override public V index(K key, final long index) { return execute(new ValueDeserializingRedisCallback(key) { @Override @@ -42,7 +41,6 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - @Override public V leftPop(K key) { return execute(new ValueDeserializingRedisCallback(key) { @Override @@ -52,7 +50,6 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - @Override public V leftPop(K key, long timeout, TimeUnit unit) { final int tm = (int) unit.toSeconds(timeout); @@ -64,79 +61,65 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - @Override public Long leftPush(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.lPush(rawKey, rawValue); } }, true); } - @Override public Long leftPushIfPresent(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.lPushX(rawKey, rawValue); } }, true); } - @Override 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() { - @Override public Long doInRedis(RedisConnection connection) { return connection.lInsert(rawKey, Position.BEFORE, rawPivot, rawValue); } }, true); } - @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.lLen(rawKey); } }, true); } - @Override public List range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback>() { - @SuppressWarnings("unchecked") - @Override public List doInRedis(RedisConnection connection) { return deserializeValues(connection.lRange(rawKey, start, end)); } }, true); } - @Override public Long remove(K key, final long count, Object value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.lRem(rawKey, count, rawValue); } }, true); } - @Override public V rightPop(K key) { return execute(new ValueDeserializingRedisCallback(key) { @Override @@ -146,7 +129,6 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - @Override public V rightPop(K key, long timeout, TimeUnit unit) { final int tm = (int) unit.toSeconds(timeout); @@ -158,45 +140,38 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - @Override public Long rightPush(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.rPush(rawKey, rawValue); } }, true); } - @Override public Long rightPushIfPresent(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.rPushX(rawKey, rawValue); } }, true); } - @Override 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() { - @Override public Long doInRedis(RedisConnection connection) { return connection.lInsert(rawKey, Position.AFTER, rawPivot, rawValue); } }, true); } - @Override public V rightPopAndLeftPush(K sourceKey, K destinationKey) { final byte[] rawDestKey = rawKey(destinationKey); @@ -208,7 +183,6 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - @Override public V rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit) { final int tm = (int) unit.toSeconds(timeout); final byte[] rawDestKey = rawKey(destinationKey); @@ -221,7 +195,6 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - @Override public void set(K key, final long index, V value) { final byte[] rawValue = rawValue(value); execute(new ValueDeserializingRedisCallback(key) { @@ -233,7 +206,6 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } - @Override public void trim(K key, final long start, final long end) { execute(new ValueDeserializingRedisCallback(key) { @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java index a4893104f..845162d76 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java @@ -32,29 +32,23 @@ class DefaultSetOperations extends AbstractOperations implements Set super(template); } - @Override public Boolean add(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.sAdd(rawKey, rawValue); } }, true); } - @Override public Set difference(K key, K otherKey) { return difference(key, Collections.singleton(otherKey)); } - @SuppressWarnings("unchecked") - @Override public Set difference(final K key, final Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { - @Override public Set doInRedis(RedisConnection connection) { return connection.sDiff(rawKeys); } @@ -63,17 +57,14 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - @Override public void differenceAndStore(K key, K otherKey, K destKey) { differenceAndStore(key, Collections.singleton(otherKey), destKey); } - @Override public void differenceAndStore(final K key, final Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.sDiffStore(rawDestKey, rawKeys); return null; @@ -81,17 +72,13 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } - @Override public Set intersect(K key, K otherKey) { return intersect(key, Collections.singleton(otherKey)); } - @SuppressWarnings("unchecked") - @Override public Set intersect(K key, Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { - @Override public Set doInRedis(RedisConnection connection) { return connection.sInter(rawKeys); } @@ -100,17 +87,14 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - @Override public void intersectAndStore(K key, K otherKey, K destKey) { intersectAndStore(key, Collections.singleton(otherKey), destKey); } - @Override public void intersectAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.sInterStore(rawDestKey, rawKeys); return null; @@ -118,24 +102,19 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } - @Override public Boolean isMember(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.sIsMember(rawKey, rawValue); } }, true); } - @SuppressWarnings("unchecked") - @Override public Set members(K key) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { - @Override public Set doInRedis(RedisConnection connection) { return connection.sMembers(rawKey); } @@ -144,21 +123,18 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - @Override 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() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.sMove(rawKey, rawDestKey, rawValue); } }, true); } - @Override public V randomMember(K key) { return execute(new ValueDeserializingRedisCallback(key) { @@ -169,19 +145,16 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } - @Override public Boolean remove(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.sRem(rawKey, rawValue); } }, true); } - @Override public V pop(K key) { return execute(new ValueDeserializingRedisCallback(key) { @Override @@ -191,28 +164,22 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } - @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.sCard(rawKey); } }, true); } - @Override public Set union(K key, K otherKey) { return union(key, Collections.singleton(otherKey)); } - @SuppressWarnings("unchecked") - @Override public Set union(K key, Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { - @Override public Set doInRedis(RedisConnection connection) { return connection.sUnion(rawKeys); } @@ -221,17 +188,14 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } - @Override public void unionAndStore(K key, K otherKey, K destKey) { unionAndStore(key, Collections.singleton(otherKey), destKey); } - @Override public void unionAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.sUnionStore(rawDestKey, rawKeys); return null; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java index bc2c13d0d..3d162933d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java @@ -36,7 +36,6 @@ class DefaultValueOperations extends AbstractOperations implements V super(template); } - @Override public V get(final Object key) { return execute(new ValueDeserializingRedisCallback(key) { @@ -47,7 +46,6 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - @Override public V getAndSet(K key, V newValue) { final byte[] rawValue = rawValue(newValue); return execute(new ValueDeserializingRedisCallback(key) { @@ -58,12 +56,10 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - @Override public Long increment(K key, final long delta) { final byte[] rawKey = rawKey(key); // TODO add conversion service in here ? return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { if (delta == 1) { return connection.incr(rawKey); @@ -82,25 +78,21 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - @Override public Integer append(K key, String value) { final byte[] rawKey = rawKey(key); final byte[] rawString = rawString(value); return execute(new RedisCallback() { - @Override public Integer doInRedis(RedisConnection connection) { return connection.append(rawKey, rawString).intValue(); } }, true); } - @Override public String get(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); byte[] rawReturn = execute(new RedisCallback() { - @Override public byte[] doInRedis(RedisConnection connection) { return connection.getRange(rawKey, start, end); } @@ -109,8 +101,6 @@ class DefaultValueOperations extends AbstractOperations implements V return deserializeString(rawReturn); } - @SuppressWarnings("unchecked") - @Override public List multiGet(Collection keys) { if (keys.isEmpty()) { return Collections.emptyList(); @@ -124,7 +114,6 @@ class DefaultValueOperations extends AbstractOperations implements V } List rawValues = execute(new RedisCallback>() { - @Override public List doInRedis(RedisConnection connection) { return connection.mGet(rawKeys); } @@ -133,7 +122,6 @@ class DefaultValueOperations extends AbstractOperations implements V return deserializeValues(rawValues); } - @Override public void multiSet(Map m) { if (m.isEmpty()) { return; @@ -146,7 +134,6 @@ class DefaultValueOperations extends AbstractOperations implements V } execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.mSet(rawKeys); return null; @@ -154,7 +141,6 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - @Override public void multiSetIfAbsent(Map m) { if (m.isEmpty()) { return; @@ -167,7 +153,6 @@ class DefaultValueOperations extends AbstractOperations implements V } execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.mSetNX(rawKeys); return null; @@ -175,7 +160,6 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - @Override public void set(K key, V value) { final byte[] rawValue = rawValue(value); execute(new ValueDeserializingRedisCallback(key) { @@ -187,14 +171,12 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - @Override public void set(K key, V value, long timeout, TimeUnit unit) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); final long rawTimeout = unit.toSeconds(timeout); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.setEx(rawKey, (int) rawTimeout, rawValue); return null; @@ -202,13 +184,11 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - @Override public Boolean setIfAbsent(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) throws DataAccessException { return connection.setNX(rawKey, rawValue); } @@ -216,13 +196,11 @@ class DefaultValueOperations extends AbstractOperations implements V } - @Override public void set(K key, final V value, final long offset) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.setRange(rawKey, rawValue, offset); return null; @@ -230,12 +208,10 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } - @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.strLen(rawKey); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java index 154163fe7..b1f96af0c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java @@ -32,43 +32,36 @@ class DefaultZSetOperations extends AbstractOperations implements ZS super(template); } - @Override public Boolean add(final K key, final V value, final double score) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.zAdd(rawKey, score, rawValue); } }, true); } - @Override public Double incrementScore(K key, V value, final double delta) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { - @Override public Double doInRedis(RedisConnection connection) { return connection.zIncrBy(rawKey, delta, rawValue); } }, true); } - @Override public void intersectAndStore(K key, K otherKey, K destKey) { intersectAndStore(key, Collections.singleton(otherKey), destKey); } - @Override public void intersectAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.zInterStore(rawDestKey, rawKeys); return null; @@ -76,13 +69,10 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - @SuppressWarnings("unchecked") - @Override public Set range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { - @Override public Set doInRedis(RedisConnection connection) { return connection.zRange(rawKey, start, end); } @@ -91,13 +81,10 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } - @SuppressWarnings("unchecked") - @Override public Set rangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { - @Override public Set doInRedis(RedisConnection connection) { return connection.zRangeByScore(rawKey, min, max); } @@ -106,13 +93,11 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } - @Override public Long rank(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { Long zRank = connection.zRank(rawKey, rawValue); return (zRank != null && zRank.longValue() >= 0 ? zRank : null); @@ -120,13 +105,11 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - @Override public Long reverseRank(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { Long zRank = connection.zRevRank(rawKey, rawValue); return (zRank != null && zRank.longValue() >= 0 ? zRank : null); @@ -134,24 +117,20 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - @Override public Boolean remove(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.zRem(rawKey, rawValue); } }, true); } - @Override public void removeRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.zRemRange(rawKey, start, end); return null; @@ -159,11 +138,9 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - @Override public void removeRangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.zRemRangeByScore(rawKey, min, max); return null; @@ -171,13 +148,10 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } - @SuppressWarnings("unchecked") - @Override public Set reverseRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { - @Override public Set doInRedis(RedisConnection connection) { return connection.zRevRange(rawKey, start, end); } @@ -186,54 +160,45 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } - @Override public Double score(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { - @Override public Double doInRedis(RedisConnection connection) { return connection.zScore(rawKey, rawValue); } }, true); } - @Override public Long count(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.zCount(rawKey, min, max); } }, true); } - @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return connection.zCard(rawKey); } }, true); } - @Override public void unionAndStore(K key, K otherKey, K destKey) { unionAndStore(key, Collections.singleton(otherKey), destKey); } - @Override public void unionAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.zUnionStore(rawDestKey, rawKeys); return null; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisConnectionUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisConnectionUtils.java index b0799b82a..9778c81d9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisConnectionUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisConnectionUtils.java @@ -173,7 +173,6 @@ public abstract class RedisConnectionUtils { this.conn = conn; } - @Override public boolean isVoid() { return isVoid; } @@ -182,12 +181,10 @@ public abstract class RedisConnectionUtils { return conn; } - @Override public void reset() { // no-op } - @Override public void unbound() { this.isVoid = true; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index d3565d996..fc0cd8c2a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -133,7 +133,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation zSetOps = new DefaultZSetOperations(this); } - @Override public T execute(RedisCallback action) { return execute(action, isExposeConnection()); } @@ -192,7 +191,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } - @Override public T execute(SessionCallback session) { RedisConnectionFactory factory = getConnectionFactory(); // bind connection @@ -425,23 +423,19 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // // RedisOperations // - @Override public List exec() { return execute(new RedisCallback>() { - @Override public List doInRedis(RedisConnection connection) throws DataAccessException { return connection.exec(); } }); } - @Override public void delete(K key) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.del(rawKey); return null; @@ -449,12 +443,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override public void delete(Collection keys) { final byte[][] rawKeys = rawKeys(keys); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.del(rawKeys); return null; @@ -462,45 +454,38 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override public Boolean hasKey(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.exists(rawKey); } }, true); } - @Override public Boolean expire(K key, long timeout, TimeUnit unit) { final byte[] rawKey = rawKey(key); final int rawTimeout = (int) unit.toSeconds(timeout); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.expire(rawKey, rawTimeout); } }, true); } - @Override public Boolean expireAt(K key, Date date) { final byte[] rawKey = rawKey(key); final long rawTimeout = date.getTime(); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.expireAt(rawKey, rawTimeout); } }, true); } - @Override public void convertAndSend(String channel, Object message) { Assert.hasText(channel, "a non-empty channel is required"); @@ -508,7 +493,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation final byte[] rawMessage = rawValue(message); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.publish(rawChannel, rawMessage); return null; @@ -521,12 +505,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // Value operations // - @Override public Long getExpire(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) { return Long.valueOf(connection.ttl(rawKey)); } @@ -534,12 +516,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @SuppressWarnings("unchecked") - @Override public Set keys(K pattern) { final byte[] rawKey = rawKey(pattern); Collection rawKeys = execute(new RedisCallback>() { - @Override public Collection doInRedis(RedisConnection connection) { return connection.keys(rawKey); } @@ -548,34 +528,28 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return (Set) SerializationUtils.deserialize(rawKeys, keySerializer); } - @Override public Boolean persist(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.persist(rawKey); } }, true); } - @Override public Boolean move(K key, final int dbIndex) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.move(rawKey, dbIndex); } }, true); } - @Override public K randomKey() { byte[] rawKey = execute(new RedisCallback() { - @Override public byte[] doInRedis(RedisConnection connection) { return connection.randomKey(); } @@ -584,13 +558,11 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return deserializeKey(rawKey); } - @Override public void rename(K oldKey, K newKey) { final byte[] rawOldKey = rawKey(oldKey); final byte[] rawNewKey = rawKey(newKey); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.rename(rawOldKey, rawNewKey); return null; @@ -598,35 +570,29 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override public Boolean renameIfAbsent(K oldKey, K newKey) { final byte[] rawOldKey = rawKey(oldKey); final byte[] rawNewKey = rawKey(newKey); return execute(new RedisCallback() { - @Override public Boolean doInRedis(RedisConnection connection) { return connection.renameNX(rawOldKey, rawNewKey); } }, true); } - @Override public DataType type(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { - @Override public DataType doInRedis(RedisConnection connection) { return connection.type(rawKey); } }, true); } - @Override public void multi() { execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.multi(); return null; @@ -634,11 +600,9 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override public void discard() { execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.discard(); return null; @@ -646,12 +610,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override public void watch(K key) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.watch(rawKey); return null; @@ -659,12 +621,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override public void watch(Collection keys) { final byte[][] rawKeys = rawKeys(keys); execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) { connection.watch(rawKeys); return null; @@ -672,10 +632,8 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } - @Override public void unwatch() { execute(new RedisCallback() { - @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.unwatch(); return null; @@ -686,18 +644,15 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // Sort operations @SuppressWarnings("unchecked") - @Override public List sort(SortQuery query) { return sort(query, valueSerializer); } - @Override public List sort(SortQuery query, RedisSerializer resultSerializer) { final byte[] rawKey = rawKey(query.getKey()); final SortParameters params = QueryUtils.convertQuery(query, stringSerializer); List vals = execute(new RedisCallback>() { - @Override public List doInRedis(RedisConnection connection) throws DataAccessException { return connection.sort(rawKey, params); } @@ -707,12 +662,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @SuppressWarnings("unchecked") - @Override public List sort(SortQuery query, BulkMapper bulkMapper) { return sort(query, bulkMapper, valueSerializer); } - @Override public List sort(SortQuery query, BulkMapper bulkMapper, RedisSerializer resultSerializer) { List values = sort(query, resultSerializer); @@ -733,66 +686,54 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return result; } - @Override public Long sort(SortQuery query, K storeKey) { final byte[] rawStoreKey = rawKey(storeKey); final byte[] rawKey = rawKey(query.getKey()); final SortParameters params = QueryUtils.convertQuery(query, stringSerializer); return execute(new RedisCallback() { - @Override public Long doInRedis(RedisConnection connection) throws DataAccessException { return connection.sort(rawKey, params, rawStoreKey); } }, true); } - @Override public BoundValueOperations boundValueOps(K key) { return new DefaultBoundValueOperations(key, this); } - @Override public ValueOperations opsForValue() { return valueOps; } - @Override public ListOperations opsForList() { return listOps; } - @Override public BoundListOperations boundListOps(K key) { return new DefaultBoundListOperations(key, this); } - @Override public BoundSetOperations boundSetOps(K key) { return new DefaultBoundSetOperations(key, this); } - @Override public SetOperations opsForSet() { return setOps; } - @Override public BoundZSetOperations boundZSetOps(K key) { return new DefaultBoundZSetOperations(key, this); } - @Override public ZSetOperations opsForZSet() { return zSetOps; } - @Override public BoundHashOperations boundHashOps(K key) { return new DefaultBoundHashOperations(key, this); } - @Override public HashOperations opsForHash() { return new DefaultHashOperations(this); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortCriterion.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortCriterion.java index 242a7af6e..89ee8a58b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortCriterion.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortCriterion.java @@ -40,36 +40,30 @@ class DefaultSortCriterion implements SortCriterion { this.key = key; } - @Override public SortCriterion alphabetical(boolean alpha) { this.alpha = Boolean.valueOf(alpha); return this; } - @Override public SortQuery build() { return new DefaultSortQuery(key, by, limit, order, alpha, getKeys); } - @Override public SortCriterion limit(long offset, long count) { this.limit = new Range(offset, count); return this; } - @Override public SortCriterion limit(Range range) { this.limit = range; return this; } - @Override public SortCriterion order(Order order) { this.order = order; return this; } - @Override public SortCriterion get(String getPattern) { this.getKeys.add(getPattern); return this; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortQuery.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortQuery.java index 4348e2fa2..df78766ce 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortQuery.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortQuery.java @@ -43,32 +43,26 @@ class DefaultSortQuery implements SortQuery { this.gets = gets; } - @Override public String getBy() { return by; } - @Override public Range getLimit() { return limit; } - @Override public Order getOrder() { return order; } - @Override public Boolean isAlphabetic() { return alpha; } - @Override public K getKey() { return key; } - @Override public List getGetPattern() { return gets; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/BeanUtilsHashMapper.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/BeanUtilsHashMapper.java index 1283eb26e..7d6dcdc32 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/BeanUtilsHashMapper.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/BeanUtilsHashMapper.java @@ -32,7 +32,6 @@ public class BeanUtilsHashMapper implements HashMapper { this.type = type; } - @Override 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; } - @Override public Map toHash(T object) { try { return BeanUtils.describe(object); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/DecoratingStringHashMapper.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/DecoratingStringHashMapper.java index 378203134..15867a059 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/DecoratingStringHashMapper.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/DecoratingStringHashMapper.java @@ -33,13 +33,11 @@ public class DecoratingStringHashMapper implements HashMapper hash) { Map h = hash; return delegate.fromHash(h); } - @Override public Map toHash(T object) { Map hash = delegate.toHash(object); Map flatten = new LinkedHashMap(hash.size()); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java index 1f4d0d105..07fd112b8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java @@ -42,12 +42,10 @@ public class JacksonHashMapper implements HashMapper { } @SuppressWarnings("unchecked") - @Override public T fromHash(Map hash) { return (T) mapper.convertValue(hash, userType); } - @Override public Map toHash(T object) { return mapper.convertValue(object, mapType); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java index 0691b8363..6905bf532 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java @@ -110,7 +110,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private volatile RedisSerializer serializer = new StringRedisSerializer(); - @Override public void afterPropertiesSet() { if (taskExecutor == null) { manageExecutor = true; @@ -137,7 +136,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab return new SimpleAsyncTaskExecutor(threadNamePrefix); } - @Override public void destroy() throws Exception { initialized = false; @@ -154,29 +152,24 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } - @Override public boolean isAutoStartup() { return true; } - @Override public void stop(Runnable callback) { stop(); callback.run(); } - @Override public int getPhase() { // start the latest return Integer.MAX_VALUE; } - @Override public boolean isRunning() { return running; } - @Override public void start() { if (!running) { running = true; @@ -198,7 +191,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } - @Override public void stop() { if (isRunning()) { running = false; @@ -301,7 +293,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab this.connectionFactory = connectionFactory; } - @Override public void setBeanName(String name) { this.beanName = name; } @@ -510,12 +501,10 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private long WAIT = 500; private long ROUNDS = 3; - @Override public boolean isLongLived() { return false; } - @Override public void run() { // wait for subscription to be initialized boolean done = false; @@ -543,12 +532,10 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private volatile RedisConnection connection; private final Object localMonitor = new Object(); - @Override public boolean isLongLived() { return true; } - @Override public void run() { connection = connectionFactory.getConnection(); try { @@ -695,7 +682,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab */ private class DispatchMessageListener implements MessageListener { - @Override public void onMessage(Message message, byte[] pattern) { // do channel matching first byte[] channel = message.getChannel(); @@ -720,7 +706,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private void dispatchChannels(Collection ch, final Message message) { for (final MessageListener messageListener : ch) { taskExecutor.execute(new Runnable() { - @Override public void run() { processMessage(messageListener, message, null); } @@ -731,7 +716,6 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private void dispatchPatterns(Collection pt, final Message message, final byte[] pattern) { for (final MessageListener messageListener : pt) { taskExecutor.execute(new Runnable() { - @Override public void run() { processMessage(messageListener, message, pattern.clone()); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java index 8def8aa52..3c30f340a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java @@ -23,7 +23,6 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.keyvalue.redis.connection.Message; import org.springframework.data.keyvalue.redis.connection.MessageListener; -import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; import org.springframework.util.Assert; @@ -166,8 +165,6 @@ public class MessageListenerAdapter implements MessageListener { * @param message the incoming Redis message * @see #handleListenerException */ - @Override - @SuppressWarnings("unchecked") public void onMessage(Message message, byte[] pattern) { try { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java index b53387366..f3c5590b2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java @@ -64,7 +64,6 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac converter = new Converter(typeConverter); } - @Override public T deserialize(byte[] bytes) { if (bytes == null) { return null; @@ -74,7 +73,6 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac return converter.convert(string, type); } - @Override public byte[] serialize(T object) { if (object == null) { return null; @@ -83,7 +81,6 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac return string.getBytes(charset); } - @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (converter == null && beanFactory instanceof ConfigurableBeanFactory) { ConfigurableBeanFactory cFB = (ConfigurableBeanFactory) beanFactory; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java index c858cfcb2..8a7023805 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java @@ -44,7 +44,6 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { } @SuppressWarnings("unchecked") - @Override public T deserialize(byte[] bytes) throws SerializationException { if (SerializationUtils.isEmpty(bytes)) { return null; @@ -56,7 +55,6 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { } } - @Override public byte[] serialize(Object t) throws SerializationException { if (t == null) { return SerializationUtils.EMPTY_ARRAY; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java index fe6de7886..3c0c78626 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java @@ -32,7 +32,6 @@ public class JdkSerializationRedisSerializer implements RedisSerializer private Converter deserializer = new DeserializingConverter(); @SuppressWarnings("unchecked") - @Override public Object deserialize(byte[] bytes) { if (SerializationUtils.isEmpty(bytes)) { return null; @@ -45,7 +44,6 @@ public class JdkSerializationRedisSerializer implements RedisSerializer } } - @Override public byte[] serialize(Object object) { if (object == null) { return SerializationUtils.EMPTY_ARRAY; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java index b1a2354f8..5e6b7f1f4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java @@ -50,7 +50,6 @@ public class OxmSerializer implements InitializingBean, RedisSerializer afterPropertiesSet(); } - @Override public void afterPropertiesSet() { Assert.notNull(marshaller, "non-null marshaller required"); Assert.notNull(unmarshaller, "non-null unmarshaller required"); @@ -70,7 +69,6 @@ public class OxmSerializer implements InitializingBean, RedisSerializer this.unmarshaller = unmarshaller; } - @Override public Object deserialize(byte[] bytes) throws SerializationException { if (SerializationUtils.isEmpty(bytes)) { return null; @@ -83,7 +81,6 @@ public class OxmSerializer implements InitializingBean, RedisSerializer } } - @Override public byte[] serialize(Object t) throws SerializationException { if (t == null) { return SerializationUtils.EMPTY_ARRAY; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java index d0b361ba1..e5edff977 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java @@ -42,12 +42,10 @@ public class StringRedisSerializer implements RedisSerializer { this.charset = charset; } - @Override public String deserialize(byte[] bytes) { return (bytes == null ? null : new String(bytes, charset)); } - @Override public byte[] serialize(String string) { return (string == null ? null : string.getBytes(charset)); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index bb4b19ba4..b54e93b1d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -162,7 +162,6 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey return generalOps.execute(new SessionCallback() { @SuppressWarnings("unchecked") - @Override public Boolean execute(RedisOperations operations) { for (;;) { operations.watch(Collections.singleton(key)); @@ -239,59 +238,57 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey * Returns the String representation of the current value. * @return the String representation of the current value. */ + @Override public String toString() { return Integer.toString(get()); } + @Override public int intValue() { return get(); } + @Override public long longValue() { - return (long) get(); - } - - public float floatValue() { - return (float) get(); - } - - public double doubleValue() { - return (double) get(); + return get(); } @Override + public float floatValue() { + return get(); + } + + @Override + public double doubleValue() { + return get(); + } + public String getKey() { return key; } - @Override public Boolean expire(long timeout, TimeUnit unit) { return generalOps.expire(key, timeout, unit); } - @Override public Boolean expireAt(Date date) { return generalOps.expireAt(key, date); } - @Override public Long getExpire() { return generalOps.getExpire(key); } - @Override public Boolean persist() { return generalOps.persist(key); } - @Override public void rename(String newKey) { generalOps.rename(key, newKey); key = newKey; } - @Override public DataType getType() { return DataType.STRING; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 5550b382d..815aed698 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -162,7 +162,6 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe return generalOps.execute(new SessionCallback() { @SuppressWarnings("unchecked") - @Override public Boolean execute(RedisOperations operations) { for (;;) { operations.watch(Collections.singleton(key)); @@ -242,59 +241,57 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe * * @return the String representation of the current value. */ + @Override public String toString() { return Long.toString(get()); } + @Override public int intValue() { return (int) get(); } + @Override public long longValue() { return get(); } + @Override public float floatValue() { - return (float) get(); - } - - public double doubleValue() { - return (double) get(); + return get(); } @Override + public double doubleValue() { + return get(); + } + public String getKey() { return key; } - @Override public Boolean expire(long timeout, TimeUnit unit) { return generalOps.expire(key, timeout, unit); } - @Override public Boolean expireAt(Date date) { return generalOps.expireAt(key, date); } - @Override public Long getExpire() { return generalOps.getExpire(key); } - @Override public Boolean persist() { return generalOps.persist(key); } - @Override public void rename(String newKey) { generalOps.rename(key, newKey); key = newKey; } - @Override public DataType getType() { return DataType.STRING; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java index cb7c0c5df..5d19e2fe6 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java @@ -40,12 +40,10 @@ public abstract class AbstractRedisCollection extends AbstractCollection i this.operations = operations; } - @Override public String getKey() { return key; } - @Override public RedisOperations getOperations() { return operations; } @@ -59,8 +57,10 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return modified; } + @Override public abstract boolean add(E e); + @Override public abstract void clear(); @Override @@ -72,6 +72,7 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return contains; } + @Override public abstract boolean remove(Object o); @@ -84,6 +85,7 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return modified; } + @Override public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } @@ -119,27 +121,22 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return sb.toString(); } - @Override public Boolean expire(long timeout, TimeUnit unit) { return operations.expire(key, timeout, unit); } - @Override public Boolean expireAt(Date date) { return operations.expireAt(key, date); } - @Override public Long getExpire() { return operations.getExpire(key); } - @Override public Boolean persist() { return operations.persist(key); } - @Override public void rename(final String newKey) { CollectionUtils.rename(key, newKey, operations); key = newKey; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java index e98c8287a..047a675b2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java @@ -56,7 +56,6 @@ abstract class CollectionUtils { static void rename(final K key, final K newKey, RedisOperations operations) { operations.execute(new SessionCallback() { @SuppressWarnings("unchecked") - @Override public Object execute(RedisOperations operations) throws DataAccessException { do { operations.watch(key); @@ -76,7 +75,6 @@ abstract class CollectionUtils { static Boolean renameIfAbsent(final K key, final K newKey, RedisOperations operations) { return operations.execute(new SessionCallback() { - @Override public Boolean execute(RedisOperations operations) throws DataAccessException { List exec = null; do { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java index 6149838c4..ba1697ff2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java @@ -47,8 +47,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R private volatile boolean capped = false; - private volatile long defaultWait = 0; - private class DefaultRedisListIterator extends RedisIterator { public DefaultRedisListIterator(Iterator delegate) { @@ -102,12 +100,10 @@ public class DefaultRedisList extends AbstractRedisCollection implements R capped = (maxSize > 0); } - @Override public List range(long start, long end) { return listOps.range(start, end); } - @Override public RedisList trim(int start, int end) { listOps.trim(start, end); return this; @@ -153,7 +149,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return (result != null && result.longValue() > 0); } - @Override public void add(int index, E element) { if (index == 0) { listOps.leftPush(element); @@ -176,7 +171,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R throw new IllegalArgumentException("Redis supports insertion only at the beginning or the end of the list"); } - @Override public boolean addAll(int index, Collection c) { // insert collection in reverse if (index == 0) { @@ -206,7 +200,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R throw new IllegalArgumentException("Redis supports insertion only at the beginning or the end of the list"); } - @Override public E get(int index) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException(); @@ -214,40 +207,33 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return listOps.index(index); } - @Override public int indexOf(Object o) { throw new UnsupportedOperationException(); } - @Override public int lastIndexOf(Object o) { throw new UnsupportedOperationException(); } - @Override public ListIterator listIterator() { throw new UnsupportedOperationException(); } - @Override public ListIterator listIterator(int index) { throw new UnsupportedOperationException(); } - @Override public E remove(int index) { throw new UnsupportedOperationException(); } - @Override public E set(int index, E e) { E object = get(index); listOps.set(index, e); return object; } - @Override public List subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException(); } @@ -256,7 +242,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // Queue methods // - @Override public E element() { E value = peek(); if (value == null) @@ -266,7 +251,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R } - @Override public boolean offer(E e) { listOps.rightPush(e); cap(); @@ -274,19 +258,16 @@ public class DefaultRedisList extends AbstractRedisCollection implements R } - @Override public E peek() { return listOps.index(0); } - @Override public E poll() { return listOps.leftPop(); } - @Override public E remove() { E value = poll(); if (value == null) @@ -299,30 +280,25 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // Dequeue // - @Override public void addFirst(E e) { listOps.leftPush(e); cap(); } - @Override public void addLast(E e) { add(e); } - @Override public Iterator descendingIterator() { List content = content(); Collections.reverse(content); return new DefaultRedisListIterator(content.iterator()); } - @Override public E getFirst() { return element(); } - @Override public E getLast() { E e = peekLast(); if (e == null) { @@ -331,39 +307,32 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } - @Override public boolean offerFirst(E e) { addFirst(e); return true; } - @Override public boolean offerLast(E e) { addLast(e); return true; } - @Override public E peekFirst() { return peek(); } - @Override public E peekLast() { return listOps.index(-1); } - @Override public E pollFirst() { return poll(); } - @Override public E pollLast() { return listOps.rightPop(); } - @Override public E pop() { E e = poll(); if (e == null) { @@ -372,22 +341,18 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } - @Override public void push(E e) { addFirst(e); } - @Override public E removeFirst() { return pop(); } - @Override public boolean removeFirstOccurrence(Object o) { return remove(o); } - @Override public E removeLast() { E e = pollLast(); if (e == null) { @@ -396,7 +361,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } - @Override public boolean removeLastOccurrence(Object o) { Long result = listOps.remove(-1, o); return (result != null && result.longValue() > 0); @@ -407,7 +371,6 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // BlockingQueue // - @Override public int drainTo(Collection c, int maxElements) { if (this.equals(c)) { throw new IllegalArgumentException("Cannot drain a queue to itself"); @@ -423,33 +386,27 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return loop; } - @Override public int drainTo(Collection c) { return drainTo(c, size()); } - @Override public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { return offer(e); } - @Override public E poll(long timeout, TimeUnit unit) throws InterruptedException { E element = listOps.leftPop(timeout, unit); return (element == null ? null : element); } - @Override public void put(E e) throws InterruptedException { offer(e); } - @Override public int remainingCapacity() { return Integer.MAX_VALUE; } - @Override public E take() throws InterruptedException { return poll(0, TimeUnit.SECONDS); } @@ -459,48 +416,39 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // BlockingDeque // - @Override public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { return offerFirst(e); } - @Override public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { return offerLast(e); } - @Override public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException { return poll(timeout, unit); } - @Override public E pollLast(long timeout, TimeUnit unit) throws InterruptedException { E element = listOps.rightPop(timeout, unit); return (element == null ? null : element); } - @Override public void putFirst(E e) throws InterruptedException { add(e); } - @Override public void putLast(E e) throws InterruptedException { put(e); } - @Override public E takeFirst() throws InterruptedException { return take(); } - @Override public E takeLast() throws InterruptedException { return pollLast(0, TimeUnit.SECONDS); } - @Override public DataType getType() { return DataType.LIST; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java index 291b6b00c..1de1e811f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java @@ -47,17 +47,14 @@ public class DefaultRedisMap implements RedisMap { this.value = value; } - @Override public K getKey() { return key; } - @Override public V getValue() { return value; } - @Override public V setValue(V value) { throw new UnsupportedOperationException(); } @@ -82,32 +79,26 @@ public class DefaultRedisMap implements RedisMap { this.hashOps = boundOps; } - @Override public Long increment(K key, long delta) { return hashOps.increment(key, delta); } - @Override public RedisOperations getOperations() { return hashOps.getOperations(); } - @Override public void clear() { getOperations().delete(Collections.singleton(getKey())); } - @Override public boolean containsKey(Object key) { return hashOps.hasKey(key); } - @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException(); } - @Override public Set> entrySet() { Set keySet = keySet(); Collection multiGet = hashOps.multiGet(keySet); @@ -123,46 +114,38 @@ public class DefaultRedisMap implements RedisMap { return entries; } - @Override public V get(Object key) { return hashOps.get(key); } - @Override public boolean isEmpty() { return size() == 0; } - @Override public Set keySet() { return hashOps.keys(); } - @Override public V put(K key, V value) { V oldV = get(key); hashOps.put(key, value); return oldV; } - @Override public void putAll(Map m) { hashOps.putAll(m); } - @Override public V remove(Object key) { V v = get(key); hashOps.delete(key); return v; } - @Override public int size() { return hashOps.size().intValue(); } - @Override public Collection values() { return hashOps.values(); } @@ -194,7 +177,6 @@ public class DefaultRedisMap implements RedisMap { return sb.toString(); } - @Override public V putIfAbsent(K key, V value) { throw new UnsupportedOperationException(); @@ -216,7 +198,6 @@ public class DefaultRedisMap implements RedisMap { // } } - @Override public boolean remove(Object key, Object value) { throw new UnsupportedOperationException(); @@ -242,7 +223,6 @@ public class DefaultRedisMap implements RedisMap { // } } - @Override public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); @@ -268,7 +248,6 @@ public class DefaultRedisMap implements RedisMap { // } } - @Override public V replace(K key, V value) { throw new UnsupportedOperationException(); @@ -294,38 +273,31 @@ public class DefaultRedisMap implements RedisMap { // } } - @Override public Boolean expire(long timeout, TimeUnit unit) { return hashOps.expire(timeout, unit); } - @Override public Boolean expireAt(Date date) { return hashOps.expireAt(date); } - @Override public Long getExpire() { return hashOps.getExpire(); } - @Override public Boolean persist() { return hashOps.persist(); } - @Override public String getKey() { return hashOps.getKey(); } - @Override public void rename(String newKey) { hashOps.rename(newKey); } - @Override public DataType getType() { return hashOps.getType(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java index 368d7c204..ac119798c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java @@ -68,68 +68,56 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re } - @Override public Set diff(RedisSet set) { return boundSetOps.diff(set.getKey()); } - @Override public Set diff(Collection> sets) { return boundSetOps.diff(CollectionUtils.extractKeys(sets)); } - @Override public RedisSet diffAndStore(RedisSet set, String destKey) { boundSetOps.diffAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - @Override public RedisSet diffAndStore(Collection> sets, String destKey) { boundSetOps.diffAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - @Override public Set intersect(RedisSet set) { return boundSetOps.intersect(set.getKey()); } - @Override public Set intersect(Collection> sets) { return boundSetOps.intersect(CollectionUtils.extractKeys(sets)); } - @Override public RedisSet intersectAndStore(RedisSet set, String destKey) { boundSetOps.intersectAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - @Override public RedisSet intersectAndStore(Collection> sets, String destKey) { boundSetOps.intersectAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - @Override public Set union(RedisSet set) { return boundSetOps.union(set.getKey()); } - @Override public Set union(Collection> sets) { return boundSetOps.union(CollectionUtils.extractKeys(sets)); } - @Override public RedisSet unionAndStore(RedisSet set, String destKey) { boundSetOps.unionAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } - @Override public RedisSet unionAndStore(Collection> sets, String destKey) { boundSetOps.unionAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); @@ -168,8 +156,7 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re return boundSetOps.size().intValue(); } - @Override public DataType getType() { return DataType.SET; } -} \ No newline at end of file +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java index 4794aae99..2a2faacc4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java @@ -91,52 +91,43 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R this.defaultScore = defaultScore; } - @Override public RedisZSet intersectAndStore(RedisZSet set, String destKey) { boundZSetOps.intersectAndStore(set.getKey(), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } - @Override public RedisZSet intersectAndStore(Collection> sets, String destKey) { boundZSetOps.intersectAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } - @Override public Set range(long start, long end) { return boundZSetOps.range(start, end); } - @Override public Set reverseRange(long start, long end) { return boundZSetOps.reverseRange(start, end); } - @Override public Set rangeByScore(double min, double max) { return boundZSetOps.rangeByScore(min, max); } - @Override public RedisZSet remove(long start, long end) { boundZSetOps.removeRange(start, end); return this; } - @Override public RedisZSet removeByScore(double min, double max) { boundZSetOps.removeRangeByScore(min, max); return this; } - @Override public RedisZSet unionAndStore(RedisZSet set, String destKey) { boundZSetOps.unionAndStore(set.getKey(), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } - @Override public RedisZSet unionAndStore(Collection> sets, String destKey) { boundZSetOps.unionAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); @@ -147,7 +138,6 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R return add(e, getDefaultScore()); } - @Override public boolean add(E e, double score) { return boundZSetOps.add(e, score); } @@ -177,12 +167,10 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R return boundZSetOps.size().intValue(); } - @Override public Double getDefaultScore() { return defaultScore; } - @Override public E first() { Iterator iterator = boundZSetOps.range(0, 0).iterator(); if (iterator.hasNext()) @@ -190,7 +178,6 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R throw new NoSuchElementException(); } - @Override public E last() { Iterator iterator = boundZSetOps.reverseRange(0, 0).iterator(); if (iterator.hasNext()) @@ -198,22 +185,18 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R throw new NoSuchElementException(); } - @Override public Long rank(Object o) { return boundZSetOps.rank(o); } - @Override public Long reverseRank(Object o) { return boundZSetOps.reverseRank(o); } - @Override public Double score(Object o) { return boundZSetOps.score(o); } - @Override public DataType getType() { return DataType.ZSET; } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/config/StubErrorHandler.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/config/StubErrorHandler.java index a9f83609d..e5e8244e9 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/config/StubErrorHandler.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/config/StubErrorHandler.java @@ -27,9 +27,7 @@ public class StubErrorHandler implements ErrorHandler { public BlockingDeque throwables = new LinkedBlockingDeque(); - @Override public void handleError(Throwable t) { throwables.add(t); } - } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index 875d65b79..ddb1c6db9 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -196,7 +196,6 @@ public abstract class AbstractConnectionIntegrationTests { final BlockingDeque queue = new LinkedBlockingDeque(); final MessageListener ml = new MessageListener() { - @Override public void onMessage(Message message, byte[] pattern) { queue.add(message); System.out.println("received message"); @@ -212,13 +211,12 @@ public abstract class AbstractConnectionIntegrationTests { final AtomicBoolean flag = new AtomicBoolean(true); Runnable listener = new Runnable() { - @Override public void run() { subConn.subscribe(ml, channel); System.out.println("Subscribed"); while (flag.get()) { try { - Thread.currentThread().sleep(2000); + Thread.sleep(2000); } catch (Exception ex) { return; } @@ -251,7 +249,6 @@ public abstract class AbstractConnectionIntegrationTests { MessageListener listener = new MessageListener() { - @Override public void onMessage(Message message, byte[] pattern) { assertArrayEquals(expectedChannel, message.getChannel()); assertArrayEquals(expectedMessage, message.getBody()); @@ -259,11 +256,10 @@ public abstract class AbstractConnectionIntegrationTests { }; Thread th = new Thread(new Runnable() { - @Override public void run() { // sleep 1 second to let the registration happen try { - Thread.currentThread().sleep(1000); + Thread.sleep(1000); } catch (InterruptedException ex) { throw new RuntimeException(ex); } @@ -288,7 +284,6 @@ public abstract class AbstractConnectionIntegrationTests { MessageListener listener = new MessageListener() { - @Override public void onMessage(Message message, byte[] pattern) { assertArrayEquals(expectedPattern, pattern); assertArrayEquals(expectedMessage, message.getBody()); @@ -297,11 +292,10 @@ public abstract class AbstractConnectionIntegrationTests { }; Thread th = new Thread(new Runnable() { - @Override public void run() { // sleep 1 second to let the registration happen try { - Thread.currentThread().sleep(1000); + Thread.sleep(1000); } catch (InterruptedException ex) { throw new RuntimeException(ex); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java index f550facfb..63a0d5245 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java @@ -37,7 +37,6 @@ public class SessionTest { final StringRedisTemplate template = new StringRedisTemplate(factory); template.execute(new SessionCallback() { - @Override public Object execute(RedisOperations operations) { checkConnection(template, conn); template.discard(); @@ -50,8 +49,6 @@ public class SessionTest { private void checkConnection(RedisTemplate template, final RedisConnection expectedConnection) { template.execute(new RedisCallback() { - - @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { assertSame(expectedConnection, connection); return null; diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/ThrowableMessageListener.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/ThrowableMessageListener.java index 2f2903e22..914b5fe69 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/ThrowableMessageListener.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/ThrowableMessageListener.java @@ -24,7 +24,6 @@ import org.springframework.data.keyvalue.redis.connection.MessageListener; */ public class ThrowableMessageListener implements MessageListener { - @Override public void onMessage(Message message, byte[] pattern) { throw new IllegalStateException("throwing exception for message " + message); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollectionTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollectionTests.java index 291f60665..3fb31d6d5 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollectionTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollectionTests.java @@ -90,8 +90,6 @@ public abstract class AbstractRedisCollectionTests { // remove the collection entirely since clear() doesn't always work collection.getOperations().delete(Collections.singleton(collection.getKey())); template.execute(new RedisCallback() { - - @Override public Object doInRedis(RedisConnection connection) { connection.flushDb(); return null; diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java index 1218c2e68..254d7f95e 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java @@ -92,8 +92,6 @@ public abstract class AbstractRedisMapTests { // remove the collection entirely since clear() doesn't always work map.getOperations().delete(Collections.singleton(map.getKey())); template.execute(new RedisCallback() { - - @Override public Object doInRedis(RedisConnection connection) { connection.flushDb(); return null; diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/PersonObjectFactory.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/PersonObjectFactory.java index 6e4dfe931..371b3f919 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/PersonObjectFactory.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/PersonObjectFactory.java @@ -27,7 +27,6 @@ public class PersonObjectFactory implements ObjectFactory { private int counter = 0; - @Override public Person instance() { String uuid = UUID.randomUUID().toString(); return new Person(uuid, uuid, ++counter, new Address(uuid, counter)); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/StringObjectFactory.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/StringObjectFactory.java index 6669ca873..3e6f4661e 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/StringObjectFactory.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/StringObjectFactory.java @@ -24,7 +24,6 @@ import java.util.UUID; */ public class StringObjectFactory implements ObjectFactory { - @Override public String instance() { return UUID.randomUUID().toString(); } From d6d87a27e1ffe3809a2711af218356c3aaec1050 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Sun, 10 Apr 2011 11:14:32 +0300 Subject: [PATCH 60/68] Revert "removed @Override annotations that cause problems in JDK 5 on interface methods" This reverts commit 41c5f7e0bcde5ceda4857bb5c70fa0fc0905c50a. Spring Redis depends on JDK 6 (at API level). --- .../redis/config/RedisNamespaceHandler.java | 2 + .../redis/connection/DefaultMessage.java | 2 + .../connection/DefaultSortParameters.java | 5 + .../DefaultStringRedisConnection.java | 103 ++++++++++++++ .../redis/connection/DefaultStringTuple.java | 1 + .../redis/connection/DefaultTuple.java | 2 + .../connection/jedis/JedisConnection.java | 129 ++++++++++++++++++ .../jedis/JedisConnectionFactory.java | 2 + .../connection/jredis/JredisConnection.java | 129 ++++++++++++++++++ .../jredis/JredisConnectionFactory.java | 4 + .../redis/connection/rjc/RjcConnection.java | 129 ++++++++++++++++++ .../connection/rjc/RjcConnectionFactory.java | 2 + .../connection/rjc/RjcMessageListener.java | 2 + .../connection/rjc/SingleDataSource.java | 1 + .../connection/util/AbstractSubscription.java | 10 ++ .../redis/core/AbstractOperations.java | 1 + .../core/DefaultBoundHashOperations.java | 14 ++ .../redis/core/DefaultBoundKeyOperations.java | 6 + .../core/DefaultBoundListOperations.java | 18 +++ .../redis/core/DefaultBoundSetOperations.java | 22 +++ .../core/DefaultBoundValueOperations.java | 12 ++ .../core/DefaultBoundZSetOperations.java | 19 +++ .../redis/core/DefaultHashOperations.java | 24 ++++ .../redis/core/DefaultListOperations.java | 28 ++++ .../redis/core/DefaultSetOperations.java | 36 +++++ .../redis/core/DefaultValueOperations.java | 24 ++++ .../redis/core/DefaultZSetOperations.java | 35 +++++ .../redis/core/RedisConnectionUtils.java | 3 + .../keyvalue/redis/core/RedisTemplate.java | 59 ++++++++ .../core/query/DefaultSortCriterion.java | 6 + .../redis/core/query/DefaultSortQuery.java | 6 + .../redis/hash/BeanUtilsHashMapper.java | 2 + .../hash/DecoratingStringHashMapper.java | 2 + .../redis/hash/JacksonHashMapper.java | 2 + .../RedisMessageListenerContainer.java | 16 +++ .../adapter/MessageListenerAdapter.java | 3 + .../serializer/GenericToStringSerializer.java | 3 + .../JacksonJsonRedisSerializer.java | 2 + .../JdkSerializationRedisSerializer.java | 2 + .../redis/serializer/OxmSerializer.java | 3 + .../serializer/StringRedisSerializer.java | 2 + .../support/atomic/RedisAtomicInteger.java | 23 ++-- .../redis/support/atomic/RedisAtomicLong.java | 21 +-- .../collections/AbstractRedisCollection.java | 11 +- .../support/collections/CollectionUtils.java | 2 + .../support/collections/DefaultRedisList.java | 52 +++++++ .../support/collections/DefaultRedisMap.java | 28 ++++ .../support/collections/DefaultRedisSet.java | 15 +- .../support/collections/DefaultRedisZSet.java | 17 +++ .../redis/config/StubErrorHandler.java | 2 + .../AbstractConnectionIntegrationTests.java | 12 +- .../data/keyvalue/redis/core/SessionTest.java | 3 + .../adapter/ThrowableMessageListener.java | 1 + .../AbstractRedisCollectionTests.java | 2 + .../collections/AbstractRedisMapTests.java | 2 + .../collections/PersonObjectFactory.java | 1 + .../collections/StringObjectFactory.java | 1 + 57 files changed, 1039 insertions(+), 27 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java index 36e901697..c2cc323e7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java @@ -15,6 +15,7 @@ */ package org.springframework.data.keyvalue.redis.config; +import org.springframework.beans.factory.xml.NamespaceHandler; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; /** @@ -24,6 +25,7 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport; */ class RedisNamespaceHandler extends NamespaceHandlerSupport { + @Override public void init() { registerBeanDefinitionParser("listener-container", new RedisListenerContainerParser()); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultMessage.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultMessage.java index 86e2305b4..1fd622577 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultMessage.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultMessage.java @@ -32,10 +32,12 @@ public class DefaultMessage implements Message { this.channel = channel; } + @Override public byte[] getChannel() { return (channel != null ? channel.clone() : null); } + @Override public byte[] getBody() { return (body != null ? body.clone() : null); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java index e6b8b3c1f..62a34bba1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultSortParameters.java @@ -68,6 +68,7 @@ public class DefaultSortParameters implements SortParameters { setGetPattern(getPattern); } + @Override public byte[] getByPattern() { return byPattern; } @@ -76,6 +77,7 @@ public class DefaultSortParameters implements SortParameters { this.byPattern = byPattern; } + @Override public Range getLimit() { return limit; } @@ -84,6 +86,7 @@ public class DefaultSortParameters implements SortParameters { this.limit = limit; } + @Override public byte[][] getGetPattern() { return getPattern.toArray(new byte[getPattern.size()][]); } @@ -100,6 +103,7 @@ public class DefaultSortParameters implements SortParameters { } } + @Override public Order getOrder() { return order; } @@ -108,6 +112,7 @@ public class DefaultSortParameters implements SortParameters { this.order = order; } + @Override public Boolean isAlphabetic() { return alphabetic; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java index a6681fa91..04484b29f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringRedisConnection.java @@ -621,415 +621,518 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return result; } + @Override public Long append(String key, String value) { return delegate.append(serialize(key), serialize(value)); } + @Override public List bLPop(int timeout, String... keys) { return deserialize(delegate.bLPop(timeout, serializeMulti(keys))); } + @Override public List bRPop(int timeout, String... keys) { return deserialize(delegate.bRPop(timeout, serializeMulti(keys))); } + @Override public String bRPopLPush(int timeout, String srcKey, String dstKey) { return deserialize(delegate.bRPopLPush(timeout, serialize(srcKey), serialize(dstKey))); } + @Override public Long decr(String key) { return delegate.decr(serialize(key)); } + @Override public Long decrBy(String key, long value) { return delegate.decrBy(serialize(key), value); } + @Override public Long del(String... keys) { return delegate.del(serializeMulti(keys)); } + @Override public String echo(String message) { return deserialize(delegate.echo(serialize(message))); } + @Override public Boolean exists(String key) { return delegate.exists(serialize(key)); } + @Override public Boolean expire(String key, long seconds) { return delegate.expire(serialize(key), seconds); } + @Override public Boolean expireAt(String key, long unixTime) { return delegate.expireAt(serialize(key), unixTime); } + @Override public String get(String key) { return deserialize(delegate.get(serialize(key))); } + @Override public Boolean getBit(String key, long offset) { return delegate.getBit(serialize(key), offset); } + @Override public String getRange(String key, long start, long end) { return deserialize(delegate.getRange(serialize(key), start, end)); } + @Override public String getSet(String key, String value) { return deserialize(delegate.getSet(serialize(key), serialize(value))); } + @Override public Boolean hDel(String key, String field) { return delegate.hDel(serialize(key), serialize(field)); } + @Override public Boolean hExists(String key, String field) { return delegate.hExists(serialize(key), serialize(field)); } + @Override public String hGet(String key, String field) { return deserialize(delegate.hGet(serialize(key), serialize(field))); } + @Override public Map hGetAll(String key) { throw new UnsupportedOperationException(); } + @Override public Long hIncrBy(String key, String field, long delta) { return delegate.hIncrBy(serialize(key), serialize(field), delta); } + @Override public Set hKeys(String key) { return deserialize(delegate.hKeys(serialize(key))); } + @Override public Long hLen(String key) { return delegate.hLen(serialize(key)); } + @Override public List hMGet(String key, String... fields) { return deserialize(delegate.hMGet(serialize(key), serializeMulti(fields))); } + @Override public void hMSet(String key, Map hashes) { delegate.hMSet(serialize(key), serialize(hashes)); } + @Override public Boolean hSet(String key, String field, String value) { return delegate.hSet(serialize(key), serialize(field), serialize(value)); } + @Override public Boolean hSetNX(String key, String field, String value) { return delegate.hSetNX(serialize(key), serialize(field), serialize(value)); } + @Override public List hVals(String key) { return deserialize(delegate.hVals(serialize(key))); } + @Override public Long incr(String key) { return delegate.incr(serialize(key)); } + @Override public Long incrBy(String key, long value) { return delegate.incrBy(serialize(key), value); } + @Override public Collection keys(String pattern) { return deserialize(delegate.keys(serialize(pattern))); } + @Override public String lIndex(String key, long index) { return deserialize(delegate.lIndex(serialize(key), index)); } + @Override public Long lInsert(String key, Position where, String pivot, String value) { return delegate.lInsert(serialize(key), where, serialize(pivot), serialize(value)); } + @Override public Long lLen(String key) { return delegate.lLen(serialize(key)); } + @Override public String lPop(String key) { return deserialize(delegate.lPop(serialize(key))); } + @Override public Long lPush(String key, String value) { return delegate.lPush(serialize(key), serialize(value)); } + @Override public Long lPushX(String key, String value) { return delegate.lPushX(serialize(key), serialize(value)); } + @Override public List lRange(String key, long start, long end) { return deserialize(delegate.lRange(serialize(key), start, end)); } + @Override public Long lRem(String key, long count, String value) { return delegate.lRem(serialize(key), count, serialize(value)); } + @Override public void lSet(String key, long index, String value) { delegate.lSet(serialize(key), index, serialize(value)); } + @Override public void lTrim(String key, long start, long end) { delegate.lTrim(serialize(key), start, end); } + @Override public List mGet(String... keys) { return deserialize(delegate.mGet(serializeMulti(keys))); } + @Override public void mSetNXString(Map tuple) { delegate.mSetNX(serialize(tuple)); } + @Override public void mSetString(Map tuple) { delegate.mSet(serialize(tuple)); } + @Override public Boolean persist(String key) { return delegate.persist(serialize(key)); } + @Override public Boolean move(String key, int dbIndex) { return delegate.move(serialize(key), dbIndex); } + @Override public void pSubscribe(MessageListener listener, String... patterns) { delegate.pSubscribe(listener, serializeMulti(patterns)); } + @Override public Long publish(String channel, String message) { return delegate.publish(serialize(channel), serialize(message)); } + @Override public void rename(String oldName, String newName) { delegate.rename(serialize(oldName), serialize(newName)); } + @Override public Boolean renameNX(String oldName, String newName) { return delegate.renameNX(serialize(oldName), serialize(newName)); } + @Override public String rPop(String key) { return deserialize(delegate.rPop(serialize(key))); } + @Override public String rPopLPush(String srcKey, String dstKey) { return deserialize(delegate.rPopLPush(serialize(srcKey), serialize(dstKey))); } + @Override public Long rPush(String key, String value) { return delegate.rPush(serialize(key), serialize(value)); } + @Override public Long rPushX(String key, String value) { return delegate.rPushX(serialize(key), serialize(value)); } + @Override public Boolean sAdd(String key, String value) { return delegate.sAdd(serialize(key), serialize(value)); } + @Override public Long sCard(String key) { return delegate.sCard(serialize(key)); } + @Override public Set sDiff(String... keys) { return deserialize(delegate.sDiff(serializeMulti(keys))); } + @Override public void sDiffStore(String destKey, String... keys) { delegate.sDiffStore(serialize(destKey), serializeMulti(keys)); } + @Override public void set(String key, String value) { delegate.set(serialize(key), serialize(value)); } + @Override public void setBit(String key, long offset, boolean value) { delegate.setBit(serialize(key), offset, value); } + @Override public void setEx(String key, long seconds, String value) { delegate.setEx(serialize(key), seconds, serialize(value)); } + @Override public Boolean setNX(String key, String value) { return delegate.setNX(serialize(key), serialize(value)); } + @Override public void setRange(String key, String value, long start) { delegate.setRange(serialize(key), serialize(value), start); } + @Override public Set sInter(String... keys) { return deserialize(delegate.sInter(serializeMulti(keys))); } + @Override public void sInterStore(String destKey, String... keys) { delegate.sInterStore(serialize(destKey), serializeMulti(keys)); } + @Override public Boolean sIsMember(String key, String value) { return delegate.sIsMember(serialize(key), serialize(value)); } + @Override public Set sMembers(String key) { return deserialize(delegate.sMembers(serialize(key))); } + @Override public Boolean sMove(String srcKey, String destKey, String value) { return delegate.sMove(serialize(srcKey), serialize(destKey), serialize(value)); } + @Override public Long sort(String key, SortParameters params, String storeKey) { return delegate.sort(serialize(key), params, serialize(storeKey)); } + @Override public List sort(String key, SortParameters params) { return deserialize(delegate.sort(serialize(key), params)); } + @Override public String sPop(String key) { return deserialize(delegate.sPop(serialize(key))); } + @Override public String sRandMember(String key) { return deserialize(delegate.sRandMember(serialize(key))); } + @Override public Boolean sRem(String key, String value) { return delegate.sRem(serialize(key), serialize(value)); } + @Override public Long strLen(String key) { return delegate.strLen(serialize(key)); } + @Override public void subscribe(MessageListener listener, String... channels) { delegate.subscribe(listener, serializeMulti(channels)); } + @Override public Set sUnion(String... keys) { return deserialize(delegate.sUnion(serializeMulti(keys))); } + @Override public void sUnionStore(String destKey, String... keys) { delegate.sUnionStore(serialize(destKey), serializeMulti(keys)); } + @Override public Long ttl(String key) { return delegate.ttl(serialize(key)); } + @Override public DataType type(String key) { return delegate.type(serialize(key)); } + @Override public Boolean zAdd(String key, double score, String value) { return delegate.zAdd(serialize(key), score, serialize(value)); } + @Override public Long zCard(String key) { return delegate.zCard(serialize(key)); } + @Override public Long zCount(String key, double min, double max) { return delegate.zCount(serialize(key), min, max); } + @Override public Double zIncrBy(String key, double increment, String value) { return delegate.zIncrBy(serialize(key), increment, serialize(value)); } + @Override public Long zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets) { return delegate.zInterStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); } + @Override public Long zInterStore(String destKey, String... sets) { return delegate.zInterStore(serialize(destKey), serializeMulti(sets)); } + @Override public Set zRange(String key, long start, long end) { return deserialize(delegate.zRange(serialize(key), start, end)); } + @Override public Set zRangeByScore(String key, double min, double max, long offset, long count) { return deserialize(delegate.zRangeByScore(serialize(key), min, max, offset, count)); } + @Override public Set zRangeByScore(String key, double min, double max) { return deserialize(delegate.zRangeByScore(serialize(key), min, max)); } + @Override public Set zRangeByScoreWithScore(String key, double min, double max, long offset, long count) { return deserializeTuple(delegate.zRangeByScoreWithScore(serialize(key), min, max, offset, count)); } + @Override public Set zRangeByScoreWithScore(String key, double min, double max) { return deserializeTuple(delegate.zRangeByScoreWithScore(serialize(key), min, max)); } + @Override public Set zRangeWithScore(String key, long start, long end) { return deserializeTuple(delegate.zRangeWithScore(serialize(key), start, end)); } + @Override public Long zRank(String key, String value) { return delegate.zRank(serialize(key), serialize(value)); } + @Override public Boolean zRem(String key, String value) { return delegate.zRem(serialize(key), serialize(value)); } + @Override public Long zRemRange(String key, long start, long end) { return delegate.zRemRange(serialize(key), start, end); } + @Override public Long zRemRangeByScore(String key, double min, double max) { return delegate.zRemRangeByScore(serialize(key), min, max); } + @Override public Set zRevRange(String key, long start, long end) { return deserialize(delegate.zRevRange(serialize(key), start, end)); } + @Override public Set zRevRangeWithScore(String key, long start, long end) { return deserializeTuple(delegate.zRevRangeWithScore(serialize(key), start, end)); } + @Override public Long zRevRank(String key, String value) { return delegate.zRevRank(serialize(key), serialize(value)); } + @Override public Double zScore(String key, String value) { return delegate.zScore(serialize(key), serialize(value)); } + @Override public Long zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets) { return delegate.zUnionStore(serialize(destKey), aggregate, weights, serializeMulti(sets)); } + @Override public Long zUnionStore(String destKey, String... sets) { return delegate.zUnionStore(serialize(destKey), serializeMulti(sets)); } + @Override public List closePipeline() { return delegate.closePipeline(); } + @Override public boolean isPipelined() { return delegate.isPipelined(); } + @Override public void openPipeline() { delegate.openPipeline(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringTuple.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringTuple.java index 8e281f108..9ed234216 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringTuple.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultStringTuple.java @@ -50,6 +50,7 @@ public class DefaultStringTuple extends DefaultTuple implements StringTuple { this.valueAsString = valueAsString; } + @Override public String getValueAsString() { return valueAsString; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultTuple.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultTuple.java index f623f7d76..e9c366fda 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultTuple.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/DefaultTuple.java @@ -39,10 +39,12 @@ public class DefaultTuple implements Tuple { this.value = value; } + @Override public Double getScore() { return score; } + @Override public byte[] getValue() { return value; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 1eac23abb..410f5fef8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -120,6 +120,7 @@ public class JedisConnection implements RedisConnection { return new UncategorizedKeyvalueStoreException("Unknown jedis exception", ex); } + @Override public void close() throws DataAccessException { // return the connection to the pool try { @@ -153,10 +154,12 @@ public class JedisConnection implements RedisConnection { } } + @Override public Jedis getNativeConnection() { return jedis; } + @Override public boolean isClosed() { try { return !jedis.isConnected(); @@ -165,14 +168,17 @@ public class JedisConnection implements RedisConnection { } } + @Override public boolean isQueueing() { return client.isInMulti(); } + @Override public boolean isPipelined() { return (pipeline != null); } + @Override public void openPipeline() { if (pipeline == null) { pipeline = jedis.pipelined(); @@ -180,6 +186,7 @@ public class JedisConnection implements RedisConnection { } @SuppressWarnings("unchecked") + @Override public List closePipeline() { if (pipeline != null) { List execute = pipeline.execute(); @@ -190,6 +197,7 @@ public class JedisConnection implements RedisConnection { return Collections.emptyList(); } + @Override public List sort(byte[] key, SortParameters params) { SortingParams sortParams = JedisUtils.convertSortParams(params); @@ -221,6 +229,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long sort(byte[] key, SortParameters params, byte[] sortKey) { SortingParams sortParams = JedisUtils.convertSortParams(params); @@ -252,6 +261,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long dbSize() { try { if (isQueueing()) { @@ -268,6 +278,7 @@ public class JedisConnection implements RedisConnection { } + @Override public void flushDb() { try { if (isQueueing()) { @@ -283,6 +294,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void flushAll() { try { if (isQueueing()) { @@ -298,6 +310,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void bgSave() { try { if (isQueueing()) { @@ -313,6 +326,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void bgWriteAof() { try { if (isQueueing()) { @@ -328,6 +342,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void save() { try { if (isQueueing()) { @@ -343,6 +358,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public List getConfig(String param) { try { if (isQueueing()) { @@ -358,6 +374,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Properties info() { try { if (isQueueing()) { @@ -372,6 +389,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long lastSave() { try { if (isQueueing()) { @@ -387,6 +405,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void setConfig(String param, String value) { try { if (isQueueing()) { @@ -403,6 +422,7 @@ public class JedisConnection implements RedisConnection { } + @Override public void resetConfigStats() { try { if (isQueueing()) { @@ -418,6 +438,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void shutdown() { try { if (isQueueing()) { @@ -432,6 +453,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] echo(byte[] message) { try { if (isQueueing()) { @@ -447,6 +469,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public String ping() { try { if (isQueueing()) { @@ -462,6 +485,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long del(byte[]... keys) { try { if (isQueueing()) { @@ -478,6 +502,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void discard() { try { client.discard(); @@ -486,6 +511,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public List exec() { try { if (isPipelined()) { @@ -498,6 +524,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean exists(byte[] key) { try { if (isQueueing()) { @@ -514,6 +541,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean expire(byte[] key, long seconds) { try { if (isQueueing()) { @@ -530,6 +558,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean expireAt(byte[] key, long unixTime) { try { if (isQueueing()) { @@ -546,6 +575,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set keys(byte[] pattern) { try { if (isQueueing()) { @@ -562,6 +592,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void multi() { if (isQueueing()) { return; @@ -577,6 +608,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean persist(byte[] key) { try { if (isQueueing()) { @@ -593,6 +625,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean move(byte[] key, int dbIndex) { try { if (isQueueing()) { @@ -609,6 +642,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] randomKey() { try { if (isQueueing()) { @@ -624,6 +658,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void rename(byte[] oldName, byte[] newName) { try { if (isQueueing()) { @@ -640,6 +675,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean renameNX(byte[] oldName, byte[] newName) { try { if (isQueueing()) { @@ -656,6 +692,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void select(int dbIndex) { try { if (isQueueing()) { @@ -671,6 +708,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long ttl(byte[] key) { try { if (isQueueing()) { @@ -687,6 +725,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public DataType type(byte[] key) { try { if (isQueueing()) { @@ -703,6 +742,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void unwatch() { try { jedis.unwatch(); @@ -711,6 +751,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void watch(byte[]... keys) { if (isQueueing()) { // ignore (as watch not allowed in multi) @@ -734,6 +775,7 @@ public class JedisConnection implements RedisConnection { // String commands // + @Override public byte[] get(byte[] key) { try { if (isQueueing()) { @@ -751,6 +793,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void set(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -768,6 +811,7 @@ public class JedisConnection implements RedisConnection { } + @Override public byte[] getSet(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -784,6 +828,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long append(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -800,6 +845,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public List mGet(byte[]... keys) { try { if (isQueueing()) { @@ -816,6 +862,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void mSet(Map tuples) { try { if (isQueueing()) { @@ -832,6 +879,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void mSetNX(Map tuples) { try { if (isQueueing()) { @@ -848,6 +896,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void setEx(byte[] key, long time, byte[] value) { try { if (isQueueing()) { @@ -864,6 +913,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean setNX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -880,6 +930,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] getRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -896,6 +947,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long decr(byte[] key) { try { if (isQueueing()) { @@ -912,6 +964,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long decrBy(byte[] key, long value) { try { if (isQueueing()) { @@ -928,6 +981,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long incr(byte[] key) { try { if (isQueueing()) { @@ -944,6 +998,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long incrBy(byte[] key, long value) { try { if (isQueueing()) { @@ -960,6 +1015,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean getBit(byte[] key, long offset) { try { if (isQueueing()) { @@ -976,6 +1032,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void setBit(byte[] key, long offset, boolean value) { try { if (isQueueing()) { @@ -992,10 +1049,12 @@ public class JedisConnection implements RedisConnection { } } + @Override public void setRange(byte[] key, byte[] value, long start) { throw new UnsupportedOperationException(); } + @Override public Long strLen(byte[] key) { try { if (isQueueing()) { @@ -1015,6 +1074,7 @@ public class JedisConnection implements RedisConnection { // List commands // + @Override public Long lPush(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1031,6 +1091,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long rPush(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1047,6 +1108,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public List bLPop(int timeout, byte[]... keys) { try { if (isQueueing()) { @@ -1067,6 +1129,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public List bRPop(int timeout, byte[]... keys) { try { if (isQueueing()) { @@ -1087,6 +1150,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] lIndex(byte[] key, long index) { try { if (isQueueing()) { @@ -1103,6 +1167,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { try { if (isQueueing()) { @@ -1120,6 +1185,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long lLen(byte[] key) { try { if (isQueueing()) { @@ -1136,6 +1202,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] lPop(byte[] key) { try { if (isQueueing()) { @@ -1152,6 +1219,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public List lRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1168,6 +1236,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long lRem(byte[] key, long count, byte[] value) { try { if (isQueueing()) { @@ -1184,6 +1253,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void lSet(byte[] key, long index, byte[] value) { try { if (isQueueing()) { @@ -1200,6 +1270,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void lTrim(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1216,6 +1287,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] rPop(byte[] key) { try { if (isQueueing()) { @@ -1232,6 +1304,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { if (isQueueing()) { @@ -1248,6 +1321,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { try { if (isQueueing()) { @@ -1263,6 +1337,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long lPushX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1278,6 +1353,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long rPushX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1298,6 +1374,7 @@ public class JedisConnection implements RedisConnection { // Set commands // + @Override public Boolean sAdd(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1314,6 +1391,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long sCard(byte[] key) { try { if (isQueueing()) { @@ -1330,6 +1408,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set sDiff(byte[]... keys) { try { if (isQueueing()) { @@ -1346,6 +1425,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void sDiffStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1362,6 +1442,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set sInter(byte[]... keys) { try { if (isQueueing()) { @@ -1378,6 +1459,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void sInterStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1394,6 +1476,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean sIsMember(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1410,6 +1493,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set sMembers(byte[] key) { try { if (isQueueing()) { @@ -1426,6 +1510,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { if (isQueueing()) { @@ -1442,6 +1527,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] sPop(byte[] key) { try { if (isQueueing()) { @@ -1458,6 +1544,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] sRandMember(byte[] key) { try { if (isQueueing()) { @@ -1474,6 +1561,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean sRem(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1490,6 +1578,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set sUnion(byte[]... keys) { try { if (isQueueing()) { @@ -1506,6 +1595,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void sUnionStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1526,6 +1616,7 @@ public class JedisConnection implements RedisConnection { // ZSet commands // + @Override public Boolean zAdd(byte[] key, double score, byte[] value) { try { if (isQueueing()) { @@ -1542,6 +1633,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zCard(byte[] key) { try { if (isQueueing()) { @@ -1558,6 +1650,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zCount(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1573,6 +1666,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Double zIncrBy(byte[] key, double increment, byte[] value) { try { if (isQueueing()) { @@ -1589,6 +1683,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { if (isQueueing()) { @@ -1606,6 +1701,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zInterStore(byte[] destKey, byte[]... sets) { try { if (isQueueing()) { @@ -1621,6 +1717,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set zRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1637,6 +1734,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set zRangeWithScore(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1653,6 +1751,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set zRangeByScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1668,6 +1767,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1683,6 +1783,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set zRevRangeWithScore(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1698,6 +1799,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { @@ -1713,6 +1815,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { @@ -1728,6 +1831,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zRank(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1744,6 +1848,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean zRem(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1760,6 +1865,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zRemRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1775,6 +1881,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zRemRangeByScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1790,6 +1897,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set zRevRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1806,6 +1914,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zRevRank(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1822,6 +1931,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Double zScore(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1838,6 +1948,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { if (isQueueing()) { @@ -1855,6 +1966,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long zUnionStore(byte[] destKey, byte[]... sets) { try { if (isQueueing()) { @@ -1874,6 +1986,7 @@ public class JedisConnection implements RedisConnection { // Hash commands // + @Override public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { if (isQueueing()) { @@ -1890,6 +2003,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { try { if (isQueueing()) { @@ -1906,6 +2020,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean hDel(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -1922,6 +2037,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Boolean hExists(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -1938,6 +2054,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public byte[] hGet(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -1954,6 +2071,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Map hGetAll(byte[] key) { try { if (isQueueing()) { @@ -1970,6 +2088,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long hIncrBy(byte[] key, byte[] field, long delta) { try { if (isQueueing()) { @@ -1986,6 +2105,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Set hKeys(byte[] key) { try { if (isQueueing()) { @@ -2002,6 +2122,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public Long hLen(byte[] key) { try { if (isQueueing()) { @@ -2018,6 +2139,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public List hMGet(byte[] key, byte[]... fields) { try { if (isQueueing()) { @@ -2034,6 +2156,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void hMSet(byte[] key, Map tuple) { try { if (isQueueing()) { @@ -2050,6 +2173,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public List hVals(byte[] key) { try { if (isQueueing()) { @@ -2070,6 +2194,7 @@ public class JedisConnection implements RedisConnection { // // Pub/Sub functionality // + @Override public Long publish(byte[] channel, byte[] message) { try { if (isQueueing()) { @@ -2084,14 +2209,17 @@ public class JedisConnection implements RedisConnection { } } + @Override public Subscription getSubscription() { return subscription; } + @Override public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } + @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( @@ -2116,6 +2244,7 @@ public class JedisConnection implements RedisConnection { } } + @Override public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java index acee611dc..51f326a39 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -149,6 +150,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, null, dbIndex))); } + @Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return JedisUtils.convertJedisAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java index 329ab8f97..ada3441e1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnection.java @@ -74,6 +74,7 @@ public class JredisConnection implements RedisConnection { return new UncategorizedKeyvalueStoreException("Unknown JRedis exception", ex); } + @Override public void close() throws RedisSystemException { isClosed = true; @@ -88,30 +89,37 @@ public class JredisConnection implements RedisConnection { } } + @Override public JRedis getNativeConnection() { return jredis; } + @Override public boolean isClosed() { return isClosed; } + @Override public boolean isQueueing() { return false; } + @Override public boolean isPipelined() { return false; } + @Override public void openPipeline() { throw new UnsupportedOperationException("Pipelining not supported by JRedis"); } + @Override public List closePipeline() { return Collections.emptyList(); } + @Override public List sort(byte[] key, SortParameters params) { Sort sort = jredis.sort(JredisUtils.decode(key)); JredisUtils.applySortingParams(sort, params, null); @@ -122,6 +130,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long sort(byte[] key, SortParameters params, byte[] storeKey) { Sort sort = jredis.sort(JredisUtils.decode(key)); JredisUtils.applySortingParams(sort, params, null); @@ -132,6 +141,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long dbSize() { try { return jredis.dbsize(); @@ -140,6 +150,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void flushDb() { try { jredis.flushdb(); @@ -148,6 +159,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void flushAll() { try { jredis.flushall(); @@ -156,6 +168,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] echo(byte[] message) { try { return jredis.echo(message); @@ -164,6 +177,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public String ping() { try { jredis.ping(); @@ -173,6 +187,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void bgSave() { try { jredis.bgsave(); @@ -181,6 +196,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void bgWriteAof() { try { jredis.bgrewriteaof(); @@ -189,6 +205,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void save() { try { jredis.save(); @@ -197,10 +214,12 @@ public class JredisConnection implements RedisConnection { } } + @Override public List getConfig(String pattern) { throw new UnsupportedOperationException(); } + @Override public Properties info() { try { return JredisUtils.info(jredis.info()); @@ -209,6 +228,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long lastSave() { try { return jredis.lastsave(); @@ -217,18 +237,22 @@ public class JredisConnection implements RedisConnection { } } + @Override public void setConfig(String param, String value) { throw new UnsupportedOperationException(); } + @Override public void resetConfigStats() { throw new UnsupportedOperationException(); } + @Override public void shutdown() { throw new UnsupportedOperationException(); } + @Override public Long del(byte[]... keys) { try { return jredis.del(JredisUtils.decodeMultiple(keys)); @@ -237,6 +261,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void discard() { try { jredis.discard(); @@ -245,10 +270,12 @@ public class JredisConnection implements RedisConnection { } } + @Override public List exec() { throw new UnsupportedOperationException(); } + @Override public Boolean exists(byte[] key) { try { return jredis.exists(JredisUtils.decode(key)); @@ -257,6 +284,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean expire(byte[] key, long seconds) { try { return jredis.expire(JredisUtils.decode(key), (int) seconds); @@ -265,6 +293,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean expireAt(byte[] key, long unixTime) { try { return jredis.expireat(JredisUtils.decode(key), unixTime); @@ -273,6 +302,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set keys(byte[] pattern) { try { return JredisUtils.convertToSet(jredis.keys(JredisUtils.decode(pattern))); @@ -281,15 +311,18 @@ public class JredisConnection implements RedisConnection { } } + @Override public void multi() { throw new UnsupportedOperationException(); } + @Override public Boolean persist(byte[] key) { throw new UnsupportedOperationException(); } + @Override public Boolean move(byte[] key, int dbIndex) { try { return jredis.move(JredisUtils.decode(key), dbIndex); @@ -298,6 +331,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] randomKey() { try { return JredisUtils.encode(jredis.randomkey()); @@ -306,6 +340,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void rename(byte[] oldName, byte[] newName) { try { jredis.rename(JredisUtils.decode(oldName), JredisUtils.decode(newName)); @@ -314,6 +349,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean renameNX(byte[] oldName, byte[] newName) { try { return jredis.renamenx(JredisUtils.decode(oldName), JredisUtils.decode(newName)); @@ -322,10 +358,12 @@ public class JredisConnection implements RedisConnection { } } + @Override public void select(int dbIndex) { throw new UnsupportedOperationException(); } + @Override public Long ttl(byte[] key) { try { return jredis.ttl(JredisUtils.decode(key)); @@ -334,6 +372,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public DataType type(byte[] key) { try { return JredisUtils.convertDataType(jredis.type(JredisUtils.decode(key))); @@ -342,10 +381,12 @@ public class JredisConnection implements RedisConnection { } } + @Override public void unwatch() { throw new UnsupportedOperationException(); } + @Override public void watch(byte[]... keys) { throw new UnsupportedOperationException(); } @@ -354,6 +395,7 @@ public class JredisConnection implements RedisConnection { // String operations // + @Override public byte[] get(byte[] key) { try { return jredis.get(JredisUtils.decode(key)); @@ -362,6 +404,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void set(byte[] key, byte[] value) { try { jredis.set(JredisUtils.decode(key), value); @@ -370,6 +413,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] getSet(byte[] key, byte[] value) { try { return jredis.getset(JredisUtils.decode(key), value); @@ -378,6 +422,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long append(byte[] key, byte[] value) { try { return jredis.append(JredisUtils.decode(key), value); @@ -386,6 +431,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public List mGet(byte[]... keys) { try { return jredis.mget(JredisUtils.decodeMultiple(keys)); @@ -394,6 +440,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void mSet(Map tuple) { try { jredis.mset(JredisUtils.decodeMap(tuple)); @@ -402,6 +449,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void mSetNX(Map tuple) { try { jredis.msetnx(JredisUtils.decodeMap(tuple)); @@ -410,10 +458,12 @@ public class JredisConnection implements RedisConnection { } } + @Override public void setEx(byte[] key, long seconds, byte[] value) { throw new UnsupportedOperationException(); } + @Override public Boolean setNX(byte[] key, byte[] value) { try { return jredis.setnx(JredisUtils.decode(key), value); @@ -422,6 +472,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] getRange(byte[] key, long start, long end) { try { return jredis.substr(JredisUtils.decode(key), start, end); @@ -430,6 +481,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long decr(byte[] key) { try { return jredis.decr(JredisUtils.decode(key)); @@ -438,6 +490,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long decrBy(byte[] key, long value) { try { return jredis.decrby(JredisUtils.decode(key), (int) value); @@ -446,6 +499,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long incr(byte[] key) { try { return jredis.incr(JredisUtils.decode(key)); @@ -454,6 +508,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long incrBy(byte[] key, long value) { try { return jredis.incrby(JredisUtils.decode(key), (int) value); @@ -462,18 +517,22 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean getBit(byte[] key, long offset) { throw new UnsupportedOperationException(); } + @Override public void setBit(byte[] key, long offset, boolean value) { throw new UnsupportedOperationException(); } + @Override public void setRange(byte[] key, byte[] value, long start) { throw new UnsupportedOperationException(); } + @Override public Long strLen(byte[] key) { throw new UnsupportedOperationException(); } @@ -482,14 +541,17 @@ public class JredisConnection implements RedisConnection { // List commands // + @Override public List bLPop(int timeout, byte[]... keys) { throw new UnsupportedOperationException(); } + @Override public List bRPop(int timeout, byte[]... keys) { throw new UnsupportedOperationException(); } + @Override public byte[] lIndex(byte[] key, long index) { try { return jredis.lindex(JredisUtils.decode(key), index); @@ -498,6 +560,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long lLen(byte[] key) { try { return jredis.llen(JredisUtils.decode(key)); @@ -506,6 +569,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] lPop(byte[] key) { try { return jredis.lpop(JredisUtils.decode(key)); @@ -514,6 +578,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long lPush(byte[] key, byte[] value) { try { jredis.lpush(JredisUtils.decode(key), value); @@ -523,6 +588,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public List lRange(byte[] key, long start, long end) { try { List lrange = jredis.lrange(JredisUtils.decode(key), start, end); @@ -533,6 +599,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long lRem(byte[] key, long count, byte[] value) { try { return jredis.lrem(JredisUtils.decode(key), value, (int) count); @@ -541,6 +608,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void lSet(byte[] key, long index, byte[] value) { try { jredis.lset(JredisUtils.decode(key), index, value); @@ -549,6 +617,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void lTrim(byte[] key, long start, long end) { try { jredis.ltrim(JredisUtils.decode(key), start, end); @@ -557,6 +626,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] rPop(byte[] key) { try { return jredis.rpop(JredisUtils.decode(key)); @@ -565,6 +635,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { return jredis.rpoplpush(JredisUtils.decode(srcKey), JredisUtils.decode(dstKey)); @@ -573,6 +644,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long rPush(byte[] key, byte[] value) { try { jredis.rpush(JredisUtils.decode(key), value); @@ -582,18 +654,22 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { throw new UnsupportedOperationException(); } + @Override public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { throw new UnsupportedOperationException(); } + @Override public Long lPushX(byte[] key, byte[] value) { throw new UnsupportedOperationException(); } + @Override public Long rPushX(byte[] key, byte[] value) { throw new UnsupportedOperationException(); } @@ -603,6 +679,7 @@ public class JredisConnection implements RedisConnection { // Set commands // + @Override public Boolean sAdd(byte[] key, byte[] value) { try { return jredis.sadd(JredisUtils.decode(key), value); @@ -611,6 +688,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long sCard(byte[] key) { try { return jredis.scard(JredisUtils.decode(key)); @@ -619,6 +697,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set sDiff(byte[]... keys) { String destKey = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -631,6 +710,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void sDiffStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -642,6 +722,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set sInter(byte[]... keys) { String set1 = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -654,6 +735,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void sInterStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -665,6 +747,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean sIsMember(byte[] key, byte[] value) { try { return jredis.sismember(JredisUtils.decode(key), value); @@ -673,6 +756,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set sMembers(byte[] key) { try { return new LinkedHashSet(jredis.smembers(JredisUtils.decode(key))); @@ -681,6 +765,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { return jredis.smove(JredisUtils.decode(srcKey), JredisUtils.decode(destKey), value); @@ -689,6 +774,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] sPop(byte[] key) { try { return jredis.spop(JredisUtils.decode(key)); @@ -697,6 +783,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] sRandMember(byte[] key) { try { return jredis.srandmember(JredisUtils.decode(key)); @@ -705,6 +792,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean sRem(byte[] key, byte[] value) { try { return jredis.srem(JredisUtils.decode(key), value); @@ -713,6 +801,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set sUnion(byte[]... keys) { String set1 = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -724,6 +813,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public void sUnionStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -740,6 +830,7 @@ public class JredisConnection implements RedisConnection { // ZSet commands // + @Override public Boolean zAdd(byte[] key, double score, byte[] value) { try { return jredis.zadd(JredisUtils.decode(key), score, value); @@ -748,6 +839,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long zCard(byte[] key) { try { return jredis.zcard(JredisUtils.decode(key)); @@ -756,6 +848,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long zCount(byte[] key, double min, double max) { try { return jredis.zcount(JredisUtils.decode(key), min, max); @@ -764,6 +857,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Double zIncrBy(byte[] key, double increment, byte[] value) { try { return jredis.zincrby(JredisUtils.decode(key), increment, value); @@ -772,14 +866,17 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } + @Override public Long zInterStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } + @Override public Set zRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrange(JredisUtils.decode(key), start, end)); @@ -788,11 +885,13 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set zRangeWithScore(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } + @Override public Set zRangeByScore(byte[] key, double min, double max) { try { return new LinkedHashSet(jredis.zrangebyscore(JredisUtils.decode(key), min, max)); @@ -801,18 +900,22 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max) { throw new UnsupportedOperationException(); } + @Override public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } + @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } + @Override public Long zRank(byte[] key, byte[] value) { try { return jredis.zrank(JredisUtils.decode(key), value); @@ -821,6 +924,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean zRem(byte[] key, byte[] value) { try { return jredis.zrem(JredisUtils.decode(key), value); @@ -829,6 +933,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long zRemRange(byte[] key, long start, long end) { try { return jredis.zremrangebyrank(JredisUtils.decode(key), start, end); @@ -837,6 +942,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long zRemRangeByScore(byte[] key, double min, double max) { try { return jredis.zremrangebyscore(JredisUtils.decode(key), min, max); @@ -845,6 +951,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set zRevRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrevrange(JredisUtils.decode(key), start, end)); @@ -853,10 +960,12 @@ public class JredisConnection implements RedisConnection { } } + @Override public Set zRevRangeWithScore(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } + @Override public Long zRevRank(byte[] key, byte[] value) { try { return jredis.zrevrank(JredisUtils.decode(key), value); @@ -865,6 +974,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Double zScore(byte[] key, byte[] value) { try { return jredis.zscore(JredisUtils.decode(key), value); @@ -878,14 +988,17 @@ public class JredisConnection implements RedisConnection { // Hash commands // + @Override public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } + @Override public Long zUnionStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } + @Override public Boolean hDel(byte[] key, byte[] field) { try { return jredis.hdel(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -894,6 +1007,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean hExists(byte[] key, byte[] field) { try { return jredis.hexists(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -902,6 +1016,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public byte[] hGet(byte[] key, byte[] field) { try { return jredis.hget(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -910,6 +1025,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Map hGetAll(byte[] key) { try { return JredisUtils.encodeMap(jredis.hgetall(JredisUtils.decode(key))); @@ -918,10 +1034,12 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long hIncrBy(byte[] key, byte[] field, long delta) { throw new UnsupportedOperationException(); } + @Override public Set hKeys(byte[] key) { try { return new LinkedHashSet(JredisUtils.convertToSet(jredis.hkeys(JredisUtils.decode(key)))); @@ -930,6 +1048,7 @@ public class JredisConnection implements RedisConnection { } } + @Override public Long hLen(byte[] key) { try { return jredis.hlen(JredisUtils.decode(key)); @@ -938,14 +1057,17 @@ public class JredisConnection implements RedisConnection { } } + @Override public List hMGet(byte[] key, byte[]... fields) { throw new UnsupportedOperationException(); } + @Override public void hMSet(byte[] key, Map values) { throw new UnsupportedOperationException(); } + @Override public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { return jredis.hset(JredisUtils.decode(key), JredisUtils.decode(field), value); @@ -954,10 +1076,12 @@ public class JredisConnection implements RedisConnection { } } + @Override public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { throw new UnsupportedOperationException(); } + @Override public List hVals(byte[] key) { try { return jredis.hvals(JredisUtils.decode(key)); @@ -970,22 +1094,27 @@ public class JredisConnection implements RedisConnection { // PubSub commands // + @Override public Subscription getSubscription() { return null; } + @Override public boolean isSubscribed() { return false; } + @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { throw new UnsupportedOperationException(); } + @Override public Long publish(byte[] channel, byte[] message) { throw new UnsupportedOperationException(); } + @Override public void subscribe(MessageListener listener, byte[]... channels) { throw new UnsupportedOperationException(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java index 852c184a2..87ae5c1a5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java @@ -72,6 +72,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean this.connectionSpec = connectionSpec; } + @Override public void afterPropertiesSet() { if (connectionSpec == null) { Assert.hasText(hostName); @@ -94,6 +95,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean } + @Override public void destroy() { if (usePool && pool != null) { pool.quit(); @@ -102,6 +104,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean } + @Override public RedisConnection getConnection() { return postProcessConnection(new JredisConnection((usePool ? pool : new JRedisClient(connectionSpec)))); } @@ -119,6 +122,7 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean return connection; } + @Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof ClientRuntimeException) { return JredisUtils.convertJredisAccessException((ClientRuntimeException) ex); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 71743571f..50d5f78f0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -76,6 +76,7 @@ public class RjcConnection implements RedisConnection { return new UncategorizedKeyvalueStoreException("Unknown rjc exception", ex); } + @Override public void close() throws DataAccessException { isClosed = true; @@ -88,22 +89,27 @@ public class RjcConnection implements RedisConnection { } + @Override public boolean isClosed() { return isClosed; } + @Override public Session getNativeConnection() { return session; } + @Override public boolean isQueueing() { return client.isInMulti(); } + @Override public boolean isPipelined() { return (pipeline != null); } + @Override public void openPipeline() { if (pipeline == null) { pipeline = client; @@ -111,6 +117,7 @@ public class RjcConnection implements RedisConnection { } @SuppressWarnings("unchecked") + @Override public List closePipeline() { if (pipeline != null) { List execute = client.getAll(); @@ -121,6 +128,7 @@ public class RjcConnection implements RedisConnection { return Collections.emptyList(); } + @Override public List sort(byte[] key, SortParameters params) { SortingParams sortParams = RjcUtils.convertSortParams(params); @@ -144,6 +152,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long sort(byte[] key, SortParameters params, byte[] sortKey) { SortingParams sortParams = RjcUtils.convertSortParams(params); @@ -168,6 +177,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long dbSize() { try { if (isPipelined()) { @@ -181,6 +191,7 @@ public class RjcConnection implements RedisConnection { } + @Override public void flushDb() { try { if (isPipelined()) { @@ -193,6 +204,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void flushAll() { try { if (isPipelined()) { @@ -205,6 +217,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void bgSave() { try { if (isPipelined()) { @@ -217,6 +230,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void bgWriteAof() { try { if (isPipelined()) { @@ -229,6 +243,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void save() { try { if (isPipelined()) { @@ -241,6 +256,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public List getConfig(String param) { try { if (isPipelined()) { @@ -253,6 +269,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Properties info() { try { if (isPipelined()) { @@ -265,6 +282,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long lastSave() { try { if (isPipelined()) { @@ -277,6 +295,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void setConfig(String param, String value) { try { if (isPipelined()) { @@ -290,6 +309,7 @@ public class RjcConnection implements RedisConnection { } + @Override public void resetConfigStats() { try { if (isPipelined()) { @@ -303,6 +323,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void shutdown() { try { if (isPipelined()) { @@ -315,6 +336,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] echo(byte[] message) { String stringMsg = RjcUtils.decode(message); try { @@ -328,6 +350,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public String ping() { try { if (isPipelined()) { @@ -339,6 +362,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long del(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -353,6 +377,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void discard() { try { if (isPipelined()) { @@ -366,6 +391,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public List exec() { try { if (isPipelined()) { @@ -378,6 +404,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean exists(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -392,6 +419,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean expire(byte[] key, long seconds) { String stringKey = RjcUtils.decode(key); @@ -406,6 +434,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean expireAt(byte[] key, long unixTime) { String stringKey = RjcUtils.decode(key); @@ -420,6 +449,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set keys(byte[] pattern) { String stringKey = RjcUtils.decode(pattern); @@ -434,6 +464,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void multi() { if (isQueueing()) { return; @@ -449,6 +480,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean persist(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -463,6 +495,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean move(byte[] key, int dbIndex) { String stringKey = RjcUtils.decode(key); @@ -477,6 +510,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] randomKey() { try { if (isPipelined()) { @@ -489,6 +523,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void rename(byte[] oldName, byte[] newName) { String stringOldKey = RjcUtils.decode(oldName); String stringNewKey = RjcUtils.decode(newName); @@ -504,6 +539,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean renameNX(byte[] oldName, byte[] newName) { String stringOldKey = RjcUtils.decode(oldName); String stringNewKey = RjcUtils.decode(newName); @@ -519,6 +555,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void select(int dbIndex) { try { if (isPipelined()) { @@ -531,6 +568,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long ttl(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -545,6 +583,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public DataType type(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -559,6 +598,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void unwatch() { try { if (isPipelined()) { @@ -572,6 +612,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void watch(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -595,6 +636,7 @@ public class RjcConnection implements RedisConnection { // String commands // + @Override public byte[] get(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -610,6 +652,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void set(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -626,6 +669,7 @@ public class RjcConnection implements RedisConnection { } + @Override public byte[] getSet(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -641,6 +685,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long append(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -656,6 +701,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public List mGet(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -670,6 +716,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void mSet(Map tuples) { String[] decodeMap = RjcUtils.flatten(tuples); @@ -684,6 +731,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void mSetNX(Map tuples) { String[] decodeMap = RjcUtils.flatten(tuples); @@ -699,6 +747,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void setEx(byte[] key, long time, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -714,6 +763,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean setNX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -729,6 +779,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] getRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -743,6 +794,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long decr(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -757,6 +809,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long decrBy(byte[] key, long value) { String stringKey = RjcUtils.decode(key); try { @@ -771,6 +824,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long incr(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -786,6 +840,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long incrBy(byte[] key, long value) { String stringKey = RjcUtils.decode(key); @@ -801,6 +856,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean getBit(byte[] key, long offset) { String stringKey = RjcUtils.decode(key); @@ -815,6 +871,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void setBit(byte[] key, long offset, boolean value) { String stringKey = RjcUtils.decode(key); @@ -829,6 +886,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void setRange(byte[] key, byte[] value, long offset) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -844,6 +902,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long strLen(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -862,6 +921,7 @@ public class RjcConnection implements RedisConnection { // List commands // + @Override public Long lPush(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -877,6 +937,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long rPush(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -893,6 +954,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public List bLPop(int timeout, byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -907,6 +969,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public List bRPop(int timeout, byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -921,6 +984,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] lIndex(byte[] key, long index) { String stringKey = RjcUtils.decode(key); @@ -936,6 +1000,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -953,6 +1018,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long lLen(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -968,6 +1034,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] lPop(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -983,6 +1050,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public List lRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -998,6 +1066,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long lRem(byte[] key, long count, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1014,6 +1083,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void lSet(byte[] key, long index, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1029,6 +1099,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void lTrim(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -1044,6 +1115,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] rPop(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1059,6 +1131,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { String stringKey = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(dstKey); @@ -1075,6 +1148,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { String stringKey = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(dstKey); @@ -1090,6 +1164,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long lPushX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1104,6 +1179,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long rPushX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1123,6 +1199,7 @@ public class RjcConnection implements RedisConnection { // Set commands // + @Override public Boolean sAdd(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1139,6 +1216,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long sCard(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1154,6 +1232,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set sDiff(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1169,6 +1248,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void sDiffStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1185,6 +1265,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set sInter(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); try { @@ -1199,6 +1280,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void sInterStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1214,6 +1296,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean sIsMember(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1230,6 +1313,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set sMembers(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1244,6 +1328,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { String stringSrc = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(destKey); @@ -1261,6 +1346,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] sPop(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1275,6 +1361,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] sRandMember(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1289,6 +1376,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean sRem(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1305,6 +1393,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set sUnion(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1320,6 +1409,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void sUnionStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1340,6 +1430,7 @@ public class RjcConnection implements RedisConnection { // ZSet commands // + @Override public Boolean zAdd(byte[] key, double score, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1355,6 +1446,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zCard(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1369,6 +1461,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zCount(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); try { @@ -1383,6 +1476,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Double zIncrBy(byte[] key, double increment, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1398,6 +1492,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1415,6 +1510,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zInterStore(byte[] destKey, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1430,6 +1526,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set zRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1444,6 +1541,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set zRangeWithScore(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1458,6 +1556,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set zRangeByScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1474,6 +1573,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1490,6 +1590,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set zRevRangeWithScore(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); String minString = Long.toString(start); @@ -1507,6 +1608,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1524,6 +1626,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1541,6 +1644,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zRank(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1556,6 +1660,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean zRem(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1571,6 +1676,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zRemRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1584,6 +1690,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zRemRangeByScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1600,6 +1707,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set zRevRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1614,6 +1722,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zRevRank(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1629,6 +1738,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Double zScore(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1644,6 +1754,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(destKey); @@ -1661,6 +1772,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long zUnionStore(byte[] destKey, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1680,6 +1792,7 @@ public class RjcConnection implements RedisConnection { // Hash commands // + @Override public Boolean hSet(byte[] key, byte[] field, byte[] value) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1696,6 +1809,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1712,6 +1826,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean hDel(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1727,6 +1842,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Boolean hExists(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1742,6 +1858,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public byte[] hGet(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1757,6 +1874,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Map hGetAll(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1771,6 +1889,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long hIncrBy(byte[] key, byte[] field, long delta) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1786,6 +1905,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Set hKeys(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1799,6 +1919,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public Long hLen(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1812,6 +1933,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public List hMGet(byte[] key, byte[]... fields) { String stringKey = RjcUtils.decode(key); String[] stringKeys = RjcUtils.decodeMultiple(fields); @@ -1827,6 +1949,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void hMSet(byte[] key, Map tuple) { String stringKey = RjcUtils.decode(key); Map stringTuple = RjcUtils.decodeMap(tuple); @@ -1842,6 +1965,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public List hVals(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1860,6 +1984,7 @@ public class RjcConnection implements RedisConnection { // // Pub/Sub functionality // + @Override public Long publish(byte[] channel, byte[] message) { try { if (isQueueing()) { @@ -1874,14 +1999,17 @@ public class RjcConnection implements RedisConnection { } } + @Override public Subscription getSubscription() { return subscription; } + @Override public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } + @Override public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( @@ -1905,6 +2033,7 @@ public class RjcConnection implements RedisConnection { } } + @Override public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java index aceaaf3ab..5c149f107 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java @@ -85,6 +85,7 @@ public class RjcConnectionFactory implements InitializingBean, DisposableBean, R } } + @Override public RedisConnection getConnection() { return postProcessConnection(new RjcConnection(dataSource.getConnection(), dbIndex)); } @@ -101,6 +102,7 @@ public class RjcConnectionFactory implements InitializingBean, DisposableBean, R return connection; } + @Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { return RjcUtils.convertRjcAccessException(ex); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java index 06f238ec7..c16a2040f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcMessageListener.java @@ -32,10 +32,12 @@ class RjcMessageListener implements MessageListener, PMessageListener { this.listener = messageListener; } + @Override public void onMessage(String channel, String message) { listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), null); } + @Override public void onMessage(String pattern, String channel, String message) { listener.onMessage(new DefaultMessage(RjcUtils.encode(channel), RjcUtils.encode(message)), RjcUtils.encode(pattern)); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java index 0f9397eee..db152b72c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/SingleDataSource.java @@ -31,6 +31,7 @@ class SingleDataSource implements DataSource { this.connection = connection; } + @Override public RedisConnection getConnection() { return connection; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java index b9be9485b..6d20a8bf5 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/util/AbstractSubscription.java @@ -98,22 +98,26 @@ public abstract class AbstractSubscription implements Subscription { */ protected abstract void doClose(); + @Override public MessageListener getListener() { return listener; } + @Override public Collection getChannels() { synchronized (channels) { return clone(channels); } } + @Override public Collection getPatterns() { synchronized (patterns) { return clone(patterns); } } + @Override public void pSubscribe(byte[]... patterns) { checkPulse(); @@ -126,11 +130,13 @@ public abstract class AbstractSubscription implements Subscription { doPsubscribe(patterns); } + @Override public void pUnsubscribe() { pUnsubscribe((byte[][]) null); } + @Override public void subscribe(byte[]... channels) { checkPulse(); @@ -143,10 +149,12 @@ public abstract class AbstractSubscription implements Subscription { doSubscribe(channels); } + @Override public void unsubscribe() { unsubscribe((byte[][]) null); } + @Override public void pUnsubscribe(byte[]... patts) { if (!isAlive()) { return; @@ -176,6 +184,7 @@ public abstract class AbstractSubscription implements Subscription { } } + @Override public void unsubscribe(byte[]... chans) { if (!isAlive()) { return; @@ -205,6 +214,7 @@ public abstract class AbstractSubscription implements Subscription { } } + @Override public boolean isAlive() { return alive.get(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java index bb7c26e3b..ccaeedfe4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/AbstractOperations.java @@ -41,6 +41,7 @@ abstract class AbstractOperations { this.key = key; } + @Override public final V doInRedis(RedisConnection connection) { byte[] result = inRedis(rawKey(key), connection); return deserializeValue(result); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java index c4bda0c69..c8e6a531e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java @@ -41,58 +41,72 @@ class DefaultBoundHashOperations extends DefaultBoundKeyOperations this.ops = operations.opsForHash(); } + @Override public void delete(Object key) { ops.delete(getKey(), key); } + @Override public HV get(Object key) { return ops.get(getKey(), key); } + @Override public Collection multiGet(Collection hashKeys) { return ops.multiGet(getKey(), hashKeys); } + @Override public RedisOperations getOperations() { return ops.getOperations(); } + @Override public boolean hasKey(Object key) { return ops.hasKey(getKey(), key); } + @Override public Long increment(HK key, long delta) { return ops.increment(getKey(), key, delta); } + @Override public Set keys() { return ops.keys(getKey()); } + @Override public Long size() { return ops.size(getKey()); } + @Override public void putAll(Map m) { ops.putAll(getKey(), m); } + @Override public void put(HK key, HV value) { ops.put(getKey(), key, value); } + @Override public Boolean putIfAbsent(HK key, HV value) { return ops.putIfAbsent(getKey(), key, value); } + @Override public Collection values() { return ops.values(getKey()); } + @Override public Map entries() { return ops.entries(getKey()); } + @Override public DataType getType() { return DataType.HASH; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java index f0b59e444..105c6e48b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundKeyOperations.java @@ -35,6 +35,7 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { this.ops = operations; } + @Override public K getKey() { return key; } @@ -43,22 +44,27 @@ abstract class DefaultBoundKeyOperations implements BoundKeyOperations { this.key = key; } + @Override public Boolean expire(long timeout, TimeUnit unit) { return ops.expire(key, timeout, unit); } + @Override public Boolean expireAt(Date date) { return ops.expireAt(key, date); } + @Override public Long getExpire() { return ops.getExpire(key); } + @Override public Boolean persist() { return ops.persist(key); } + @Override public void rename(K newKey) { ops.rename(key, newKey); key = newKey; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java index b8610cf7c..45a34511c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java @@ -42,74 +42,92 @@ class DefaultBoundListOperations extends DefaultBoundKeyOperations impl } + @Override public RedisOperations getOperations() { return ops.getOperations(); } + @Override public V index(long index) { return ops.index(getKey(), index); } + @Override public V leftPop() { return ops.leftPop(getKey()); } + @Override public V leftPop(long timeout, TimeUnit unit) { return ops.leftPop(getKey(), timeout, unit); } + @Override public Long leftPush(V value) { return ops.leftPush(getKey(), value); } + @Override public Long leftPushIfPresent(V value) { return ops.leftPushIfPresent(getKey(), value); } + @Override public Long leftPush(V pivot, V value) { return ops.leftPush(getKey(), pivot, value); } + @Override public Long size() { return ops.size(getKey()); } + @Override public List range(long start, long end) { return ops.range(getKey(), start, end); } + @Override public Long remove(long i, Object value) { return ops.remove(getKey(), i, value); } + @Override public V rightPop() { return ops.rightPop(getKey()); } + @Override public V rightPop(long timeout, TimeUnit unit) { return ops.rightPop(getKey(), timeout, unit); } + @Override public Long rightPushIfPresent(V value) { return ops.rightPushIfPresent(getKey(), value); } + @Override public Long rightPush(V value) { return ops.rightPush(getKey(), value); } + @Override public Long rightPush(V pivot, V value) { return ops.rightPush(getKey(), pivot, value); } + @Override public void trim(long start, long end) { ops.trim(getKey(), start, end); } + @Override public void set(long index, V value) { ops.set(getKey(), index, value); } + @Override public DataType getType() { return DataType.LIST; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java index 2ae41a5d5..d0010b63a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundSetOperations.java @@ -42,92 +42,114 @@ class DefaultBoundSetOperations extends DefaultBoundKeyOperations imple this.ops = operations.opsForSet(); } + @Override public Boolean add(V value) { return ops.add(getKey(), value); } + @Override public Set diff(K key) { return ops.difference(getKey(), key); } + @Override public Set diff(Collection keys) { return ops.difference(getKey(), keys); } + @Override public void diffAndStore(K key, K destKey) { ops.differenceAndStore(getKey(), key, destKey); } + @Override public void diffAndStore(Collection keys, K destKey) { ops.differenceAndStore(getKey(), keys, destKey); } + @Override public RedisOperations getOperations() { return ops.getOperations(); } + @Override public Set intersect(K key) { return ops.intersect(getKey(), key); } + @Override public Set intersect(Collection keys) { return ops.intersect(getKey(), keys); } + @Override public void intersectAndStore(K key, K destKey) { ops.intersectAndStore(getKey(), key, destKey); } + @Override public void intersectAndStore(Collection keys, K destKey) { ops.intersectAndStore(getKey(), keys, destKey); } + @Override public Boolean isMember(Object o) { return ops.isMember(getKey(), o); } + @Override public Set members() { return ops.members(getKey()); } + @Override public Boolean move(K destKey, V value) { return ops.move(getKey(), value, destKey); } + @Override public V randomMember() { return ops.randomMember(getKey()); } + @Override public Boolean remove(Object o) { return ops.remove(getKey(), o); } + @Override public V pop() { return ops.pop(getKey()); } + @Override public Long size() { return ops.size(getKey()); } + @Override public Set union(K key) { return ops.union(getKey(), key); } + @Override public Set union(Collection keys) { return ops.union(getKey(), keys); } + @Override public void unionAndStore(K key, K destKey) { ops.unionAndStore(getKey(), key, destKey); } + @Override public void unionAndStore(Collection keys, K destKey) { ops.unionAndStore(getKey(), keys, destKey); } + @Override public DataType getType() { return DataType.SET; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java index 69a80fce6..b9ec6b168 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundValueOperations.java @@ -37,50 +37,62 @@ class DefaultBoundValueOperations extends DefaultBoundKeyOperations imp this.ops = operations.opsForValue(); } + @Override public V get() { return ops.get(getKey()); } + @Override public V getAndSet(V value) { return ops.getAndSet(getKey(), value); } + @Override public Long increment(long delta) { return ops.increment(getKey(), delta); } + @Override public Integer append(String value) { return ops.append(getKey(), value); } + @Override public String get(long start, long end) { return ops.get(getKey(), start, end); } + @Override public void set(V value, long timeout, TimeUnit unit) { ops.set(getKey(), value, timeout, unit); } + @Override public void set(V value) { ops.set(getKey(), value); } + @Override public Boolean setIfAbsent(V value) { return ops.setIfAbsent(getKey(), value); } + @Override public void set(V value, long offset) { ops.set(getKey(), value, offset); } + @Override public Long size() { return ops.size(getKey()); } + @Override public RedisOperations getOperations() { return ops.getOperations(); } + @Override public DataType getType() { return DataType.STRING; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java index 6adf9d4b6..71590d863 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundZSetOperations.java @@ -41,78 +41,97 @@ class DefaultBoundZSetOperations extends DefaultBoundKeyOperations impl this.ops = operations.opsForZSet(); } + @Override public Boolean add(V value, double score) { return ops.add(getKey(), value, score); } + @Override public Double incrementScore(V value, double delta) { return ops.incrementScore(getKey(), value, delta); } + @Override public RedisOperations getOperations() { return ops.getOperations(); } + @Override public void intersectAndStore(K destKey, K otherKey) { ops.intersectAndStore(getKey(), otherKey, destKey); } + @Override public void intersectAndStore(Collection otherKeys, K destKey) { ops.intersectAndStore(getKey(), otherKeys, destKey); } + @Override public Set range(long start, long end) { return ops.range(getKey(), start, end); } + @Override public Set rangeByScore(double min, double max) { return ops.rangeByScore(getKey(), min, max); } + @Override public Long rank(Object o) { return ops.rank(getKey(), o); } + @Override public Long reverseRank(Object o) { return ops.reverseRank(getKey(), o); } + @Override public Double score(Object o) { return ops.score(getKey(), o); } + @Override public Boolean remove(Object o) { return ops.remove(getKey(), o); } + @Override public void removeRange(long start, long end) { ops.removeRange(getKey(), start, end); } + @Override public void removeRangeByScore(double min, double max) { ops.removeRangeByScore(getKey(), min, max); } + @Override public Set reverseRange(long start, long end) { return ops.reverseRange(getKey(), start, end); } + @Override public Long count(double min, double max) { return ops.count(getKey(), min, max); } + @Override public Long size() { return ops.size(getKey()); } + @Override public void unionAndStore(K otherKey, K destKey) { ops.unionAndStore(getKey(), otherKey, destKey); } + @Override public void unionAndStore(Collection otherKeys, K destKey) { ops.unionAndStore(getKey(), otherKeys, destKey); } + @Override public DataType getType() { return DataType.ZSET; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java index ab62fe1bf..afe1def4f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultHashOperations.java @@ -37,11 +37,13 @@ class DefaultHashOperations extends AbstractOperations imp } @SuppressWarnings("unchecked") + @Override public HV get(K key, Object hashKey) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); byte[] rawHashValue = execute(new RedisCallback() { + @Override public byte[] doInRedis(RedisConnection connection) { return connection.hGet(rawKey, rawHashKey); } @@ -50,22 +52,26 @@ class DefaultHashOperations extends AbstractOperations imp return (HV) deserializeHashValue(rawHashValue); } + @Override public Boolean hasKey(K key, Object hashKey) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.hExists(rawKey, rawHashKey); } }, true); } + @Override public Long increment(K key, HK hashKey, final long delta) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.hIncrBy(rawKey, rawHashKey, delta); } @@ -73,10 +79,12 @@ class DefaultHashOperations extends AbstractOperations imp } + @Override public Set keys(K key) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { + @Override public Set doInRedis(RedisConnection connection) { return connection.hKeys(rawKey); } @@ -85,16 +93,19 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashKeys(rawValues); } + @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.hLen(rawKey); } }, true); } + @Override public void putAll(K key, Map m) { if (m.isEmpty()) { return; @@ -109,6 +120,7 @@ class DefaultHashOperations extends AbstractOperations imp } execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.hMSet(rawKey, hashes); return null; @@ -117,6 +129,7 @@ class DefaultHashOperations extends AbstractOperations imp } + @Override public Collection multiGet(K key, Collection fields) { if (fields.isEmpty()) { return Collections.emptyList(); @@ -132,6 +145,7 @@ class DefaultHashOperations extends AbstractOperations imp } List rawValues = execute(new RedisCallback>() { + @Override public List doInRedis(RedisConnection connection) { return connection.hMGet(rawKey, rawHashKeys); } @@ -140,12 +154,14 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashValues(rawValues); } + @Override 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() { + @Override public Object doInRedis(RedisConnection connection) { connection.hSet(rawKey, rawHashKey, rawHashValue); return null; @@ -153,12 +169,14 @@ class DefaultHashOperations extends AbstractOperations imp }, true); } + @Override 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() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.hSetNX(rawKey, rawHashKey, rawHashValue); } @@ -166,10 +184,12 @@ class DefaultHashOperations extends AbstractOperations imp } + @Override public List values(K key) { final byte[] rawKey = rawKey(key); List rawValues = execute(new RedisCallback>() { + @Override public List doInRedis(RedisConnection connection) { return connection.hVals(rawKey); } @@ -178,11 +198,13 @@ class DefaultHashOperations extends AbstractOperations imp return deserializeHashValues(rawValues); } + @Override public void delete(K key, Object hashKey) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.hDel(rawKey, rawHashKey); return null; @@ -190,10 +212,12 @@ class DefaultHashOperations extends AbstractOperations imp }, true); } + @Override public Map entries(K key) { final byte[] rawKey = rawKey(key); Map entries = execute(new RedisCallback>() { + @Override public Map doInRedis(RedisConnection connection) { return connection.hGetAll(rawKey); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java index 7c397b4e9..b6c67936f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultListOperations.java @@ -32,6 +32,7 @@ class DefaultListOperations extends AbstractOperations implements Li super(template); } + @Override public V index(K key, final long index) { return execute(new ValueDeserializingRedisCallback(key) { @Override @@ -41,6 +42,7 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } + @Override public V leftPop(K key) { return execute(new ValueDeserializingRedisCallback(key) { @Override @@ -50,6 +52,7 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } + @Override public V leftPop(K key, long timeout, TimeUnit unit) { final int tm = (int) unit.toSeconds(timeout); @@ -61,65 +64,79 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } + @Override public Long leftPush(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.lPush(rawKey, rawValue); } }, true); } + @Override public Long leftPushIfPresent(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.lPushX(rawKey, rawValue); } }, true); } + @Override 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() { + @Override public Long doInRedis(RedisConnection connection) { return connection.lInsert(rawKey, Position.BEFORE, rawPivot, rawValue); } }, true); } + @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.lLen(rawKey); } }, true); } + @Override public List range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback>() { + @SuppressWarnings("unchecked") + @Override public List doInRedis(RedisConnection connection) { return deserializeValues(connection.lRange(rawKey, start, end)); } }, true); } + @Override public Long remove(K key, final long count, Object value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.lRem(rawKey, count, rawValue); } }, true); } + @Override public V rightPop(K key) { return execute(new ValueDeserializingRedisCallback(key) { @Override @@ -129,6 +146,7 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } + @Override public V rightPop(K key, long timeout, TimeUnit unit) { final int tm = (int) unit.toSeconds(timeout); @@ -140,38 +158,45 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } + @Override public Long rightPush(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.rPush(rawKey, rawValue); } }, true); } + @Override public Long rightPushIfPresent(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.rPushX(rawKey, rawValue); } }, true); } + @Override 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() { + @Override public Long doInRedis(RedisConnection connection) { return connection.lInsert(rawKey, Position.AFTER, rawPivot, rawValue); } }, true); } + @Override public V rightPopAndLeftPush(K sourceKey, K destinationKey) { final byte[] rawDestKey = rawKey(destinationKey); @@ -183,6 +208,7 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } + @Override public V rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit) { final int tm = (int) unit.toSeconds(timeout); final byte[] rawDestKey = rawKey(destinationKey); @@ -195,6 +221,7 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } + @Override public void set(K key, final long index, V value) { final byte[] rawValue = rawValue(value); execute(new ValueDeserializingRedisCallback(key) { @@ -206,6 +233,7 @@ class DefaultListOperations extends AbstractOperations implements Li }, true); } + @Override public void trim(K key, final long start, final long end) { execute(new ValueDeserializingRedisCallback(key) { @Override diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java index 845162d76..a4893104f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultSetOperations.java @@ -32,23 +32,29 @@ class DefaultSetOperations extends AbstractOperations implements Set super(template); } + @Override public Boolean add(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.sAdd(rawKey, rawValue); } }, true); } + @Override public Set difference(K key, K otherKey) { return difference(key, Collections.singleton(otherKey)); } + @SuppressWarnings("unchecked") + @Override public Set difference(final K key, final Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { + @Override public Set doInRedis(RedisConnection connection) { return connection.sDiff(rawKeys); } @@ -57,14 +63,17 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } + @Override public void differenceAndStore(K key, K otherKey, K destKey) { differenceAndStore(key, Collections.singleton(otherKey), destKey); } + @Override public void differenceAndStore(final K key, final Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.sDiffStore(rawDestKey, rawKeys); return null; @@ -72,13 +81,17 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } + @Override public Set intersect(K key, K otherKey) { return intersect(key, Collections.singleton(otherKey)); } + @SuppressWarnings("unchecked") + @Override public Set intersect(K key, Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { + @Override public Set doInRedis(RedisConnection connection) { return connection.sInter(rawKeys); } @@ -87,14 +100,17 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } + @Override public void intersectAndStore(K key, K otherKey, K destKey) { intersectAndStore(key, Collections.singleton(otherKey), destKey); } + @Override public void intersectAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.sInterStore(rawDestKey, rawKeys); return null; @@ -102,19 +118,24 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } + @Override public Boolean isMember(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.sIsMember(rawKey, rawValue); } }, true); } + @SuppressWarnings("unchecked") + @Override public Set members(K key) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { + @Override public Set doInRedis(RedisConnection connection) { return connection.sMembers(rawKey); } @@ -123,18 +144,21 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } + @Override 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() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.sMove(rawKey, rawDestKey, rawValue); } }, true); } + @Override public V randomMember(K key) { return execute(new ValueDeserializingRedisCallback(key) { @@ -145,16 +169,19 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } + @Override public Boolean remove(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.sRem(rawKey, rawValue); } }, true); } + @Override public V pop(K key) { return execute(new ValueDeserializingRedisCallback(key) { @Override @@ -164,22 +191,28 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } + @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.sCard(rawKey); } }, true); } + @Override public Set union(K key, K otherKey) { return union(key, Collections.singleton(otherKey)); } + @SuppressWarnings("unchecked") + @Override public Set union(K key, Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { + @Override public Set doInRedis(RedisConnection connection) { return connection.sUnion(rawKeys); } @@ -188,14 +221,17 @@ class DefaultSetOperations extends AbstractOperations implements Set return deserializeValues(rawValues); } + @Override public void unionAndStore(K key, K otherKey, K destKey) { unionAndStore(key, Collections.singleton(otherKey), destKey); } + @Override public void unionAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.sUnionStore(rawDestKey, rawKeys); return null; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java index 3d162933d..bc2c13d0d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultValueOperations.java @@ -36,6 +36,7 @@ class DefaultValueOperations extends AbstractOperations implements V super(template); } + @Override public V get(final Object key) { return execute(new ValueDeserializingRedisCallback(key) { @@ -46,6 +47,7 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } + @Override public V getAndSet(K key, V newValue) { final byte[] rawValue = rawValue(newValue); return execute(new ValueDeserializingRedisCallback(key) { @@ -56,10 +58,12 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } + @Override public Long increment(K key, final long delta) { final byte[] rawKey = rawKey(key); // TODO add conversion service in here ? return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { if (delta == 1) { return connection.incr(rawKey); @@ -78,21 +82,25 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } + @Override public Integer append(K key, String value) { final byte[] rawKey = rawKey(key); final byte[] rawString = rawString(value); return execute(new RedisCallback() { + @Override public Integer doInRedis(RedisConnection connection) { return connection.append(rawKey, rawString).intValue(); } }, true); } + @Override public String get(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); byte[] rawReturn = execute(new RedisCallback() { + @Override public byte[] doInRedis(RedisConnection connection) { return connection.getRange(rawKey, start, end); } @@ -101,6 +109,8 @@ class DefaultValueOperations extends AbstractOperations implements V return deserializeString(rawReturn); } + @SuppressWarnings("unchecked") + @Override public List multiGet(Collection keys) { if (keys.isEmpty()) { return Collections.emptyList(); @@ -114,6 +124,7 @@ class DefaultValueOperations extends AbstractOperations implements V } List rawValues = execute(new RedisCallback>() { + @Override public List doInRedis(RedisConnection connection) { return connection.mGet(rawKeys); } @@ -122,6 +133,7 @@ class DefaultValueOperations extends AbstractOperations implements V return deserializeValues(rawValues); } + @Override public void multiSet(Map m) { if (m.isEmpty()) { return; @@ -134,6 +146,7 @@ class DefaultValueOperations extends AbstractOperations implements V } execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.mSet(rawKeys); return null; @@ -141,6 +154,7 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } + @Override public void multiSetIfAbsent(Map m) { if (m.isEmpty()) { return; @@ -153,6 +167,7 @@ class DefaultValueOperations extends AbstractOperations implements V } execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.mSetNX(rawKeys); return null; @@ -160,6 +175,7 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } + @Override public void set(K key, V value) { final byte[] rawValue = rawValue(value); execute(new ValueDeserializingRedisCallback(key) { @@ -171,12 +187,14 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } + @Override public void set(K key, V value, long timeout, TimeUnit unit) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); final long rawTimeout = unit.toSeconds(timeout); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.setEx(rawKey, (int) rawTimeout, rawValue); return null; @@ -184,11 +202,13 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } + @Override public Boolean setIfAbsent(K key, V value) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) throws DataAccessException { return connection.setNX(rawKey, rawValue); } @@ -196,11 +216,13 @@ class DefaultValueOperations extends AbstractOperations implements V } + @Override public void set(K key, final V value, final long offset) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.setRange(rawKey, rawValue, offset); return null; @@ -208,10 +230,12 @@ class DefaultValueOperations extends AbstractOperations implements V }, true); } + @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.strLen(rawKey); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java index b1f96af0c..154163fe7 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultZSetOperations.java @@ -32,36 +32,43 @@ class DefaultZSetOperations extends AbstractOperations implements ZS super(template); } + @Override public Boolean add(final K key, final V value, final double score) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.zAdd(rawKey, score, rawValue); } }, true); } + @Override public Double incrementScore(K key, V value, final double delta) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); return execute(new RedisCallback() { + @Override public Double doInRedis(RedisConnection connection) { return connection.zIncrBy(rawKey, delta, rawValue); } }, true); } + @Override public void intersectAndStore(K key, K otherKey, K destKey) { intersectAndStore(key, Collections.singleton(otherKey), destKey); } + @Override public void intersectAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.zInterStore(rawDestKey, rawKeys); return null; @@ -69,10 +76,13 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } + @SuppressWarnings("unchecked") + @Override public Set range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { + @Override public Set doInRedis(RedisConnection connection) { return connection.zRange(rawKey, start, end); } @@ -81,10 +91,13 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } + @SuppressWarnings("unchecked") + @Override public Set rangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { + @Override public Set doInRedis(RedisConnection connection) { return connection.zRangeByScore(rawKey, min, max); } @@ -93,11 +106,13 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } + @Override public Long rank(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { Long zRank = connection.zRank(rawKey, rawValue); return (zRank != null && zRank.longValue() >= 0 ? zRank : null); @@ -105,11 +120,13 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } + @Override public Long reverseRank(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { Long zRank = connection.zRevRank(rawKey, rawValue); return (zRank != null && zRank.longValue() >= 0 ? zRank : null); @@ -117,20 +134,24 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } + @Override public Boolean remove(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.zRem(rawKey, rawValue); } }, true); } + @Override public void removeRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.zRemRange(rawKey, start, end); return null; @@ -138,9 +159,11 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } + @Override public void removeRangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.zRemRangeByScore(rawKey, min, max); return null; @@ -148,10 +171,13 @@ class DefaultZSetOperations extends AbstractOperations implements ZS }, true); } + @SuppressWarnings("unchecked") + @Override public Set reverseRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { + @Override public Set doInRedis(RedisConnection connection) { return connection.zRevRange(rawKey, start, end); } @@ -160,45 +186,54 @@ class DefaultZSetOperations extends AbstractOperations implements ZS return deserializeValues(rawValues); } + @Override public Double score(K key, Object o) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(o); return execute(new RedisCallback() { + @Override public Double doInRedis(RedisConnection connection) { return connection.zScore(rawKey, rawValue); } }, true); } + @Override public Long count(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.zCount(rawKey, min, max); } }, true); } + @Override public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return connection.zCard(rawKey); } }, true); } + @Override public void unionAndStore(K key, K otherKey, K destKey) { unionAndStore(key, Collections.singleton(otherKey), destKey); } + @Override public void unionAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.zUnionStore(rawDestKey, rawKeys); return null; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisConnectionUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisConnectionUtils.java index 9778c81d9..b0799b82a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisConnectionUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisConnectionUtils.java @@ -173,6 +173,7 @@ public abstract class RedisConnectionUtils { this.conn = conn; } + @Override public boolean isVoid() { return isVoid; } @@ -181,10 +182,12 @@ public abstract class RedisConnectionUtils { return conn; } + @Override public void reset() { // no-op } + @Override public void unbound() { this.isVoid = true; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index fc0cd8c2a..d3565d996 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -133,6 +133,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation zSetOps = new DefaultZSetOperations(this); } + @Override public T execute(RedisCallback action) { return execute(action, isExposeConnection()); } @@ -191,6 +192,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } + @Override public T execute(SessionCallback session) { RedisConnectionFactory factory = getConnectionFactory(); // bind connection @@ -423,19 +425,23 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // // RedisOperations // + @Override public List exec() { return execute(new RedisCallback>() { + @Override public List doInRedis(RedisConnection connection) throws DataAccessException { return connection.exec(); } }); } + @Override public void delete(K key) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.del(rawKey); return null; @@ -443,10 +449,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @Override public void delete(Collection keys) { final byte[][] rawKeys = rawKeys(keys); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.del(rawKeys); return null; @@ -454,38 +462,45 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @Override public Boolean hasKey(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.exists(rawKey); } }, true); } + @Override public Boolean expire(K key, long timeout, TimeUnit unit) { final byte[] rawKey = rawKey(key); final int rawTimeout = (int) unit.toSeconds(timeout); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.expire(rawKey, rawTimeout); } }, true); } + @Override public Boolean expireAt(K key, Date date) { final byte[] rawKey = rawKey(key); final long rawTimeout = date.getTime(); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.expireAt(rawKey, rawTimeout); } }, true); } + @Override public void convertAndSend(String channel, Object message) { Assert.hasText(channel, "a non-empty channel is required"); @@ -493,6 +508,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation final byte[] rawMessage = rawValue(message); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.publish(rawChannel, rawMessage); return null; @@ -505,10 +521,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // Value operations // + @Override public Long getExpire(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) { return Long.valueOf(connection.ttl(rawKey)); } @@ -516,10 +534,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @SuppressWarnings("unchecked") + @Override public Set keys(K pattern) { final byte[] rawKey = rawKey(pattern); Collection rawKeys = execute(new RedisCallback>() { + @Override public Collection doInRedis(RedisConnection connection) { return connection.keys(rawKey); } @@ -528,28 +548,34 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return (Set) SerializationUtils.deserialize(rawKeys, keySerializer); } + @Override public Boolean persist(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.persist(rawKey); } }, true); } + @Override public Boolean move(K key, final int dbIndex) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.move(rawKey, dbIndex); } }, true); } + @Override public K randomKey() { byte[] rawKey = execute(new RedisCallback() { + @Override public byte[] doInRedis(RedisConnection connection) { return connection.randomKey(); } @@ -558,11 +584,13 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return deserializeKey(rawKey); } + @Override public void rename(K oldKey, K newKey) { final byte[] rawOldKey = rawKey(oldKey); final byte[] rawNewKey = rawKey(newKey); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.rename(rawOldKey, rawNewKey); return null; @@ -570,29 +598,35 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @Override public Boolean renameIfAbsent(K oldKey, K newKey) { final byte[] rawOldKey = rawKey(oldKey); final byte[] rawNewKey = rawKey(newKey); return execute(new RedisCallback() { + @Override public Boolean doInRedis(RedisConnection connection) { return connection.renameNX(rawOldKey, rawNewKey); } }, true); } + @Override public DataType type(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback() { + @Override public DataType doInRedis(RedisConnection connection) { return connection.type(rawKey); } }, true); } + @Override public void multi() { execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.multi(); return null; @@ -600,9 +634,11 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @Override public void discard() { execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.discard(); return null; @@ -610,10 +646,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @Override public void watch(K key) { final byte[] rawKey = rawKey(key); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.watch(rawKey); return null; @@ -621,10 +659,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @Override public void watch(Collection keys) { final byte[][] rawKeys = rawKeys(keys); execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) { connection.watch(rawKeys); return null; @@ -632,8 +672,10 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } + @Override public void unwatch() { execute(new RedisCallback() { + @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.unwatch(); return null; @@ -644,15 +686,18 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation // Sort operations @SuppressWarnings("unchecked") + @Override public List sort(SortQuery query) { return sort(query, valueSerializer); } + @Override public List sort(SortQuery query, RedisSerializer resultSerializer) { final byte[] rawKey = rawKey(query.getKey()); final SortParameters params = QueryUtils.convertQuery(query, stringSerializer); List vals = execute(new RedisCallback>() { + @Override public List doInRedis(RedisConnection connection) throws DataAccessException { return connection.sort(rawKey, params); } @@ -662,10 +707,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation } @SuppressWarnings("unchecked") + @Override public List sort(SortQuery query, BulkMapper bulkMapper) { return sort(query, bulkMapper, valueSerializer); } + @Override public List sort(SortQuery query, BulkMapper bulkMapper, RedisSerializer resultSerializer) { List values = sort(query, resultSerializer); @@ -686,54 +733,66 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return result; } + @Override public Long sort(SortQuery query, K storeKey) { final byte[] rawStoreKey = rawKey(storeKey); final byte[] rawKey = rawKey(query.getKey()); final SortParameters params = QueryUtils.convertQuery(query, stringSerializer); return execute(new RedisCallback() { + @Override public Long doInRedis(RedisConnection connection) throws DataAccessException { return connection.sort(rawKey, params, rawStoreKey); } }, true); } + @Override public BoundValueOperations boundValueOps(K key) { return new DefaultBoundValueOperations(key, this); } + @Override public ValueOperations opsForValue() { return valueOps; } + @Override public ListOperations opsForList() { return listOps; } + @Override public BoundListOperations boundListOps(K key) { return new DefaultBoundListOperations(key, this); } + @Override public BoundSetOperations boundSetOps(K key) { return new DefaultBoundSetOperations(key, this); } + @Override public SetOperations opsForSet() { return setOps; } + @Override public BoundZSetOperations boundZSetOps(K key) { return new DefaultBoundZSetOperations(key, this); } + @Override public ZSetOperations opsForZSet() { return zSetOps; } + @Override public BoundHashOperations boundHashOps(K key) { return new DefaultBoundHashOperations(key, this); } + @Override public HashOperations opsForHash() { return new DefaultHashOperations(this); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortCriterion.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortCriterion.java index 89ee8a58b..242a7af6e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortCriterion.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortCriterion.java @@ -40,30 +40,36 @@ class DefaultSortCriterion implements SortCriterion { this.key = key; } + @Override public SortCriterion alphabetical(boolean alpha) { this.alpha = Boolean.valueOf(alpha); return this; } + @Override public SortQuery build() { return new DefaultSortQuery(key, by, limit, order, alpha, getKeys); } + @Override public SortCriterion limit(long offset, long count) { this.limit = new Range(offset, count); return this; } + @Override public SortCriterion limit(Range range) { this.limit = range; return this; } + @Override public SortCriterion order(Order order) { this.order = order; return this; } + @Override public SortCriterion get(String getPattern) { this.getKeys.add(getPattern); return this; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortQuery.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortQuery.java index df78766ce..4348e2fa2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortQuery.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/query/DefaultSortQuery.java @@ -43,26 +43,32 @@ class DefaultSortQuery implements SortQuery { this.gets = gets; } + @Override public String getBy() { return by; } + @Override public Range getLimit() { return limit; } + @Override public Order getOrder() { return order; } + @Override public Boolean isAlphabetic() { return alpha; } + @Override public K getKey() { return key; } + @Override public List getGetPattern() { return gets; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/BeanUtilsHashMapper.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/BeanUtilsHashMapper.java index 7d6dcdc32..1283eb26e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/BeanUtilsHashMapper.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/BeanUtilsHashMapper.java @@ -32,6 +32,7 @@ public class BeanUtilsHashMapper implements HashMapper { this.type = type; } + @Override public T fromHash(Map hash) { T instance = org.springframework.beans.BeanUtils.instantiate(type); try { @@ -42,6 +43,7 @@ public class BeanUtilsHashMapper implements HashMapper { return instance; } + @Override public Map toHash(T object) { try { return BeanUtils.describe(object); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/DecoratingStringHashMapper.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/DecoratingStringHashMapper.java index 15867a059..378203134 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/DecoratingStringHashMapper.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/DecoratingStringHashMapper.java @@ -33,11 +33,13 @@ public class DecoratingStringHashMapper implements HashMapper hash) { Map h = hash; return delegate.fromHash(h); } + @Override public Map toHash(T object) { Map hash = delegate.toHash(object); Map flatten = new LinkedHashMap(hash.size()); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java index 07fd112b8..1f4d0d105 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/hash/JacksonHashMapper.java @@ -42,10 +42,12 @@ public class JacksonHashMapper implements HashMapper { } @SuppressWarnings("unchecked") + @Override public T fromHash(Map hash) { return (T) mapper.convertValue(hash, userType); } + @Override public Map toHash(T object) { return mapper.convertValue(object, mapType); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java index 6905bf532..0691b8363 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/RedisMessageListenerContainer.java @@ -110,6 +110,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private volatile RedisSerializer serializer = new StringRedisSerializer(); + @Override public void afterPropertiesSet() { if (taskExecutor == null) { manageExecutor = true; @@ -136,6 +137,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab return new SimpleAsyncTaskExecutor(threadNamePrefix); } + @Override public void destroy() throws Exception { initialized = false; @@ -152,24 +154,29 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } + @Override public boolean isAutoStartup() { return true; } + @Override public void stop(Runnable callback) { stop(); callback.run(); } + @Override public int getPhase() { // start the latest return Integer.MAX_VALUE; } + @Override public boolean isRunning() { return running; } + @Override public void start() { if (!running) { running = true; @@ -191,6 +198,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab } } + @Override public void stop() { if (isRunning()) { running = false; @@ -293,6 +301,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab this.connectionFactory = connectionFactory; } + @Override public void setBeanName(String name) { this.beanName = name; } @@ -501,10 +510,12 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private long WAIT = 500; private long ROUNDS = 3; + @Override public boolean isLongLived() { return false; } + @Override public void run() { // wait for subscription to be initialized boolean done = false; @@ -532,10 +543,12 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private volatile RedisConnection connection; private final Object localMonitor = new Object(); + @Override public boolean isLongLived() { return true; } + @Override public void run() { connection = connectionFactory.getConnection(); try { @@ -682,6 +695,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab */ private class DispatchMessageListener implements MessageListener { + @Override public void onMessage(Message message, byte[] pattern) { // do channel matching first byte[] channel = message.getChannel(); @@ -706,6 +720,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private void dispatchChannels(Collection ch, final Message message) { for (final MessageListener messageListener : ch) { taskExecutor.execute(new Runnable() { + @Override public void run() { processMessage(messageListener, message, null); } @@ -716,6 +731,7 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab private void dispatchPatterns(Collection pt, final Message message, final byte[] pattern) { for (final MessageListener messageListener : pt) { taskExecutor.execute(new Runnable() { + @Override public void run() { processMessage(messageListener, message, pattern.clone()); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java index 3c30f340a..8def8aa52 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/listener/adapter/MessageListenerAdapter.java @@ -23,6 +23,7 @@ import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.keyvalue.redis.connection.Message; import org.springframework.data.keyvalue.redis.connection.MessageListener; +import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.keyvalue.redis.serializer.RedisSerializer; import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer; import org.springframework.util.Assert; @@ -165,6 +166,8 @@ public class MessageListenerAdapter implements MessageListener { * @param message the incoming Redis message * @see #handleListenerException */ + @Override + @SuppressWarnings("unchecked") public void onMessage(Message message, byte[] pattern) { try { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java index f3c5590b2..b53387366 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/GenericToStringSerializer.java @@ -64,6 +64,7 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac converter = new Converter(typeConverter); } + @Override public T deserialize(byte[] bytes) { if (bytes == null) { return null; @@ -73,6 +74,7 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac return converter.convert(string, type); } + @Override public byte[] serialize(T object) { if (object == null) { return null; @@ -81,6 +83,7 @@ public class GenericToStringSerializer implements RedisSerializer, BeanFac return string.getBytes(charset); } + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (converter == null && beanFactory instanceof ConfigurableBeanFactory) { ConfigurableBeanFactory cFB = (ConfigurableBeanFactory) beanFactory; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java index 8a7023805..c858cfcb2 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JacksonJsonRedisSerializer.java @@ -44,6 +44,7 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { } @SuppressWarnings("unchecked") + @Override public T deserialize(byte[] bytes) throws SerializationException { if (SerializationUtils.isEmpty(bytes)) { return null; @@ -55,6 +56,7 @@ public class JacksonJsonRedisSerializer implements RedisSerializer { } } + @Override public byte[] serialize(Object t) throws SerializationException { if (t == null) { return SerializationUtils.EMPTY_ARRAY; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java index 3c0c78626..fe6de7886 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/JdkSerializationRedisSerializer.java @@ -32,6 +32,7 @@ public class JdkSerializationRedisSerializer implements RedisSerializer private Converter deserializer = new DeserializingConverter(); @SuppressWarnings("unchecked") + @Override public Object deserialize(byte[] bytes) { if (SerializationUtils.isEmpty(bytes)) { return null; @@ -44,6 +45,7 @@ public class JdkSerializationRedisSerializer implements RedisSerializer } } + @Override public byte[] serialize(Object object) { if (object == null) { return SerializationUtils.EMPTY_ARRAY; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java index 5e6b7f1f4..b1a2354f8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/OxmSerializer.java @@ -50,6 +50,7 @@ public class OxmSerializer implements InitializingBean, RedisSerializer afterPropertiesSet(); } + @Override public void afterPropertiesSet() { Assert.notNull(marshaller, "non-null marshaller required"); Assert.notNull(unmarshaller, "non-null unmarshaller required"); @@ -69,6 +70,7 @@ public class OxmSerializer implements InitializingBean, RedisSerializer this.unmarshaller = unmarshaller; } + @Override public Object deserialize(byte[] bytes) throws SerializationException { if (SerializationUtils.isEmpty(bytes)) { return null; @@ -81,6 +83,7 @@ public class OxmSerializer implements InitializingBean, RedisSerializer } } + @Override public byte[] serialize(Object t) throws SerializationException { if (t == null) { return SerializationUtils.EMPTY_ARRAY; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java index e5edff977..d0b361ba1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/StringRedisSerializer.java @@ -42,10 +42,12 @@ public class StringRedisSerializer implements RedisSerializer { this.charset = charset; } + @Override public String deserialize(byte[] bytes) { return (bytes == null ? null : new String(bytes, charset)); } + @Override public byte[] serialize(String string) { return (string == null ? null : string.getBytes(charset)); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index b54e93b1d..bb4b19ba4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -162,6 +162,7 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey return generalOps.execute(new SessionCallback() { @SuppressWarnings("unchecked") + @Override public Boolean execute(RedisOperations operations) { for (;;) { operations.watch(Collections.singleton(key)); @@ -238,57 +239,59 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey * Returns the String representation of the current value. * @return the String representation of the current value. */ - @Override public String toString() { return Integer.toString(get()); } - @Override public int intValue() { return get(); } - @Override public long longValue() { - return get(); + return (long) get(); } - @Override public float floatValue() { - return get(); + return (float) get(); + } + + public double doubleValue() { + return (double) get(); } @Override - public double doubleValue() { - return get(); - } - public String getKey() { return key; } + @Override public Boolean expire(long timeout, TimeUnit unit) { return generalOps.expire(key, timeout, unit); } + @Override public Boolean expireAt(Date date) { return generalOps.expireAt(key, date); } + @Override public Long getExpire() { return generalOps.getExpire(key); } + @Override public Boolean persist() { return generalOps.persist(key); } + @Override public void rename(String newKey) { generalOps.rename(key, newKey); key = newKey; } + @Override public DataType getType() { return DataType.STRING; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 815aed698..5550b382d 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -162,6 +162,7 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe return generalOps.execute(new SessionCallback() { @SuppressWarnings("unchecked") + @Override public Boolean execute(RedisOperations operations) { for (;;) { operations.watch(Collections.singleton(key)); @@ -241,57 +242,59 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe * * @return the String representation of the current value. */ - @Override public String toString() { return Long.toString(get()); } - @Override public int intValue() { return (int) get(); } - @Override public long longValue() { return get(); } - @Override public float floatValue() { - return get(); + return (float) get(); + } + + public double doubleValue() { + return (double) get(); } @Override - public double doubleValue() { - return get(); - } - public String getKey() { return key; } + @Override public Boolean expire(long timeout, TimeUnit unit) { return generalOps.expire(key, timeout, unit); } + @Override public Boolean expireAt(Date date) { return generalOps.expireAt(key, date); } + @Override public Long getExpire() { return generalOps.getExpire(key); } + @Override public Boolean persist() { return generalOps.persist(key); } + @Override public void rename(String newKey) { generalOps.rename(key, newKey); key = newKey; } + @Override public DataType getType() { return DataType.STRING; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java index 5d19e2fe6..cb7c0c5df 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollection.java @@ -40,10 +40,12 @@ public abstract class AbstractRedisCollection extends AbstractCollection i this.operations = operations; } + @Override public String getKey() { return key; } + @Override public RedisOperations getOperations() { return operations; } @@ -57,10 +59,8 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return modified; } - @Override public abstract boolean add(E e); - @Override public abstract void clear(); @Override @@ -72,7 +72,6 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return contains; } - @Override public abstract boolean remove(Object o); @@ -85,7 +84,6 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return modified; } - @Override public boolean retainAll(Collection c) { throw new UnsupportedOperationException(); } @@ -121,22 +119,27 @@ public abstract class AbstractRedisCollection extends AbstractCollection i return sb.toString(); } + @Override public Boolean expire(long timeout, TimeUnit unit) { return operations.expire(key, timeout, unit); } + @Override public Boolean expireAt(Date date) { return operations.expireAt(key, date); } + @Override public Long getExpire() { return operations.getExpire(key); } + @Override public Boolean persist() { return operations.persist(key); } + @Override public void rename(final String newKey) { CollectionUtils.rename(key, newKey, operations); key = newKey; diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java index 047a675b2..e98c8287a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/CollectionUtils.java @@ -56,6 +56,7 @@ abstract class CollectionUtils { static void rename(final K key, final K newKey, RedisOperations operations) { operations.execute(new SessionCallback() { @SuppressWarnings("unchecked") + @Override public Object execute(RedisOperations operations) throws DataAccessException { do { operations.watch(key); @@ -75,6 +76,7 @@ abstract class CollectionUtils { static Boolean renameIfAbsent(final K key, final K newKey, RedisOperations operations) { return operations.execute(new SessionCallback() { + @Override public Boolean execute(RedisOperations operations) throws DataAccessException { List exec = null; do { diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java index ba1697ff2..6149838c4 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisList.java @@ -47,6 +47,8 @@ public class DefaultRedisList extends AbstractRedisCollection implements R private volatile boolean capped = false; + private volatile long defaultWait = 0; + private class DefaultRedisListIterator extends RedisIterator { public DefaultRedisListIterator(Iterator delegate) { @@ -100,10 +102,12 @@ public class DefaultRedisList extends AbstractRedisCollection implements R capped = (maxSize > 0); } + @Override public List range(long start, long end) { return listOps.range(start, end); } + @Override public RedisList trim(int start, int end) { listOps.trim(start, end); return this; @@ -149,6 +153,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return (result != null && result.longValue() > 0); } + @Override public void add(int index, E element) { if (index == 0) { listOps.leftPush(element); @@ -171,6 +176,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R throw new IllegalArgumentException("Redis supports insertion only at the beginning or the end of the list"); } + @Override public boolean addAll(int index, Collection c) { // insert collection in reverse if (index == 0) { @@ -200,6 +206,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R throw new IllegalArgumentException("Redis supports insertion only at the beginning or the end of the list"); } + @Override public E get(int index) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException(); @@ -207,33 +214,40 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return listOps.index(index); } + @Override public int indexOf(Object o) { throw new UnsupportedOperationException(); } + @Override public int lastIndexOf(Object o) { throw new UnsupportedOperationException(); } + @Override public ListIterator listIterator() { throw new UnsupportedOperationException(); } + @Override public ListIterator listIterator(int index) { throw new UnsupportedOperationException(); } + @Override public E remove(int index) { throw new UnsupportedOperationException(); } + @Override public E set(int index, E e) { E object = get(index); listOps.set(index, e); return object; } + @Override public List subList(int fromIndex, int toIndex) { throw new UnsupportedOperationException(); } @@ -242,6 +256,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // Queue methods // + @Override public E element() { E value = peek(); if (value == null) @@ -251,6 +266,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R } + @Override public boolean offer(E e) { listOps.rightPush(e); cap(); @@ -258,16 +274,19 @@ public class DefaultRedisList extends AbstractRedisCollection implements R } + @Override public E peek() { return listOps.index(0); } + @Override public E poll() { return listOps.leftPop(); } + @Override public E remove() { E value = poll(); if (value == null) @@ -280,25 +299,30 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // Dequeue // + @Override public void addFirst(E e) { listOps.leftPush(e); cap(); } + @Override public void addLast(E e) { add(e); } + @Override public Iterator descendingIterator() { List content = content(); Collections.reverse(content); return new DefaultRedisListIterator(content.iterator()); } + @Override public E getFirst() { return element(); } + @Override public E getLast() { E e = peekLast(); if (e == null) { @@ -307,32 +331,39 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } + @Override public boolean offerFirst(E e) { addFirst(e); return true; } + @Override public boolean offerLast(E e) { addLast(e); return true; } + @Override public E peekFirst() { return peek(); } + @Override public E peekLast() { return listOps.index(-1); } + @Override public E pollFirst() { return poll(); } + @Override public E pollLast() { return listOps.rightPop(); } + @Override public E pop() { E e = poll(); if (e == null) { @@ -341,18 +372,22 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } + @Override public void push(E e) { addFirst(e); } + @Override public E removeFirst() { return pop(); } + @Override public boolean removeFirstOccurrence(Object o) { return remove(o); } + @Override public E removeLast() { E e = pollLast(); if (e == null) { @@ -361,6 +396,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return e; } + @Override public boolean removeLastOccurrence(Object o) { Long result = listOps.remove(-1, o); return (result != null && result.longValue() > 0); @@ -371,6 +407,7 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // BlockingQueue // + @Override public int drainTo(Collection c, int maxElements) { if (this.equals(c)) { throw new IllegalArgumentException("Cannot drain a queue to itself"); @@ -386,27 +423,33 @@ public class DefaultRedisList extends AbstractRedisCollection implements R return loop; } + @Override public int drainTo(Collection c) { return drainTo(c, size()); } + @Override public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { return offer(e); } + @Override public E poll(long timeout, TimeUnit unit) throws InterruptedException { E element = listOps.leftPop(timeout, unit); return (element == null ? null : element); } + @Override public void put(E e) throws InterruptedException { offer(e); } + @Override public int remainingCapacity() { return Integer.MAX_VALUE; } + @Override public E take() throws InterruptedException { return poll(0, TimeUnit.SECONDS); } @@ -416,39 +459,48 @@ public class DefaultRedisList extends AbstractRedisCollection implements R // BlockingDeque // + @Override public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException { return offerFirst(e); } + @Override public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException { return offerLast(e); } + @Override public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException { return poll(timeout, unit); } + @Override public E pollLast(long timeout, TimeUnit unit) throws InterruptedException { E element = listOps.rightPop(timeout, unit); return (element == null ? null : element); } + @Override public void putFirst(E e) throws InterruptedException { add(e); } + @Override public void putLast(E e) throws InterruptedException { put(e); } + @Override public E takeFirst() throws InterruptedException { return take(); } + @Override public E takeLast() throws InterruptedException { return pollLast(0, TimeUnit.SECONDS); } + @Override public DataType getType() { return DataType.LIST; } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java index 1de1e811f..291b6b00c 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisMap.java @@ -47,14 +47,17 @@ public class DefaultRedisMap implements RedisMap { this.value = value; } + @Override public K getKey() { return key; } + @Override public V getValue() { return value; } + @Override public V setValue(V value) { throw new UnsupportedOperationException(); } @@ -79,26 +82,32 @@ public class DefaultRedisMap implements RedisMap { this.hashOps = boundOps; } + @Override public Long increment(K key, long delta) { return hashOps.increment(key, delta); } + @Override public RedisOperations getOperations() { return hashOps.getOperations(); } + @Override public void clear() { getOperations().delete(Collections.singleton(getKey())); } + @Override public boolean containsKey(Object key) { return hashOps.hasKey(key); } + @Override public boolean containsValue(Object value) { throw new UnsupportedOperationException(); } + @Override public Set> entrySet() { Set keySet = keySet(); Collection multiGet = hashOps.multiGet(keySet); @@ -114,38 +123,46 @@ public class DefaultRedisMap implements RedisMap { return entries; } + @Override public V get(Object key) { return hashOps.get(key); } + @Override public boolean isEmpty() { return size() == 0; } + @Override public Set keySet() { return hashOps.keys(); } + @Override public V put(K key, V value) { V oldV = get(key); hashOps.put(key, value); return oldV; } + @Override public void putAll(Map m) { hashOps.putAll(m); } + @Override public V remove(Object key) { V v = get(key); hashOps.delete(key); return v; } + @Override public int size() { return hashOps.size().intValue(); } + @Override public Collection values() { return hashOps.values(); } @@ -177,6 +194,7 @@ public class DefaultRedisMap implements RedisMap { return sb.toString(); } + @Override public V putIfAbsent(K key, V value) { throw new UnsupportedOperationException(); @@ -198,6 +216,7 @@ public class DefaultRedisMap implements RedisMap { // } } + @Override public boolean remove(Object key, Object value) { throw new UnsupportedOperationException(); @@ -223,6 +242,7 @@ public class DefaultRedisMap implements RedisMap { // } } + @Override public boolean replace(K key, V oldValue, V newValue) { throw new UnsupportedOperationException(); @@ -248,6 +268,7 @@ public class DefaultRedisMap implements RedisMap { // } } + @Override public V replace(K key, V value) { throw new UnsupportedOperationException(); @@ -273,31 +294,38 @@ public class DefaultRedisMap implements RedisMap { // } } + @Override public Boolean expire(long timeout, TimeUnit unit) { return hashOps.expire(timeout, unit); } + @Override public Boolean expireAt(Date date) { return hashOps.expireAt(date); } + @Override public Long getExpire() { return hashOps.getExpire(); } + @Override public Boolean persist() { return hashOps.persist(); } + @Override public String getKey() { return hashOps.getKey(); } + @Override public void rename(String newKey) { hashOps.rename(newKey); } + @Override public DataType getType() { return hashOps.getType(); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java index ac119798c..368d7c204 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisSet.java @@ -68,56 +68,68 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re } + @Override public Set diff(RedisSet set) { return boundSetOps.diff(set.getKey()); } + @Override public Set diff(Collection> sets) { return boundSetOps.diff(CollectionUtils.extractKeys(sets)); } + @Override public RedisSet diffAndStore(RedisSet set, String destKey) { boundSetOps.diffAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } + @Override public RedisSet diffAndStore(Collection> sets, String destKey) { boundSetOps.diffAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } + @Override public Set intersect(RedisSet set) { return boundSetOps.intersect(set.getKey()); } + @Override public Set intersect(Collection> sets) { return boundSetOps.intersect(CollectionUtils.extractKeys(sets)); } + @Override public RedisSet intersectAndStore(RedisSet set, String destKey) { boundSetOps.intersectAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } + @Override public RedisSet intersectAndStore(Collection> sets, String destKey) { boundSetOps.intersectAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } + @Override public Set union(RedisSet set) { return boundSetOps.union(set.getKey()); } + @Override public Set union(Collection> sets) { return boundSetOps.union(CollectionUtils.extractKeys(sets)); } + @Override public RedisSet unionAndStore(RedisSet set, String destKey) { boundSetOps.unionAndStore(set.getKey(), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); } + @Override public RedisSet unionAndStore(Collection> sets, String destKey) { boundSetOps.unionAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisSet(boundSetOps.getOperations().boundSetOps(destKey)); @@ -156,7 +168,8 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re return boundSetOps.size().intValue(); } + @Override public DataType getType() { return DataType.SET; } -} +} \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java index 2a2faacc4..4794aae99 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/DefaultRedisZSet.java @@ -91,43 +91,52 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R this.defaultScore = defaultScore; } + @Override public RedisZSet intersectAndStore(RedisZSet set, String destKey) { boundZSetOps.intersectAndStore(set.getKey(), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } + @Override public RedisZSet intersectAndStore(Collection> sets, String destKey) { boundZSetOps.intersectAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } + @Override public Set range(long start, long end) { return boundZSetOps.range(start, end); } + @Override public Set reverseRange(long start, long end) { return boundZSetOps.reverseRange(start, end); } + @Override public Set rangeByScore(double min, double max) { return boundZSetOps.rangeByScore(min, max); } + @Override public RedisZSet remove(long start, long end) { boundZSetOps.removeRange(start, end); return this; } + @Override public RedisZSet removeByScore(double min, double max) { boundZSetOps.removeRangeByScore(min, max); return this; } + @Override public RedisZSet unionAndStore(RedisZSet set, String destKey) { boundZSetOps.unionAndStore(set.getKey(), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); } + @Override public RedisZSet unionAndStore(Collection> sets, String destKey) { boundZSetOps.unionAndStore(CollectionUtils.extractKeys(sets), destKey); return new DefaultRedisZSet(boundZSetOps.getOperations().boundZSetOps(destKey), getDefaultScore()); @@ -138,6 +147,7 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R return add(e, getDefaultScore()); } + @Override public boolean add(E e, double score) { return boundZSetOps.add(e, score); } @@ -167,10 +177,12 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R return boundZSetOps.size().intValue(); } + @Override public Double getDefaultScore() { return defaultScore; } + @Override public E first() { Iterator iterator = boundZSetOps.range(0, 0).iterator(); if (iterator.hasNext()) @@ -178,6 +190,7 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R throw new NoSuchElementException(); } + @Override public E last() { Iterator iterator = boundZSetOps.reverseRange(0, 0).iterator(); if (iterator.hasNext()) @@ -185,18 +198,22 @@ public class DefaultRedisZSet extends AbstractRedisCollection implements R throw new NoSuchElementException(); } + @Override public Long rank(Object o) { return boundZSetOps.rank(o); } + @Override public Long reverseRank(Object o) { return boundZSetOps.reverseRank(o); } + @Override public Double score(Object o) { return boundZSetOps.score(o); } + @Override public DataType getType() { return DataType.ZSET; } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/config/StubErrorHandler.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/config/StubErrorHandler.java index e5e8244e9..a9f83609d 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/config/StubErrorHandler.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/config/StubErrorHandler.java @@ -27,7 +27,9 @@ public class StubErrorHandler implements ErrorHandler { public BlockingDeque throwables = new LinkedBlockingDeque(); + @Override public void handleError(Throwable t) { throwables.add(t); } + } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java index ddb1c6db9..875d65b79 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/connection/AbstractConnectionIntegrationTests.java @@ -196,6 +196,7 @@ public abstract class AbstractConnectionIntegrationTests { final BlockingDeque queue = new LinkedBlockingDeque(); final MessageListener ml = new MessageListener() { + @Override public void onMessage(Message message, byte[] pattern) { queue.add(message); System.out.println("received message"); @@ -211,12 +212,13 @@ public abstract class AbstractConnectionIntegrationTests { final AtomicBoolean flag = new AtomicBoolean(true); Runnable listener = new Runnable() { + @Override public void run() { subConn.subscribe(ml, channel); System.out.println("Subscribed"); while (flag.get()) { try { - Thread.sleep(2000); + Thread.currentThread().sleep(2000); } catch (Exception ex) { return; } @@ -249,6 +251,7 @@ public abstract class AbstractConnectionIntegrationTests { MessageListener listener = new MessageListener() { + @Override public void onMessage(Message message, byte[] pattern) { assertArrayEquals(expectedChannel, message.getChannel()); assertArrayEquals(expectedMessage, message.getBody()); @@ -256,10 +259,11 @@ public abstract class AbstractConnectionIntegrationTests { }; Thread th = new Thread(new Runnable() { + @Override public void run() { // sleep 1 second to let the registration happen try { - Thread.sleep(1000); + Thread.currentThread().sleep(1000); } catch (InterruptedException ex) { throw new RuntimeException(ex); } @@ -284,6 +288,7 @@ public abstract class AbstractConnectionIntegrationTests { MessageListener listener = new MessageListener() { + @Override public void onMessage(Message message, byte[] pattern) { assertArrayEquals(expectedPattern, pattern); assertArrayEquals(expectedMessage, message.getBody()); @@ -292,10 +297,11 @@ public abstract class AbstractConnectionIntegrationTests { }; Thread th = new Thread(new Runnable() { + @Override public void run() { // sleep 1 second to let the registration happen try { - Thread.sleep(1000); + Thread.currentThread().sleep(1000); } catch (InterruptedException ex) { throw new RuntimeException(ex); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java index 63a0d5245..f550facfb 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/SessionTest.java @@ -37,6 +37,7 @@ public class SessionTest { final StringRedisTemplate template = new StringRedisTemplate(factory); template.execute(new SessionCallback() { + @Override public Object execute(RedisOperations operations) { checkConnection(template, conn); template.discard(); @@ -49,6 +50,8 @@ public class SessionTest { private void checkConnection(RedisTemplate template, final RedisConnection expectedConnection) { template.execute(new RedisCallback() { + + @Override public Object doInRedis(RedisConnection connection) throws DataAccessException { assertSame(expectedConnection, connection); return null; diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/ThrowableMessageListener.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/ThrowableMessageListener.java index 914b5fe69..2f2903e22 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/ThrowableMessageListener.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/listener/adapter/ThrowableMessageListener.java @@ -24,6 +24,7 @@ import org.springframework.data.keyvalue.redis.connection.MessageListener; */ public class ThrowableMessageListener implements MessageListener { + @Override public void onMessage(Message message, byte[] pattern) { throw new IllegalStateException("throwing exception for message " + message); } diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollectionTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollectionTests.java index 3fb31d6d5..291f60665 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollectionTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisCollectionTests.java @@ -90,6 +90,8 @@ public abstract class AbstractRedisCollectionTests { // remove the collection entirely since clear() doesn't always work collection.getOperations().delete(Collections.singleton(collection.getKey())); template.execute(new RedisCallback() { + + @Override public Object doInRedis(RedisConnection connection) { connection.flushDb(); return null; diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java index 254d7f95e..1218c2e68 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java @@ -92,6 +92,8 @@ public abstract class AbstractRedisMapTests { // remove the collection entirely since clear() doesn't always work map.getOperations().delete(Collections.singleton(map.getKey())); template.execute(new RedisCallback() { + + @Override public Object doInRedis(RedisConnection connection) { connection.flushDb(); return null; diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/PersonObjectFactory.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/PersonObjectFactory.java index 371b3f919..6e4dfe931 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/PersonObjectFactory.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/PersonObjectFactory.java @@ -27,6 +27,7 @@ public class PersonObjectFactory implements ObjectFactory { private int counter = 0; + @Override public Person instance() { String uuid = UUID.randomUUID().toString(); return new Person(uuid, uuid, ++counter, new Address(uuid, counter)); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/StringObjectFactory.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/StringObjectFactory.java index 3e6f4661e..6669ca873 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/StringObjectFactory.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/StringObjectFactory.java @@ -24,6 +24,7 @@ import java.util.UUID; */ public class StringObjectFactory implements ObjectFactory { + @Override public String instance() { return UUID.randomUUID().toString(); } From af2265c813f59d5459e2eeef0e49b4e122360e14 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 14 Apr 2011 15:49:46 +0300 Subject: [PATCH 61/68] + fix problem causing atomic counters to reinitialize Redis values (even if no value was given) --- .../keyvalue/redis/support/atomic/RedisAtomicInteger.java | 6 ++++-- .../keyvalue/redis/support/atomic/RedisAtomicLong.java | 6 ++++-- .../keyvalue/redis/support/atomic/RedisAtomicTests.java | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java index bb4b19ba4..79e5b523e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicInteger.java @@ -77,8 +77,10 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey this.generalOps = redisTemplate; this.operations = generalOps.opsForValue(); - if (initialValue == null || this.operations.get(redisCounter) == null) { - set(0); + if (initialValue == null) { + if (this.operations.get(redisCounter) == null) { + set(0); + } } else { set(initialValue); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java index 5550b382d..9da634b3e 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicLong.java @@ -77,8 +77,10 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe this.generalOps = redisTemplate; this.operations = generalOps.opsForValue(); - if (initialValue == null || this.operations.get(redisCounter) == null) { - set(0); + if (initialValue == null) { + if (this.operations.get(redisCounter) == null) { + set(0); + } } else { set(initialValue); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java index 25c0a93dc..d69d19add 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/atomic/RedisAtomicTests.java @@ -105,4 +105,11 @@ public class RedisAtomicTests { int delta = 5; assertEquals(delta, intCounter.addAndGet(delta)); } + + @Test + public void testReadExistingValue() throws Exception { + longCounter.set(5); + RedisAtomicLong keyCopy = new RedisAtomicLong(longCounter.getKey(), factory); + assertEquals(longCounter.get(), keyCopy.get()); + } } \ No newline at end of file From 1f1db82ffb83558ea05b4ab9b82097118c2fffd6 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 14 Apr 2011 19:38:55 +0300 Subject: [PATCH 62/68] DATAKV-62 + fixed incorrect method invocation --- .../keyvalue/redis/core/RedisTemplate.java | 6 +- .../keyvalue/redis/core/TemplateTest.java | 59 +++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/TemplateTest.java diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index d3565d996..eb9c1d398 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -538,14 +538,14 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation public Set keys(K pattern) { final byte[] rawKey = rawKey(pattern); - Collection rawKeys = execute(new RedisCallback>() { + Set rawKeys = execute(new RedisCallback>() { @Override - public Collection doInRedis(RedisConnection connection) { + public Set doInRedis(RedisConnection connection) { return connection.keys(rawKey); } }, true); - return (Set) SerializationUtils.deserialize(rawKeys, keySerializer); + return SerializationUtils.deserialize(rawKeys, keySerializer); } @Override diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/TemplateTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/TemplateTest.java new file mode 100644 index 000000000..96cf1d05c --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/core/TemplateTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.core; + +import static org.junit.Assert.*; + +import java.util.Collection; + +import org.junit.AfterClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.springframework.data.keyvalue.redis.ConnectionFactoryTracker; +import org.springframework.data.keyvalue.redis.support.collections.CollectionTestParams; +import org.springframework.data.keyvalue.redis.support.collections.ObjectFactory; + +/** + * @author Costin Leau + */ +@RunWith(Parameterized.class) +public class TemplateTest { + private ObjectFactory objFactory; + private RedisTemplate template; + + public TemplateTest(ObjectFactory objFactory, RedisTemplate template) { + this.objFactory = objFactory; + this.template = template; + ConnectionFactoryTracker.add(template.getConnectionFactory()); + } + + @AfterClass + public static void cleanUp() { + ConnectionFactoryTracker.cleanUp(); + } + + @Parameters + public static Collection testParams() { + return CollectionTestParams.testParams(); + } + + @Test + public void testKeys() throws Exception { + assertTrue(template.keys("*") != null); + } +} From aebcb56c3c1e2ac3cc9309ec5ab9632ca095768f Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 14 Apr 2011 19:53:55 +0300 Subject: [PATCH 63/68] DATAKV-63 + reset the selected db when the connection is closed --- .../keyvalue/redis/connection/jedis/JedisConnection.java | 5 +++++ .../data/keyvalue/redis/connection/rjc/RjcConnection.java | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java index 410f5fef8..0d751765a 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnection.java @@ -129,6 +129,11 @@ public class JedisConnection implements RedisConnection { pool.returnBrokenResource(jedis); } else { + // reset the connection + if (dbIndex > 0) { + select(0); + } + pool.returnResource(jedis); } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java index 50d5f78f0..5b9c739a1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnection.java @@ -80,6 +80,11 @@ public class RjcConnection implements RedisConnection { public void close() throws DataAccessException { isClosed = true; + // reset the connection (in case a pool is being used) + if (dbIndex > 0) { + select(0); + } + try { subscriber.close(); session.close(); From 825a58c0aec9322752a4b431612d4dbf4a7cddc6 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 14 Apr 2011 20:27:56 +0300 Subject: [PATCH 64/68] make Spring OXM optional --- spring-data-redis/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-redis/pom.xml b/spring-data-redis/pom.xml index df79d0267..bdb8330c0 100644 --- a/spring-data-redis/pom.xml +++ b/spring-data-redis/pom.xml @@ -87,6 +87,7 @@ org.springframework spring-oxm ${org.springframework.version} + true From 62a43d746cc4f89c594fd08010004644aa8d8bce Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 15 Apr 2011 15:58:16 +0300 Subject: [PATCH 65/68] DATAKV-58 + add Properties implementation for Redis --- .../support/collections/RedisProperties.java | 265 +++++++++++++++ .../collections/AbstractRedisMapTests.java | 2 +- .../collections/RedisPropertiesTest.java | 309 ++++++++++++++++++ .../support/collections/props.properties | 4 + .../redis/support/collections/props.xml | 6 + 5 files changed, 585 insertions(+), 1 deletion(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisProperties.java create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTest.java create mode 100644 spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/props.properties create mode 100644 spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/props.xml diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisProperties.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisProperties.java new file mode 100644 index 000000000..22b44ddc3 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisProperties.java @@ -0,0 +1,265 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.support.collections; + +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Enumeration; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import org.springframework.data.keyvalue.redis.connection.DataType; +import org.springframework.data.keyvalue.redis.core.BoundHashOperations; +import org.springframework.data.keyvalue.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}. + *

+ * Note that this implementation only accepts Strings - objects of other type are not supported. + * + * @see Properties + * @see org.springframework.core.io.support.PropertiesLoaderSupport + * @author Costin Leau + */ +public class RedisProperties extends Properties implements RedisMap { + + private final BoundHashOperations hashOps; + private final RedisMap delegate; + + /** + * Constructs a new RedisProperties instance. + * + */ + public RedisProperties(BoundHashOperations boundOps) { + this(null, boundOps); + } + + /** + * Constructs a new RedisProperties instance. + * + * @param boundOps + */ + public RedisProperties(String key, RedisOperations operations) { + this(null, operations. boundHashOps(key)); + } + + /** + * Constructs a new RedisProperties instance. + * + * @param defaults + */ + public RedisProperties(Properties defaults, BoundHashOperations boundOps) { + super(defaults); + this.hashOps = boundOps; + this.delegate = new DefaultRedisMap(boundOps); + } + + /** + * Constructs a new RedisProperties instance. + * + * @param defaults + * @param boundOps + */ + public RedisProperties(Properties defaults, String key, RedisOperations operations) { + this(defaults, operations. boundHashOps(key)); + } + + @Override + public synchronized Object get(Object key) { + return delegate.get(key); + } + + @Override + public synchronized Object put(Object key, Object value) { + return delegate.put((String) key, (String) value); + } + + @SuppressWarnings("unchecked") + @Override + public synchronized void putAll(Map t) { + delegate.putAll((Map) t); + } + + @Override + public Enumeration propertyNames() { + Set keys = new LinkedHashSet(delegate.keySet()); + keys.addAll(defaults.stringPropertyNames()); + return Collections.enumeration(keys); + } + + @Override + public synchronized void clear() { + delegate.clear(); + } + + @Override + public synchronized Object clone() { + return new RedisProperties(defaults, hashOps); + } + + @Override + public synchronized boolean contains(Object value) { + return containsValue(value); + } + + @Override + public synchronized boolean containsKey(Object key) { + return delegate.containsKey(key); + } + + @Override + public boolean containsValue(Object value) { + return delegate.containsValue(value); + } + + @SuppressWarnings("unchecked") + @Override + public synchronized Enumeration elements() { + Collection values = delegate.values(); + return Collections.enumeration(values); + } + + @Override + @SuppressWarnings("unchecked") + public Set> entrySet() { + Set entries = delegate.entrySet(); + return entries; + } + + @Override + public synchronized boolean equals(Object o) { + if (o == this) + return true; + + if (o instanceof RedisProperties) { + return o.hashCode() == hashCode(); + } + return false; + } + + @Override + public synchronized int hashCode() { + int hash = RedisProperties.class.hashCode(); + return hash * 17 + delegate.hashCode(); + } + + @Override + public synchronized boolean isEmpty() { + return delegate.isEmpty(); + } + + @Override + public synchronized Enumeration keys() { + Set keys = keySet(); + return Collections.enumeration(keys); + } + + @SuppressWarnings("unchecked") + @Override + public Set keySet() { + Set keys = delegate.keySet(); + return keys; + } + + @Override + public synchronized Object remove(Object key) { + return delegate.remove(key); + } + + @Override + public synchronized int size() { + return delegate.size(); + } + + @SuppressWarnings("unchecked") + @Override + public Collection values() { + Collection vals = delegate.values(); + return vals; + } + + @Override + public Long increment(Object key, long delta) { + return hashOps.increment((String) key, delta); + } + + @Override + public RedisOperations getOperations() { + return hashOps.getOperations(); + } + + @Override + public Boolean expire(long timeout, TimeUnit unit) { + return hashOps.expire(timeout, unit); + } + + @Override + public Boolean expireAt(Date date) { + return hashOps.expireAt(date); + } + + @Override + public Long getExpire() { + return hashOps.getExpire(); + } + + @Override + public String getKey() { + return hashOps.getKey(); + } + + @Override + public DataType getType() { + return hashOps.getType(); + } + + @Override + public Boolean persist() { + return hashOps.persist(); + } + + @Override + public void rename(String newKey) { + hashOps.rename(newKey); + } + + @Override + public Object putIfAbsent(Object key, Object value) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object key, Object value) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean replace(Object key, Object oldValue, Object newValue) { + throw new UnsupportedOperationException(); + } + + @Override + public Object replace(Object key, Object value) { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java index 1218c2e68..f9d266355 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/AbstractRedisMapTests.java @@ -162,7 +162,7 @@ public abstract class AbstractRedisMapTests { K k1 = getKey(); V v1 = getValue(); - assertNull(map.get(UUID.randomUUID())); + assertNull(map.get(UUID.randomUUID().toString())); assertNull(map.get(k1)); map.put(k1, v1); assertEquals(v1, map.get(k1)); diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTest.java new file mode 100644 index 000000000..2075d788a --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTest.java @@ -0,0 +1,309 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.support.collections; + +import static org.junit.Assert.*; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Collection; +import java.util.Enumeration; +import java.util.LinkedHashSet; +import java.util.Properties; +import java.util.Set; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameters; +import org.springframework.data.keyvalue.redis.Person; +import org.springframework.data.keyvalue.redis.SettingsUtils; +import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.keyvalue.redis.connection.jredis.JredisConnectionFactory; +import org.springframework.data.keyvalue.redis.connection.rjc.RjcConnectionFactory; +import org.springframework.data.keyvalue.redis.core.RedisTemplate; +import org.springframework.data.keyvalue.redis.core.StringRedisTemplate; +import org.springframework.data.keyvalue.redis.serializer.JacksonJsonRedisSerializer; +import org.springframework.data.keyvalue.redis.serializer.OxmSerializer; +import org.springframework.oxm.xstream.XStreamMarshaller; + +/** + * @author Costin Leau + */ +public class RedisPropertiesTest extends RedisMapTests { + + protected Properties defaults = new Properties(); + protected RedisProperties props; + + /** + * Constructs a new RedisPropertiesTest instance. + * + * @param keyFactory + * @param valueFactory + * @param template + */ + public RedisPropertiesTest(ObjectFactory keyFactory, ObjectFactory valueFactory, + RedisTemplate template) { + super(keyFactory, valueFactory, template); + } + + @Override + RedisMap createMap() { + String redisName = getClass().getSimpleName(); + props = new RedisProperties(defaults, redisName, new StringRedisTemplate(template.getConnectionFactory())); + return props; + } + + @Override + protected RedisStore copyStore(RedisStore store) { + return new RedisProperties(store.getKey(), store.getOperations()); + } + + @Test + public void testGetOperations() { + assertTrue(map.getOperations() instanceof StringRedisTemplate); + } + + @Test + public void testPropertiesLoad() throws Exception { + InputStream stream = getClass().getResourceAsStream( + "/org/springframework/data/keyvalue/redis/support/collections/props.properties"); + + assertNotNull(stream); + + int size = props.size(); + + try { + props.load(stream); + } finally { + stream.close(); + } + + assertEquals("bar", props.get("foo")); + assertEquals("head", props.get("bucket")); + assertEquals("island", props.get("lotus")); + assertEquals(size + 3, props.size()); + } + + @Test + @Ignore + public void testPropertiesLoadXml() throws Exception { + InputStream stream = getClass().getResourceAsStream( + "/org/springframework/data/keyvalue/redis/support/collections/props.properties"); + + assertNotNull(stream); + + int size = props.size(); + + try { + props.loadFromXML(stream); + } finally { + stream.close(); + } + + assertEquals("bar", props.get("foo")); + assertEquals("head", props.get("bucket")); + assertEquals("island", props.get("lotus")); + assertEquals(size + 3, props.size()); + } + + @Test + public void testPropertiesSave() throws Exception { + props.setProperty("x", "y"); + props.setProperty("a", "b"); + + StringWriter writer = new StringWriter(); + props.store(writer, "no-comment"); + System.out.println(writer.toString()); + } + + @Test + @Ignore + public void testPropertiesSaveXml() throws Exception { + props.setProperty("x", "y"); + props.setProperty("a", "b"); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + props.storeToXML(bos, "comment"); + System.out.println(bos.toString()); + } + + @Test + public void testGetProperty() throws Exception { + String property = props.getProperty("a"); + assertNull(property); + defaults.put("a", "x"); + assertEquals("x", props.getProperty("a")); + } + + @Test + public void testGetPropertyDefault() throws Exception { + assertEquals("x", props.getProperty("a", "x")); + } + + @Test + public void testSetProperty() throws Exception { + assertNull(props.getProperty("a")); + defaults.setProperty("a", "x"); + assertEquals("x", props.getProperty("a")); + } + + @Test + public void testPropertiesList() throws Exception { + defaults.setProperty("a", "b"); + props.setProperty("x", "y"); + props.list(System.out); + } + + @Test + public void testPropertyNames() throws Exception { + String key1="foo"; + String key2="x"; + String key3 = "d"; + + String val ="o"; + + defaults.setProperty(key3, val); + props.setProperty(key1, val); + props.setProperty(key2, val); + + Enumeration names = props.propertyNames(); + Set keys = new LinkedHashSet(); + keys.add(names.nextElement()); + keys.add(names.nextElement()); + keys.add(names.nextElement()); + + assertFalse(names.hasMoreElements()); + } + + @Test + public void testStringPropertyNames() throws Exception { + String key1 = "foo"; + String key2 = "x"; + String key3 = "d"; + + String val = "o"; + + defaults.setProperty(key3, val); + props.setProperty(key1, val); + props.setProperty(key2, val); + + Set keys = props.stringPropertyNames(); + assertTrue(keys.contains(key1)); + assertTrue(keys.contains(key2)); + assertTrue(keys.contains(key3)); + } + + @Parameters + public static Collection testParams() { + // XStream serializer + XStreamMarshaller xstream = new XStreamMarshaller(); + try { + xstream.afterPropertiesSet(); + } catch (Exception ex) { + throw new RuntimeException("Cannot init XStream", ex); + } + OxmSerializer serializer = new OxmSerializer(xstream, xstream); + JacksonJsonRedisSerializer jsonSerializer = new JacksonJsonRedisSerializer(Person.class); + JacksonJsonRedisSerializer jsonStringSerializer = new JacksonJsonRedisSerializer(String.class); + + // create Jedis Factory + ObjectFactory stringFactory = new StringObjectFactory(); + + JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); + jedisConnFactory.setUsePool(false); + + jedisConnFactory.setPort(SettingsUtils.getPort()); + jedisConnFactory.setHostName(SettingsUtils.getHost()); + + jedisConnFactory.afterPropertiesSet(); + + RedisTemplate genericTemplate = new RedisTemplate(jedisConnFactory); + + RedisTemplate xstreamGenericTemplate = new RedisTemplate(); + xstreamGenericTemplate.setConnectionFactory(jedisConnFactory); + xstreamGenericTemplate.setDefaultSerializer(serializer); + xstreamGenericTemplate.afterPropertiesSet(); + + RedisTemplate jsonPersonTemplate = new RedisTemplate(); + jsonPersonTemplate.setConnectionFactory(jedisConnFactory); + jsonPersonTemplate.setDefaultSerializer(jsonSerializer); + jsonPersonTemplate.setHashKeySerializer(jsonSerializer); + jsonPersonTemplate.setHashValueSerializer(jsonStringSerializer); + jsonPersonTemplate.afterPropertiesSet(); + + // JRedis + JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory(); + jredisConnFactory.setUsePool(true); + jredisConnFactory.setPort(SettingsUtils.getPort()); + jredisConnFactory.setHostName(SettingsUtils.getHost()); + jredisConnFactory.afterPropertiesSet(); + + RedisTemplate genericTemplateJR = new RedisTemplate(jredisConnFactory); + RedisTemplate xGenericTemplateJR = new RedisTemplate(); + xGenericTemplateJR.setConnectionFactory(jredisConnFactory); + xGenericTemplateJR.setDefaultSerializer(serializer); + xGenericTemplateJR.afterPropertiesSet(); + + RedisTemplate jsonPersonTemplateJR = new RedisTemplate(); + jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory); + jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer); + jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer); + jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer); + jsonPersonTemplateJR.afterPropertiesSet(); + + // RJC + + // rjc + RjcConnectionFactory rjcConnFactory = new RjcConnectionFactory(); + rjcConnFactory.setUsePool(true); + rjcConnFactory.setPort(SettingsUtils.getPort()); + rjcConnFactory.setHostName(SettingsUtils.getHost()); + rjcConnFactory.afterPropertiesSet(); + + RedisTemplate genericTemplateRJC = new RedisTemplate(jredisConnFactory); + RedisTemplate xGenericTemplateRJC = new RedisTemplate(); + xGenericTemplateRJC.setConnectionFactory(rjcConnFactory); + xGenericTemplateRJC.setDefaultSerializer(serializer); + xGenericTemplateRJC.afterPropertiesSet(); + + RedisTemplate jsonPersonTemplateRJC = new RedisTemplate(); + jsonPersonTemplateRJC.setConnectionFactory(rjcConnFactory); + jsonPersonTemplateRJC.setDefaultSerializer(jsonSerializer); + jsonPersonTemplateRJC.setHashKeySerializer(jsonSerializer); + jsonPersonTemplateRJC.setHashValueSerializer(jsonStringSerializer); + jsonPersonTemplateRJC.afterPropertiesSet(); + + + return Arrays.asList(new Object[][] { { stringFactory, stringFactory, genericTemplate }, + { stringFactory, stringFactory, genericTemplate }, { stringFactory, stringFactory, genericTemplate }, + { stringFactory, stringFactory, genericTemplate }, + { stringFactory, stringFactory, xstreamGenericTemplate }, + { stringFactory, stringFactory, genericTemplateJR }, + { stringFactory, stringFactory, genericTemplateJR }, + { stringFactory, stringFactory, genericTemplateJR }, + { stringFactory, stringFactory, genericTemplateJR }, + { stringFactory, stringFactory, xGenericTemplateJR }, + { stringFactory, stringFactory, jsonPersonTemplate }, + { stringFactory, stringFactory, jsonPersonTemplateJR }, + { stringFactory, stringFactory, genericTemplateRJC }, + { stringFactory, stringFactory, genericTemplateRJC }, + { stringFactory, stringFactory, genericTemplateRJC }, + { stringFactory, stringFactory, genericTemplateRJC }, + { stringFactory, stringFactory, xGenericTemplateRJC }, + { stringFactory, stringFactory, jsonPersonTemplateRJC } }); + } +} \ No newline at end of file diff --git a/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/props.properties b/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/props.properties new file mode 100644 index 000000000..aad78142d --- /dev/null +++ b/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/props.properties @@ -0,0 +1,4 @@ +# redis connection properties +foo=bar +bucket=head +lotus=island \ No newline at end of file diff --git a/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/props.xml b/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/props.xml new file mode 100644 index 000000000..2e49de5b7 --- /dev/null +++ b/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/props.xml @@ -0,0 +1,6 @@ + +Hi +bar +head +island + \ No newline at end of file From 30d82a3ae887a2936bed104ea0e1b7022c81d6e8 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 15 Apr 2011 17:51:56 +0300 Subject: [PATCH 66/68] DATAKV-58 --- .../{RedisPropertiesTest.java => RedisPropertiesTests.java} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/{RedisPropertiesTest.java => RedisPropertiesTests.java} (97%) diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTest.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTests.java similarity index 97% rename from spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTest.java rename to spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTests.java index 2075d788a..0a9770b16 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTest.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTests.java @@ -44,19 +44,19 @@ import org.springframework.oxm.xstream.XStreamMarshaller; /** * @author Costin Leau */ -public class RedisPropertiesTest extends RedisMapTests { +public class RedisPropertiesTests extends RedisMapTests { protected Properties defaults = new Properties(); protected RedisProperties props; /** - * Constructs a new RedisPropertiesTest instance. + * Constructs a new RedisPropertiesTests instance. * * @param keyFactory * @param valueFactory * @param template */ - public RedisPropertiesTest(ObjectFactory keyFactory, ObjectFactory valueFactory, + public RedisPropertiesTests(ObjectFactory keyFactory, ObjectFactory valueFactory, RedisTemplate template) { super(keyFactory, valueFactory, template); } From ffb61645de6286b293eaeedead8c7688efbd3848 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 15 Apr 2011 20:44:58 +0300 Subject: [PATCH 67/68] DATAKV-58 + add FactoryBean for creating collections on top of Redis keys + add dedicated namespace + code + integration tests --- .../redis/config/RedisCollectionParser.java | 48 +++++ .../config/RedisListenerContainerParser.java | 2 +- .../redis/config/RedisNamespaceHandler.java | 1 + .../RedisCollectionFactoryBean.java | 167 ++++++++++++++++++ .../support/collections/RedisProperties.java | 12 ++ .../redis/config/spring-redis-1.0.xsd | 57 ++++++ .../RedisCollectionFactoryBeanTests.java | 123 +++++++++++++ .../collections/RedisPropertiesTests.java | 6 +- .../support/collections/SupportXmlTests.java | 37 ++++ .../redis/support/collections/container.xml | 16 ++ 10 files changed, 466 insertions(+), 3 deletions(-) create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisCollectionParser.java create mode 100644 spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisCollectionFactoryBean.java create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisCollectionFactoryBeanTests.java create mode 100644 spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/SupportXmlTests.java create mode 100644 spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/container.xml diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisCollectionParser.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisCollectionParser.java new file mode 100644 index 000000000..c806f8dcb --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisCollectionParser.java @@ -0,0 +1,48 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.config; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; +import org.springframework.data.keyvalue.redis.support.collections.RedisCollectionFactoryBean; +import org.springframework.util.StringUtils; +import org.w3c.dom.Element; + +/** + * Parser for the Redis <collection> element. + * + * @author Costin Leau + */ +public class RedisCollectionParser extends AbstractSimpleBeanDefinitionParser { + + @Override + protected Class getBeanClass(Element element) { + return RedisCollectionFactoryBean.class; + } + + @Override + protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { + String template = element.getAttribute("template"); + if (StringUtils.hasText(template)) { + beanDefinition.addPropertyReference("template", template); + } + } + + @Override + protected boolean isEligibleAttribute(String attributeName) { + return super.isEligibleAttribute(attributeName) && (!"template".equals(attributeName)); + } +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisListenerContainerParser.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisListenerContainerParser.java index 1c300a8f4..12fd192fd 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisListenerContainerParser.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisListenerContainerParser.java @@ -37,7 +37,7 @@ import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; /** - * Parser for the JMS <listener-container> element. + * Parser for the Redis <listener-container> element. * * @author Costin Leau */ diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java index c2cc323e7..2a136f377 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/config/RedisNamespaceHandler.java @@ -28,5 +28,6 @@ class RedisNamespaceHandler extends NamespaceHandlerSupport { @Override public void init() { registerBeanDefinitionParser("listener-container", new RedisListenerContainerParser()); + registerBeanDefinitionParser("collection", new RedisCollectionParser()); } } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisCollectionFactoryBean.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisCollectionFactoryBean.java new file mode 100644 index 000000000..0f0fa8249 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisCollectionFactoryBean.java @@ -0,0 +1,167 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.support.collections; + +import org.springframework.beans.factory.BeanNameAware; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.data.keyvalue.redis.connection.DataType; +import org.springframework.data.keyvalue.redis.core.RedisTemplate; +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). + * Otherwise uses the provided type (default is list). + * + * @author Costin Leau + */ +public class RedisCollectionFactoryBean implements InitializingBean, BeanNameAware, FactoryBean { + + public enum CollectionType { + LIST { + @Override + public DataType dataType() { + return DataType.LIST; + } + }, + SET { + @Override + public DataType dataType() { + return DataType.SET; + } + }, + ZSET { + @Override + public DataType dataType() { + return DataType.ZSET; + } + }, + MAP { + @Override + public DataType dataType() { + return DataType.HASH; + } + }, + PROPERTIES { + @Override + public DataType dataType() { + return DataType.HASH; + } + }; + + abstract DataType dataType(); + } + + + private RedisStore store; + private CollectionType type = null; + private RedisTemplate template; + private String key; + private String beanName; + + @Override + public void afterPropertiesSet() { + if (!StringUtils.hasText(key)) { + key = beanName; + } + + Assert.hasText(key, "Collection key is required - no key or bean name specified"); + Assert.notNull(template, "Redis template is required"); + + DataType dt = template.type(key); + + // can't create store + Assert.isTrue(!DataType.STRING.equals(dt), "Cannot create store on keys of type 'string'"); + + store = createStore(dt); + + if (store == null) { + if (type == null) { + type = CollectionType.LIST; + } + store = createStore(type.dataType()); + } + } + + private RedisStore createStore(DataType dt) { + switch (dt) { + case LIST: + return new DefaultRedisList(key, template); + + case SET: + return new DefaultRedisSet(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); + } + return null; + } + + @Override + public RedisStore getObject() { + return store; + } + + @Override + public Class getObjectType() { + return (store != null ? store.getClass() : RedisStore.class); + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + public void setBeanName(String name) { + this.beanName = name; + } + + /** + * Sets the store type. Used if the key does not exist. + * + * @param type The type to set. + */ + public void setType(CollectionType type) { + this.type = type; + } + + /** + * Sets the template used by the resulting store. + * + * @param template The template to set. + */ + public void setTemplate(RedisTemplate template) { + this.template = template; + } + + /** + * 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/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisProperties.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisProperties.java index 22b44ddc3..0fec1d1b9 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisProperties.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/support/collections/RedisProperties.java @@ -15,6 +15,8 @@ */ package org.springframework.data.keyvalue.redis.support.collections; +import java.io.IOException; +import java.io.OutputStream; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -262,4 +264,14 @@ public class RedisProperties extends Properties implements RedisMap + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisCollectionFactoryBeanTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisCollectionFactoryBeanTests.java new file mode 100644 index 000000000..3f6742d40 --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisCollectionFactoryBeanTests.java @@ -0,0 +1,123 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.support.collections; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; +import org.springframework.data.keyvalue.redis.ConnectionFactoryTracker; +import org.springframework.data.keyvalue.redis.SettingsUtils; +import org.springframework.data.keyvalue.redis.connection.RedisConnection; +import org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.keyvalue.redis.core.RedisCallback; +import org.springframework.data.keyvalue.redis.core.StringRedisTemplate; +import org.springframework.data.keyvalue.redis.support.collections.RedisCollectionFactoryBean.CollectionType; + +/** + * @author Costin Leau + */ +public class RedisCollectionFactoryBeanTests { + + protected ObjectFactory factory = new StringObjectFactory(); + protected StringRedisTemplate template; + protected RedisStore col; + + public RedisCollectionFactoryBeanTests() { + JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); + jedisConnFactory.setUsePool(true); + + jedisConnFactory.setPort(SettingsUtils.getPort()); + jedisConnFactory.setHostName(SettingsUtils.getHost()); + + jedisConnFactory.afterPropertiesSet(); + + this.template = new StringRedisTemplate(jedisConnFactory); + ConnectionFactoryTracker.add(jedisConnFactory); + } + + @AfterClass + public static void cleanUp() { + ConnectionFactoryTracker.cleanUp(); + } + + @After + public void tearDown() throws Exception { + // clean up the whole db + template.execute(new RedisCallback() { + + @Override + public Object doInRedis(RedisConnection connection) { + connection.flushDb(); + return null; + } + }); + } + + private RedisStore createCollection(String key) { + return createCollection(key, null); + } + + private RedisStore createCollection(String key, CollectionType type) { + RedisCollectionFactoryBean fb = new RedisCollectionFactoryBean(); + fb.setKey(key); + fb.setTemplate(template); + fb.setType(type); + fb.afterPropertiesSet(); + + return fb.getObject(); + } + + @Test + public void testNone() throws Exception { + RedisStore store = createCollection("nosrt", CollectionType.PROPERTIES); + assertThat(store, instanceOf(RedisProperties.class)); + + store = createCollection("nosrt", CollectionType.MAP); + assertThat(store, instanceOf(DefaultRedisMap.class)); + + store = createCollection("nosrt", CollectionType.SET); + assertThat(store, instanceOf(DefaultRedisSet.class)); + + store = createCollection("nosrt", CollectionType.LIST); + assertThat(store, instanceOf(DefaultRedisList.class)); + + store = createCollection("nosrt"); + assertThat(store, instanceOf(DefaultRedisList.class)); + } + + + @Test + public void testExistingCol() throws Exception { + String key = "set"; + String val = "value"; + + template.boundSetOps(key).add(val); + RedisStore col = createCollection(key); + assertThat(col, is(DefaultRedisSet.class)); + + key = "map"; + template.boundHashOps(key).put(val, val); + col = createCollection(key); + assertThat(col, is(DefaultRedisMap.class)); + + col = createCollection(key, CollectionType.PROPERTIES); + assertThat(col, is(RedisProperties.class)); + + } +} \ No newline at end of file diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTests.java index 0a9770b16..8053fde02 100644 --- a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTests.java +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/RedisPropertiesTests.java @@ -19,6 +19,7 @@ import static org.junit.Assert.*; import java.io.ByteArrayOutputStream; import java.io.InputStream; +import java.io.PrintWriter; import java.io.StringWriter; import java.util.Arrays; import java.util.Collection; @@ -128,7 +129,7 @@ public class RedisPropertiesTests extends RedisMapTests { StringWriter writer = new StringWriter(); props.store(writer, "no-comment"); - System.out.println(writer.toString()); + //System.out.println(writer.toString()); } @Test @@ -165,7 +166,8 @@ public class RedisPropertiesTests extends RedisMapTests { public void testPropertiesList() throws Exception { defaults.setProperty("a", "b"); props.setProperty("x", "y"); - props.list(System.out); + StringWriter wr = new StringWriter(); + props.list(new PrintWriter(wr)); } @Test diff --git a/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/SupportXmlTests.java b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/SupportXmlTests.java new file mode 100644 index 000000000..026074fbd --- /dev/null +++ b/spring-data-redis/src/test/java/org/springframework/data/keyvalue/redis/support/collections/SupportXmlTests.java @@ -0,0 +1,37 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.keyvalue.redis.support.collections; + +import java.util.Map; + +import org.junit.Test; +import org.springframework.context.support.GenericXmlApplicationContext; + +/** + * @author Costin Leau + */ +public class SupportXmlTests { + + @Test + public void testContainerSetup() throws Exception { + GenericXmlApplicationContext ctx = new GenericXmlApplicationContext( + "/org/springframework/data/keyvalue/redis/support/collections/container.xml"); + + RedisList list = ctx.getBean("non-existing", RedisList.class); + RedisProperties props = ctx.getBean("props", RedisProperties.class); + Map map = ctx.getBean("map", Map.class); + } +} diff --git a/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/container.xml b/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/container.xml new file mode 100644 index 000000000..410c81422 --- /dev/null +++ b/spring-data-redis/src/test/resources/org/springframework/data/keyvalue/redis/support/collections/container.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + From 9b1f5464ba2cefa99c73baa5f99d44c393020519 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 19 Apr 2011 19:56:10 +0300 Subject: [PATCH 68/68] DATAKV-66 + add getter for database index on ConnectionFactories + update javadoc --- .../connection/jedis/JedisConnectionFactory.java | 12 +++++++++++- .../connection/jredis/JredisConnectionFactory.java | 9 +++++++++ .../redis/connection/rjc/RjcConnectionFactory.java | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java index 51f326a39..1f41fbb6b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jedis/JedisConnectionFactory.java @@ -280,9 +280,19 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean, this.poolConfig = poolConfig; } + + /** + * Returns the index of the database. + * + * @return Returns the database index + */ + public int getDatabase() { + return dbIndex; + } + /** * Sets the index of the database used by this connection factory. - * Can be between 0 (default) and 15. + * Default is 0. * * @param index database index */ diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java index 87ae5c1a5..a52d377a1 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/jredis/JredisConnectionFactory.java @@ -224,6 +224,15 @@ public class JredisConnectionFactory implements InitializingBean, DisposableBean usePool = true; } + /** + * Returns the index of the database. + * + * @return Returns the database index + */ + public int getDatabase() { + return dbIndex; + } + /** * Sets the index of the database used by this connection factory. * Can be between 0 (default) and 15. diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java index 5c149f107..641c9c61f 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/connection/rjc/RjcConnectionFactory.java @@ -196,6 +196,15 @@ public class RjcConnectionFactory implements InitializingBean, DisposableBean, R this.usePool = usePool; } + /** + * Returns the index of the database. + * + * @return Returns the database index + */ + public int getDatabase() { + return dbIndex; + } + /** * Sets the index of the database used by this connection factory. * Can be between 0 (default) and 15.