From a6f79e267542ffcc6f3d4c0303da8a1cda7d19c3 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 29 Mar 2012 18:58:46 +0300 Subject: [PATCH 01/22] update docs DATAREDIS-8 --- docs/src/reference/docbook/reference/redis.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/reference/docbook/reference/redis.xml b/docs/src/reference/docbook/reference/redis.xml index 0b354e6d8..851323551 100644 --- a/docs/src/reference/docbook/reference/redis.xml +++ b/docs/src/reference/docbook/reference/redis.xml @@ -284,7 +284,7 @@ template; // inject the template as ListOperations From e1a3b3100e07e51e1174ffc5472c73a46dbacfb3 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 18:05:49 +0300 Subject: [PATCH 02/22] fix connection.setBit() DATAREDIS-89 --- .../data/redis/connection/jedis/JedisUtils.java | 4 ++-- .../connection/AbstractConnectionIntegrationTests.java | 9 +++++++++ .../jredis/JRedisConnectionIntegrationTests.java | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisUtils.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisUtils.java index 7a107cd7e..43878dcd6 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisUtils.java @@ -58,8 +58,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[] { 1 }; - private static final byte[] ZERO = new byte[] { 0 }; + 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. diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index 216be63be..4b4d3276f 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -116,6 +116,15 @@ public abstract class AbstractConnectionIntegrationTests { assertEquals("PONG", connection.ping()); } + @Test + public void testBitSet() throws Exception { + String key = "bitset-test"; + connection.setBit(key, 0, false); + connection.setBit(key, 1, true); + assertTrue(!connection.getBit(key, 0)); + assertTrue(connection.getBit(key, 1)); + } + @Test public void testInfo() throws Exception { Properties info = connection.info(); diff --git a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java index 6ddc7df89..c38a6134c 100644 --- a/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jredis/JRedisConnectionIntegrationTests.java @@ -22,7 +22,6 @@ import org.junit.Test; import org.springframework.data.redis.SettingsUtils; import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests; import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.jredis.JredisConnectionFactory; public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests { @@ -86,6 +85,10 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat @Ignore public void testPubSubWithNamedChannels() { - } + + @Ignore + public void testBitSet() throws Exception { + } + } \ No newline at end of file From ff8184c264b0421a547b16a31094dbfbdd9a2511 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 18:10:54 +0300 Subject: [PATCH 03/22] switch params in ZSetOperations#intersectAndStore DATAREDIS-84 --- .../data/redis/core/DefaultBoundZSetOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java index 968da3221..0031b676f 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundZSetOperations.java @@ -58,7 +58,7 @@ class DefaultBoundZSetOperations extends DefaultBoundKeyOperations impl } - public void intersectAndStore(K destKey, K otherKey) { + public void intersectAndStore(K otherKey, K destKey) { ops.intersectAndStore(getKey(), otherKey, destKey); } From 27d7e5dd0b856997db02a004fde9c92a7ea29d62 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 18:38:23 +0300 Subject: [PATCH 04/22] ValueOps#increment properly handles negative vals DATAREDIS-88 --- .../data/redis/core/DefaultValueOperations.java | 6 ------ .../springframework/data/redis/core/TemplateTest.java | 11 +++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java index 133158b63..8d6532036 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultValueOperations.java @@ -73,10 +73,6 @@ class DefaultValueOperations extends AbstractOperations implements V return connection.decr(rawKey); } - if (delta < 0) { - return connection.decrBy(rawKey, delta); - } - return connection.incrBy(rawKey, delta); } }, true); @@ -109,8 +105,6 @@ class DefaultValueOperations extends AbstractOperations implements V return deserializeString(rawReturn); } - @SuppressWarnings("unchecked") - public List multiGet(Collection keys) { if (keys.isEmpty()) { return Collections.emptyList(); diff --git a/src/test/java/org/springframework/data/redis/core/TemplateTest.java b/src/test/java/org/springframework/data/redis/core/TemplateTest.java index 5aac04dc4..3d8b310d6 100644 --- a/src/test/java/org/springframework/data/redis/core/TemplateTest.java +++ b/src/test/java/org/springframework/data/redis/core/TemplateTest.java @@ -15,6 +15,7 @@ */ package org.springframework.data.redis.core; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Collection; @@ -56,4 +57,14 @@ public class TemplateTest { public void testKeys() throws Exception { assertTrue(template.keys("*") != null); } + + @Test + public void testIncrement() throws Exception { + StringRedisTemplate sr = new StringRedisTemplate(template.getConnectionFactory()); + String key = "test.template.inc"; + ValueOperations valueOps = sr.opsForValue(); + valueOps.set(key, "10"); + valueOps.increment(key, -10); + assertEquals(0, Integer.valueOf(valueOps.get(key)).intValue()); + } } From 3bfcc7daf6c062e448f6afa48249e659e5e49c2a Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 19:29:04 +0300 Subject: [PATCH 05/22] add test exclusion to avoid RJC bug for incr(by) DATAREDIS-88 --- .../data/redis/core/TemplateTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/test/java/org/springframework/data/redis/core/TemplateTest.java b/src/test/java/org/springframework/data/redis/core/TemplateTest.java index 3d8b310d6..c665fb621 100644 --- a/src/test/java/org/springframework/data/redis/core/TemplateTest.java +++ b/src/test/java/org/springframework/data/redis/core/TemplateTest.java @@ -19,13 +19,17 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Collection; +import java.util.List; 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.dao.DataAccessException; import org.springframework.data.redis.ConnectionFactoryTracker; +import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.rjc.RjcConnectionFactory; import org.springframework.data.redis.support.collections.CollectionTestParams; import org.springframework.data.redis.support.collections.ObjectFactory; @@ -60,11 +64,33 @@ public class TemplateTest { @Test public void testIncrement() throws Exception { + // disable in case of Rjc + if (isRjc()) { + return; + } + StringRedisTemplate sr = new StringRedisTemplate(template.getConnectionFactory()); String key = "test.template.inc"; ValueOperations valueOps = sr.opsForValue(); valueOps.set(key, "10"); valueOps.increment(key, -10); assertEquals(0, Integer.valueOf(valueOps.get(key)).intValue()); + valueOps.increment(key, -10); + assertEquals(-10, Integer.valueOf(valueOps.get(key)).intValue()); + } + + private boolean isRjc() { + return (template.getConnectionFactory() instanceof RjcConnectionFactory); + } + + //@Test + public void testGetNonExistingKey() throws Exception { + List res = (List) template.execute(new RedisCallback>() { + + public List doInRedis(RedisConnection connection) throws DataAccessException { + connection.hGet("non-existing-key".getBytes(), "some-value".getBytes()); + return connection.closePipeline(); + } + }, true, true); } } From 6028ba86ed3313e0da4216f297474db6d7c8e8f4 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 20:12:09 +0300 Subject: [PATCH 06/22] remove caching of serializers in abstractOps DATAREDIS-85 Since the serializers inside the template might/can change, even at runtime, abstractOps now always asks the template itself for the serializers to avoid missing any changes. --- .../data/redis/core/AbstractOperations.java | 61 +++++++++++-------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/AbstractOperations.java b/src/main/java/org/springframework/data/redis/core/AbstractOperations.java index 85013edc3..fe137dae0 100644 --- a/src/main/java/org/springframework/data/redis/core/AbstractOperations.java +++ b/src/main/java/org/springframework/data/redis/core/AbstractOperations.java @@ -53,23 +53,32 @@ abstract class AbstractOperations { 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; } + RedisSerializer keySerializer() { + return template.getKeySerializer(); + } + + RedisSerializer valueSerializer() { + return template.getValueSerializer(); + } + + RedisSerializer hashKeySerializer() { + return template.getHashKeySerializer(); + } + + RedisSerializer hashValueSerializer() { + return template.getHashValueSerializer(); + } + + RedisSerializer stringSerializer() { + return template.getStringSerializer(); + } + T execute(RedisCallback callback, boolean b) { return template.execute(callback, b); @@ -82,27 +91,27 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") byte[] rawKey(Object key) { Assert.notNull(key, "non null key required"); - return keySerializer.serialize(key); + return keySerializer().serialize(key); } byte[] rawString(String key) { - return stringSerializer.serialize(key); + return stringSerializer().serialize(key); } @SuppressWarnings("unchecked") byte[] rawValue(Object value) { - return valueSerializer.serialize(value); + return valueSerializer().serialize(value); } @SuppressWarnings("unchecked") byte[] rawHashKey(HK hashKey) { Assert.notNull(hashKey, "non null hash key required"); - return hashKeySerializer.serialize(hashKey); + return hashKeySerializer().serialize(hashKey); } @SuppressWarnings("unchecked") byte[] rawHashValue(HV value) { - return hashValueSerializer.serialize(value); + return hashValueSerializer().serialize(value); } byte[][] rawKeys(K key, K otherKey) { @@ -136,31 +145,31 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") Set deserializeValues(Set rawValues) { - return SerializationUtils.deserialize(rawValues, valueSerializer); + return SerializationUtils.deserialize(rawValues, valueSerializer()); } @SuppressWarnings("unchecked") Set> deserializeTupleValues(Set rawValues) { Set> set = new LinkedHashSet>(rawValues.size()); for (Tuple rawValue : rawValues) { - set.add(new DefaultTypedTuple(valueSerializer.deserialize(rawValue.getValue()), rawValue.getScore())); + set.add(new DefaultTypedTuple(valueSerializer().deserialize(rawValue.getValue()), rawValue.getScore())); } return set; } @SuppressWarnings("unchecked") List deserializeValues(List rawValues) { - return SerializationUtils.deserialize(rawValues, valueSerializer); + return SerializationUtils.deserialize(rawValues, valueSerializer()); } @SuppressWarnings("unchecked") Set deserializeHashKeys(Set rawKeys) { - return SerializationUtils.deserialize(rawKeys, hashKeySerializer); + return SerializationUtils.deserialize(rawKeys, hashKeySerializer()); } @SuppressWarnings("unchecked") List deserializeHashValues(List rawValues) { - return SerializationUtils.deserialize(rawValues, hashValueSerializer); + return SerializationUtils.deserialize(rawValues, hashValueSerializer()); } @SuppressWarnings("unchecked") @@ -181,25 +190,25 @@ abstract class AbstractOperations { @SuppressWarnings("unchecked") K deserializeKey(byte[] value) { - return (K) keySerializer.deserialize(value); + return (K) keySerializer().deserialize(value); } @SuppressWarnings("unchecked") V deserializeValue(byte[] value) { - return (V) valueSerializer.deserialize(value); + return (V) valueSerializer().deserialize(value); } String deserializeString(byte[] value) { - return (String) stringSerializer.deserialize(value); + return (String) stringSerializer().deserialize(value); } @SuppressWarnings( { "unchecked" }) HK deserializeHashKey(byte[] value) { - return (HK) hashKeySerializer.deserialize(value); + return (HK) hashKeySerializer().deserialize(value); } @SuppressWarnings("unchecked") HV deserializeHashValue(byte[] value) { - return (HV) hashValueSerializer.deserialize(value); + return (HV) hashValueSerializer().deserialize(value); } } \ No newline at end of file From 646f1e39210d5dee3dc3aa4ee0fc68847d80e13d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 20:29:06 +0300 Subject: [PATCH 07/22] make set *store ops to return the resulting set size DATAREDIS-86 --- .../DefaultStringRedisConnection.java | 12 +++++----- .../redis/connection/RedisSetCommands.java | 6 ++--- .../connection/jedis/JedisConnection.java | 24 +++++++++---------- .../connection/jredis/JredisConnection.java | 9 ++++--- .../redis/connection/rjc/RjcConnection.java | 18 +++++++------- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 191b87cfc..97012ddaa 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -372,8 +372,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.sDiff(keys); } - public void sDiffStore(byte[] destKey, byte[]... keys) { - delegate.sDiffStore(destKey, keys); + public Long sDiffStore(byte[] destKey, byte[]... keys) { + return delegate.sDiffStore(destKey, keys); } public void select(int dbIndex) { @@ -412,8 +412,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.sInter(keys); } - public void sInterStore(byte[] destKey, byte[]... keys) { - delegate.sInterStore(destKey, keys); + public Long sInterStore(byte[] destKey, byte[]... keys) { + return delegate.sInterStore(destKey, keys); } public Boolean sIsMember(byte[] key, byte[] value) { @@ -460,8 +460,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection { return delegate.sUnion(keys); } - public void sUnionStore(byte[] destKey, byte[]... keys) { - delegate.sUnionStore(destKey, keys); + public Long sUnionStore(byte[] destKey, byte[]... keys) { + return delegate.sUnionStore(destKey, keys); } public Long ttl(byte[] key) { diff --git a/src/main/java/org/springframework/data/redis/connection/RedisSetCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisSetCommands.java index f3ec271ef..3c07ae99b 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisSetCommands.java @@ -39,15 +39,15 @@ public interface RedisSetCommands { Set sInter(byte[]... keys); - void sInterStore(byte[] destKey, byte[]... keys); + Long sInterStore(byte[] destKey, byte[]... keys); Set sUnion(byte[]... keys); - void sUnionStore(byte[] destKey, byte[]... keys); + Long sUnionStore(byte[] destKey, byte[]... keys); Set sDiff(byte[]... keys); - void sDiffStore(byte[] destKey, byte[]... keys); + Long sDiffStore(byte[] destKey, byte[]... keys); Set sMembers(byte[] key); diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index 7899ab558..bd764940b 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -1423,17 +1423,17 @@ public class JedisConnection implements RedisConnection { } - public void sDiffStore(byte[] destKey, byte[]... keys) { + public Long sDiffStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { transaction.sdiffstore(destKey, keys); - return; + return null; } if (isPipelined()) { pipeline.sdiffstore(destKey, keys); - return; + return null; } - jedis.sdiffstore(destKey, keys); + return jedis.sdiffstore(destKey, keys); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -1457,17 +1457,17 @@ public class JedisConnection implements RedisConnection { } - public void sInterStore(byte[] destKey, byte[]... keys) { + public Long sInterStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { transaction.sinterstore(destKey, keys); - return; + return null; } if (isPipelined()) { pipeline.sinterstore(destKey, keys); - return; + return null; } - jedis.sinterstore(destKey, keys); + return jedis.sinterstore(destKey, keys); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -1593,17 +1593,17 @@ public class JedisConnection implements RedisConnection { } - public void sUnionStore(byte[] destKey, byte[]... keys) { + public Long sUnionStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { transaction.sunionstore(destKey, keys); - return; + return null; } if (isPipelined()) { pipeline.sunionstore(destKey, keys); - return; + return null; } - jedis.sunionstore(destKey, keys); + return jedis.sunionstore(destKey, keys); } catch (Exception ex) { throw convertJedisAccessException(ex); } diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java index e7d4a3a92..2ea1d5556 100644 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java @@ -710,12 +710,13 @@ public class JredisConnection implements RedisConnection { } - public void sDiffStore(byte[] destKey, byte[]... keys) { + public Long sDiffStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); try { jredis.sdiffstore(destSet, sets); + return Long.valueOf(-1); } catch (Exception ex) { throw convertJredisAccessException(ex); } @@ -735,12 +736,13 @@ public class JredisConnection implements RedisConnection { } - public void sInterStore(byte[] destKey, byte[]... keys) { + public Long sInterStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); try { jredis.sinterstore(destSet, sets); + return Long.valueOf(-1); } catch (Exception ex) { throw convertJredisAccessException(ex); } @@ -813,12 +815,13 @@ public class JredisConnection implements RedisConnection { } - public void sUnionStore(byte[] destKey, byte[]... keys) { + public Long sUnionStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); try { jredis.sunionstore(destSet, sets); + return Long.valueOf(-1); } catch (Exception ex) { throw convertJredisAccessException(ex); } diff --git a/src/main/java/org/springframework/data/redis/connection/rjc/RjcConnection.java b/src/main/java/org/springframework/data/redis/connection/rjc/RjcConnection.java index 19c7a6fc6..67a3b5801 100644 --- a/src/main/java/org/springframework/data/redis/connection/rjc/RjcConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/rjc/RjcConnection.java @@ -1254,7 +1254,7 @@ public class RjcConnection implements RedisConnection { } - public void sDiffStore(byte[] destKey, byte[]... keys) { + public Long sDiffStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1262,9 +1262,9 @@ public class RjcConnection implements RedisConnection { if (isPipelined()) { pipeline.sdiffstore(stringKey, stringKeys); - return; + return null; } - session.sdiffstore(stringKey, stringKeys); + return session.sdiffstore(stringKey, stringKeys); } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -1286,16 +1286,16 @@ public class RjcConnection implements RedisConnection { } - public void sInterStore(byte[] destKey, byte[]... keys) { + public Long sInterStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); try { if (isPipelined()) { pipeline.sinterstore(stringKey, stringKeys); - return; + return null; } - session.sinterstore(stringKey, stringKeys); + return session.sinterstore(stringKey, stringKeys); } catch (Exception ex) { throw convertRjcAccessException(ex); } @@ -1415,7 +1415,7 @@ public class RjcConnection implements RedisConnection { } - public void sUnionStore(byte[] destKey, byte[]... keys) { + public Long sUnionStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1423,9 +1423,9 @@ public class RjcConnection implements RedisConnection { if (isPipelined()) { pipeline.sunionstore(stringKey, stringKeys); - return; + return null; } - session.sunionstore(stringKey, stringKeys); + return session.sunionstore(stringKey, stringKeys); } catch (Exception ex) { throw convertRjcAccessException(ex); } From 042f3e8ca40dcf374bbe0e16e9ebc5756f7701ca Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 20:32:34 +0300 Subject: [PATCH 08/22] Make Template Set *storeOps() return the resulting set size DATAREDIS-86 --- .../data/redis/core/DefaultSetOperations.java | 42 ++++++++----------- .../data/redis/core/SetOperations.java | 12 +++--- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java index 63ab5d37d..f34689880 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultSetOperations.java @@ -49,8 +49,6 @@ class DefaultSetOperations extends AbstractOperations implements Set return difference(key, Collections.singleton(otherKey)); } - @SuppressWarnings("unchecked") - public Set difference(final K key, final Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { @@ -64,19 +62,18 @@ class DefaultSetOperations extends AbstractOperations implements Set } - public void differenceAndStore(K key, K otherKey, K destKey) { - differenceAndStore(key, Collections.singleton(otherKey), destKey); + public Long differenceAndStore(K key, K otherKey, K destKey) { + return differenceAndStore(key, Collections.singleton(otherKey), destKey); } - public void differenceAndStore(final K key, final Collection otherKeys, K destKey) { + public Long differenceAndStore(final K key, final Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { + return execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { - connection.sDiffStore(rawDestKey, rawKeys); - return null; + public Long doInRedis(RedisConnection connection) { + return connection.sDiffStore(rawDestKey, rawKeys); } }, true); } @@ -86,8 +83,6 @@ class DefaultSetOperations extends AbstractOperations implements Set return intersect(key, Collections.singleton(otherKey)); } - @SuppressWarnings("unchecked") - public Set intersect(K key, Collection otherKeys) { final byte[][] rawKeys = rawKeys(key, otherKeys); Set rawValues = execute(new RedisCallback>() { @@ -101,17 +96,17 @@ class DefaultSetOperations extends AbstractOperations implements Set } - public void intersectAndStore(K key, K otherKey, K destKey) { - intersectAndStore(key, Collections.singleton(otherKey), destKey); + public Long intersectAndStore(K key, K otherKey, K destKey) { + return intersectAndStore(key, Collections.singleton(otherKey), destKey); } - public void intersectAndStore(K key, Collection otherKeys, K destKey) { + public Long intersectAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { + return execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { + public Long doInRedis(RedisConnection connection) { connection.sInterStore(rawDestKey, rawKeys); return null; } @@ -130,8 +125,6 @@ class DefaultSetOperations extends AbstractOperations implements Set }, true); } - @SuppressWarnings("unchecked") - public Set members(K key) { final byte[] rawKey = rawKey(key); Set rawValues = execute(new RedisCallback>() { @@ -222,19 +215,18 @@ class DefaultSetOperations extends AbstractOperations implements Set } - public void unionAndStore(K key, K otherKey, K destKey) { - unionAndStore(key, Collections.singleton(otherKey), destKey); + public Long unionAndStore(K key, K otherKey, K destKey) { + return unionAndStore(key, Collections.singleton(otherKey), destKey); } - public void unionAndStore(K key, Collection otherKeys, K destKey) { + public Long unionAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { + return execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { - connection.sUnionStore(rawDestKey, rawKeys); - return null; + public Long doInRedis(RedisConnection connection) { + return connection.sUnionStore(rawDestKey, rawKeys); } }, true); } diff --git a/src/main/java/org/springframework/data/redis/core/SetOperations.java b/src/main/java/org/springframework/data/redis/core/SetOperations.java index b8a078bec..f54be4325 100644 --- a/src/main/java/org/springframework/data/redis/core/SetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/SetOperations.java @@ -30,25 +30,25 @@ public interface SetOperations { Set difference(K key, Collection otherKeys); - void differenceAndStore(K key, K otherKey, K destKey); + Long differenceAndStore(K key, K otherKey, K destKey); - void differenceAndStore(K key, Collection otherKeys, K destKey); + Long differenceAndStore(K key, Collection otherKeys, K destKey); Set intersect(K key, K otherKey); Set intersect(K key, Collection otherKeys); - void intersectAndStore(K key, K otherKey, K destKey); + Long intersectAndStore(K key, K otherKey, K destKey); - void intersectAndStore(K key, Collection otherKeys, K destKey); + Long intersectAndStore(K key, Collection otherKeys, K destKey); Set union(K key, K otherKey); Set union(K key, Collection otherKeys); - void unionAndStore(K key, K otherKey, K destKey); + Long unionAndStore(K key, K otherKey, K destKey); - void unionAndStore(K key, Collection otherKeys, K destKey); + Long unionAndStore(K key, Collection otherKeys, K destKey); Boolean add(K key, V value); From 8684be99fb5664c047f5b4ed4fb94794708093c5 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 20:35:17 +0300 Subject: [PATCH 09/22] Make Template Set *storeOps() return the resulting set size DATAREDIS-86 --- .../redis/core/DefaultZSetOperations.java | 26 +++++++++---------- .../data/redis/core/ZSetOperations.java | 8 +++--- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java index 5cf540faa..bb20ff4ad 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java @@ -60,19 +60,18 @@ class DefaultZSetOperations extends AbstractOperations implements ZS } - public void intersectAndStore(K key, K otherKey, K destKey) { - intersectAndStore(key, Collections.singleton(otherKey), destKey); + public Long intersectAndStore(K key, K otherKey, K destKey) { + return intersectAndStore(key, Collections.singleton(otherKey), destKey); } - public void intersectAndStore(K key, Collection otherKeys, K destKey) { + public Long intersectAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { + return execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { - connection.zInterStore(rawDestKey, rawKeys); - return null; + public Long doInRedis(RedisConnection connection) { + return connection.zInterStore(rawDestKey, rawKeys); } }, true); } @@ -294,19 +293,18 @@ class DefaultZSetOperations extends AbstractOperations implements ZS } - public void unionAndStore(K key, K otherKey, K destKey) { - unionAndStore(key, Collections.singleton(otherKey), destKey); + public Long unionAndStore(K key, K otherKey, K destKey) { + return unionAndStore(key, Collections.singleton(otherKey), destKey); } - public void unionAndStore(K key, Collection otherKeys, K destKey) { + public Long unionAndStore(K key, Collection otherKeys, K destKey) { final byte[][] rawKeys = rawKeys(key, otherKeys); final byte[] rawDestKey = rawKey(destKey); - execute(new RedisCallback() { + return execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { - connection.zUnionStore(rawDestKey, rawKeys); - return null; + public Long doInRedis(RedisConnection connection) { + return connection.zUnionStore(rawDestKey, rawKeys); } }, true); } diff --git a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java index 54a363d1e..42ef3aa45 100644 --- a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java @@ -35,13 +35,13 @@ public interface ZSetOperations { Double getScore(); } - void intersectAndStore(K key, K otherKey, K destKey); + Long intersectAndStore(K key, K otherKey, K destKey); - void intersectAndStore(K key, Collection otherKeys, K destKey); + Long intersectAndStore(K key, Collection otherKeys, K destKey); - void unionAndStore(K key, K otherKey, K destKey); + Long unionAndStore(K key, K otherKey, K destKey); - void unionAndStore(K key, Collection otherKeys, K destKey); + Long unionAndStore(K key, Collection otherKeys, K destKey); Set range(K key, long start, long end); From fa44da26fad27b5e710601b96d4780079c53b53c Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 20:37:43 +0300 Subject: [PATCH 10/22] ZSetOps#removeRange* return the # of elements removed DATAREDIS-86 --- .../data/redis/core/DefaultZSetOperations.java | 18 ++++++++---------- .../data/redis/core/ZSetOperations.java | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java index bb20ff4ad..79382b4f2 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultZSetOperations.java @@ -232,25 +232,23 @@ class DefaultZSetOperations extends AbstractOperations implements ZS } - public void removeRange(K key, final long start, final long end) { + public Long removeRange(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); - execute(new RedisCallback() { + return execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { - connection.zRemRange(rawKey, start, end); - return null; + public Long doInRedis(RedisConnection connection) { + return connection.zRemRange(rawKey, start, end); } }, true); } - public void removeRangeByScore(K key, final double min, final double max) { + public Long removeRangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); - execute(new RedisCallback() { + return execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { - connection.zRemRangeByScore(rawKey, min, max); - return null; + public Long doInRedis(RedisConnection connection) { + return connection.zRemRangeByScore(rawKey, min, max); } }, true); } diff --git a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java index 42ef3aa45..4014e4c9e 100644 --- a/src/main/java/org/springframework/data/redis/core/ZSetOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ZSetOperations.java @@ -71,9 +71,9 @@ public interface ZSetOperations { Boolean remove(K key, Object o); - void removeRange(K key, long start, long end); + Long removeRange(K key, long start, long end); - void removeRangeByScore(K key, double min, double max); + Long removeRangeByScore(K key, double min, double max); Long count(K key, double min, double max); From c44f9d41402a33448958ca66c210823b1a26f92d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 21:08:18 +0300 Subject: [PATCH 11/22] upgrade to Jedis 2.1.0 incl. prev unsupported methods DATAREDIS-90 the upgrade provides a fix as well when connecting to Jedis 2.0.0 for backwards compatibility --- gradle.properties | 6 +++--- .../connection/jedis/JedisConnection.java | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index f2e892a26..66da45e04 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ log4jVersion = 1.2.16 slf4jVersion = 1.6.4 # Common libraries -springVersion = 3.1.0.RELEASE +springVersion = 3.1.1.RELEASE jacksonVersion = 1.8.6 # Testing @@ -13,7 +13,7 @@ junitVersion = 4.8.1 mockitoVersion = 1.8.5 # Drivers -jedisVersion = 2.0.0 +jedisVersion = 2.1.0 jredisVersion = 03122010 rjcVersion= 0.6.4 @@ -21,7 +21,7 @@ rjcVersion= 0.6.4 ## OSGi ranges spring.range = "[3.1.0, 4.0.0)" -jedis.range = "[2.0.0, 2.0.0]" +jedis.range = "[2.1.0, 2.1.0]" jackson.range = "[1.6, 2.0.0)" rjc.range = "[0.6.4, 0.6.4]" diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index bd764940b..ccd926bcd 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -1021,7 +1021,14 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { throw new UnsupportedOperationException(); } - return (jedis.getbit(key, offset) == 0 ? Boolean.FALSE : Boolean.TRUE); + // compatibility check for Jedis 2.0.0 + Object getBit = jedis.getbit(key, offset); + // Jedis 2.0 + if (getBit instanceof Long) { + return (((Long)getBit) == 0 ? Boolean.FALSE : Boolean.TRUE); + } + // Jedis 2.1 + return ((Boolean) getBit); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -1846,7 +1853,7 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { throw new UnsupportedOperationException(); } - throw new UnsupportedOperationException(); + return jedis.zrevrangeByScore(key, max, min, (int) offset, (int) count); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -1861,7 +1868,7 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { throw new UnsupportedOperationException(); } - throw new UnsupportedOperationException(); + return jedis.zrevrangeByScore(key, max, min); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -1876,7 +1883,8 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { throw new UnsupportedOperationException(); } - throw new UnsupportedOperationException(); + return JedisUtils.convertJedisTuple(jedis.zrevrangeByScoreWithScores(key, max, min, (int) offset, + (int) count)); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -1891,7 +1899,7 @@ public class JedisConnection implements RedisConnection { if (isPipelined()) { throw new UnsupportedOperationException(); } - throw new UnsupportedOperationException(); + return JedisUtils.convertJedisTuple(jedis.zrevrangeByScoreWithScores(key, max, min)); } catch (Exception ex) { throw convertJedisAccessException(ex); } From 99df3d123a53a4b859d5cf98c050f358ef2bc86d Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Wed, 23 May 2012 21:09:54 +0300 Subject: [PATCH 12/22] remove Eclipse files since they are not portable --- .classpath | 38 ---------------------------- .gitignore | 3 ++- .project | 16 ------------ .settings/org.eclipse.jdt.core.prefs | 13 ---------- 4 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 .classpath delete mode 100644 .project delete mode 100644 .settings/org.eclipse.jdt.core.prefs diff --git a/.classpath b/.classpath deleted file mode 100644 index 4d236507f..000000000 --- a/.classpath +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore index 863410265..140bc3589 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ pom.xml *.iws *.log .classpath -.project \ No newline at end of file +.project +.settings diff --git a/.project b/.project deleted file mode 100644 index 862bb3d6d..000000000 --- a/.project +++ /dev/null @@ -1,16 +0,0 @@ - - - spring-data-redis - Spring Data Redis - - - org.eclipse.jdt.core.javanature - - - - org.eclipse.jdt.core.javabuilder - - - - - diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index be590e07c..000000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,13 +0,0 @@ -# -#Tue Dec 13 20:42:40 EET 2011 -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.source=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error From 6686d63bcd2f9ae5e113345204e3c985e7e6aea0 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 19 Jun 2012 19:12:39 +0300 Subject: [PATCH 13/22] make internal class protected --- .../data/redis/config/RedisCollectionParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/redis/config/RedisCollectionParser.java b/src/main/java/org/springframework/data/redis/config/RedisCollectionParser.java index f1d79c9bd..4ecebf0c1 100644 --- a/src/main/java/org/springframework/data/redis/config/RedisCollectionParser.java +++ b/src/main/java/org/springframework/data/redis/config/RedisCollectionParser.java @@ -26,7 +26,7 @@ import org.w3c.dom.Element; * * @author Costin Leau */ -public class RedisCollectionParser extends AbstractSimpleBeanDefinitionParser { +class RedisCollectionParser extends AbstractSimpleBeanDefinitionParser { protected Class getBeanClass(Element element) { From 74668976ce71dc2114ff0ce8f5ce9f4e0270c92f Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Tue, 19 Jun 2012 19:20:41 +0300 Subject: [PATCH 14/22] fix incorrect pipeline condition in JedisConnection DATAREDIS-93 --- .../data/redis/connection/jedis/JedisConnection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index ccd926bcd..4d45a535c 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -1661,7 +1661,7 @@ public class JedisConnection implements RedisConnection { transaction.zcount(key, min, max); return null; } - if (isQueueing()) { + if (isPipelined()) { pipeline.zcount(key, min, max); return null; } @@ -1715,7 +1715,7 @@ public class JedisConnection implements RedisConnection { transaction.zinterstore(destKey, sets); return null; } - if (isQueueing()) { + if (isPipelined()) { pipeline.zinterstore(destKey, sets); return null; } From 27f293ecbbf7cfdcd7032291a85e9a5b0510d2e8 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 21 Jun 2012 14:26:34 +0300 Subject: [PATCH 15/22] simplify binding of Redis connections to prevent messing up ongoing synchronizations --- .../data/redis/core/RedisConnectionUtils.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java b/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java index 02feabe07..3f65b35c2 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java +++ b/src/main/java/org/springframework/data/redis/core/RedisConnectionUtils.java @@ -81,14 +81,8 @@ public abstract class RedisConnectionUtils { RedisConnection conn = factory.getConnection(); - boolean synchronizationActive = TransactionSynchronizationManager.isSynchronizationActive(); - - if (bind || synchronizationActive) { + if (bind) { connHolder = new RedisConnectionHolder(conn); - if (synchronizationActive) { - TransactionSynchronizationManager.registerSynchronization(new RedisConnectionSynchronization( - connHolder, factory, true)); - } TransactionSynchronizationManager.bindResource(factory, connHolder); return connHolder.getConnection(); } From f200b5fceb9b938be5add08699b0139c71c86ed8 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 21 Jun 2012 14:40:05 +0300 Subject: [PATCH 16/22] fix bug in closing the pipeline --- .../data/redis/core/RedisTemplate.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java index cf9c54964..5a404083c 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -160,16 +160,16 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation try { RedisConnection connToExpose = (exposeConnection ? conn : createRedisConnectionProxy(conn)); T result = action.doInRedis(connToExpose); + + // close pipeline + if (pipeline && !pipelineStatus) { + conn.closePipeline(); + } + // TODO: any other connection processing? return postProcessResult(result, conn, existingConnection); } finally { - try { - if (pipeline && !pipelineStatus) { - conn.closePipeline(); - } - } finally { - RedisConnectionUtils.releaseConnection(conn, factory); - } + RedisConnectionUtils.releaseConnection(conn, factory); } } From 35cc2760409ae06746f42f6b607c2b8b91822476 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 21 Jun 2012 14:40:18 +0300 Subject: [PATCH 17/22] make use of repo.springsource.org --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index f0ab280eb..b561df415 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,11 @@ buildscript { } } +repositories { + mavenRepo name: "springsource", urls: "http://repo.springsource.org/libs-snapshot" +} + + allprojects { group = 'org.springframework.data.redis' version = "$springDataRedisVersion" From 1d03085a8158ca38d792b8049977b8bc8ea92ebc Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 21 Jun 2012 17:11:46 +0300 Subject: [PATCH 18/22] add native execute for JedisConnection --- .../DefaultStringRedisConnection.java | 9 + .../data/redis/connection/RedisCommands.java | 12 + .../connection/StringRedisConnection.java | 2 + .../connection/jedis/JedisConnection.java | 319 ++++++++++-------- .../AbstractConnectionIntegrationTests.java | 18 +- 5 files changed, 213 insertions(+), 147 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 97012ddaa..9714e51c2 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -1152,4 +1152,13 @@ public class DefaultStringRedisConnection implements StringRedisConnection { public void openPipeline() { delegate.openPipeline(); } + + + public Object execute(String command, byte[]... args) { + return delegate.execute(command, args); + } + + public Object execute(String command, String... args) { + return execute(command, serializeMulti(args)); + } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/redis/connection/RedisCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisCommands.java index 507d6faee..ff3ff20c7 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisCommands.java @@ -25,4 +25,16 @@ package org.springframework.data.redis.connection; public interface RedisCommands extends RedisKeyCommands, RedisStringCommands, RedisListCommands, RedisSetCommands, RedisZSetCommands, RedisHashCommands, RedisTxCommands, RedisPubSubCommands, RedisConnectionCommands, RedisServerCommands { + + + /** + * 'Native' or 'raw' execution of the given command along-side the given arguments. + * The command is executed as is, with as little 'interpretation' as possible - it is up to the caller + * to take care of any processing of arguments or the result. + * + * @param command Command to execute + * @param args Possible command arguments (may be null) + * @return execution result. + */ + Object execute(String command, byte[]... args); } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java index a3edf9984..4d92b09f7 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -42,6 +42,8 @@ public interface StringRedisConnection extends RedisConnection { String getValueAsString(); } + Object execute(String command, String... args); + Boolean exists(String key); Long del(String... keys); diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index 4d45a535c..2ad170877 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -17,6 +17,7 @@ package org.springframework.data.redis.connection.jedis; import java.io.IOException; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -32,14 +33,19 @@ import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisSubscribedConnectionException; import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; +import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import redis.clients.jedis.BinaryJedis; import redis.clients.jedis.BinaryJedisPubSub; import redis.clients.jedis.BinaryTransaction; +import redis.clients.jedis.Builder; import redis.clients.jedis.Client; +import redis.clients.jedis.Connection; import redis.clients.jedis.Jedis; import redis.clients.jedis.Pipeline; +import redis.clients.jedis.Protocol.Command; +import redis.clients.jedis.Queable; import redis.clients.jedis.SortingParams; import redis.clients.jedis.Transaction; import redis.clients.jedis.ZParams; @@ -55,10 +61,17 @@ import redis.clients.util.Pool; public class JedisConnection implements RedisConnection { private static final Field CLIENT_FIELD; + private static final Method SEND_COMMAND; + private static final Method GET_RESPONSE; static { CLIENT_FIELD = ReflectionUtils.findField(BinaryJedis.class, "client", Client.class); ReflectionUtils.makeAccessible(CLIENT_FIELD); + SEND_COMMAND = ReflectionUtils.findMethod(Connection.class, "sendCommand", + new Class[] { Command.class, byte[][].class }); + ReflectionUtils.makeAccessible(SEND_COMMAND); + GET_RESPONSE = ReflectionUtils.findMethod(Queable.class, "getResponse", Builder.class); + ReflectionUtils.makeAccessible(GET_RESPONSE); } private final Jedis jedis; @@ -119,7 +132,34 @@ public class JedisConnection implements RedisConnection { return new RedisSystemException("Unknown jedis exception", ex); } - + public Object execute(String command, byte[]... args) { + Assert.hasText(command, "a valid command needs to be specified"); + List mArgs = new ArrayList(); + if (args == null) { + mArgs.add(new byte[0]); + } + else { + Collections.addAll(mArgs, args); + } + + Object result = ReflectionUtils.invokeMethod(SEND_COMMAND, client, + Command.valueOf(command.trim().toUpperCase()), mArgs.toArray(new byte[mArgs.size()][])); + if (isQueueing() || isPipelined()) { + Object target = (isPipelined() ? pipeline : transaction); + ReflectionUtils.invokeMethod(GET_RESPONSE, target, new Builder() { + public Object build(Object data) { + return data; + } + + public String toString() { + return "Object"; + } + }); + } + + return result; + } + public void close() throws DataAccessException { // return the connection to the pool try { @@ -158,12 +198,12 @@ public class JedisConnection implements RedisConnection { } } - + public Jedis getNativeConnection() { return jedis; } - + public boolean isClosed() { try { return !jedis.isConnected(); @@ -172,17 +212,17 @@ public class JedisConnection implements RedisConnection { } } - + public boolean isQueueing() { return client.isInMulti(); } - + public boolean isPipelined() { return (pipeline != null); } - + public void openPipeline() { if (pipeline == null) { pipeline = jedis.pipelined(); @@ -190,7 +230,6 @@ public class JedisConnection implements RedisConnection { } @SuppressWarnings("unchecked") - public List closePipeline() { if (pipeline != null) { List execute = pipeline.syncAndReturnAll(); @@ -201,7 +240,7 @@ public class JedisConnection implements RedisConnection { return Collections.emptyList(); } - + public List sort(byte[] key, SortParameters params) { SortingParams sortParams = JedisUtils.convertSortParams(params); @@ -233,7 +272,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long sort(byte[] key, SortParameters params, byte[] sortKey) { SortingParams sortParams = JedisUtils.convertSortParams(params); @@ -265,14 +304,14 @@ public class JedisConnection implements RedisConnection { } } - + public Long dbSize() { try { if (isQueueing()) { - throw new UnsupportedOperationException(); + transaction.dbSize(); } if (isPipelined()) { - throw new UnsupportedOperationException(); + pipeline.dbSize(); } return jedis.dbSize(); } catch (Exception ex) { @@ -281,14 +320,14 @@ public class JedisConnection implements RedisConnection { } - + public void flushDb() { try { if (isQueueing()) { - throw new UnsupportedOperationException(); + transaction.flushDB(); } if (isPipelined()) { - throw new UnsupportedOperationException(); + pipeline.flushDB(); } jedis.flushDB(); } catch (Exception ex) { @@ -296,14 +335,14 @@ public class JedisConnection implements RedisConnection { } } - + public void flushAll() { try { if (isQueueing()) { - throw new UnsupportedOperationException(); + transaction.flushAll(); } if (isPipelined()) { - throw new UnsupportedOperationException(); + pipeline.flushAll(); } jedis.flushAll(); } catch (Exception ex) { @@ -311,7 +350,7 @@ public class JedisConnection implements RedisConnection { } } - + public void bgSave() { try { if (isQueueing()) { @@ -327,7 +366,7 @@ public class JedisConnection implements RedisConnection { } } - + public void bgWriteAof() { try { if (isQueueing()) { @@ -343,7 +382,7 @@ public class JedisConnection implements RedisConnection { } } - + public void save() { try { if (isQueueing()) { @@ -359,7 +398,7 @@ public class JedisConnection implements RedisConnection { } } - + public List getConfig(String param) { try { if (isQueueing()) { @@ -375,7 +414,7 @@ public class JedisConnection implements RedisConnection { } } - + public Properties info() { try { if (isQueueing()) { @@ -390,7 +429,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long lastSave() { try { if (isQueueing()) { @@ -406,7 +445,7 @@ public class JedisConnection implements RedisConnection { } } - + public void setConfig(String param, String value) { try { if (isQueueing()) { @@ -423,7 +462,7 @@ public class JedisConnection implements RedisConnection { } - + public void resetConfigStats() { try { if (isQueueing()) { @@ -439,7 +478,7 @@ public class JedisConnection implements RedisConnection { } } - + public void shutdown() { try { if (isQueueing()) { @@ -454,7 +493,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] echo(byte[] message) { try { if (isQueueing()) { @@ -470,7 +509,7 @@ public class JedisConnection implements RedisConnection { } } - + public String ping() { try { if (isQueueing()) { @@ -485,7 +524,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long del(byte[]... keys) { try { if (isQueueing()) { @@ -502,7 +541,7 @@ public class JedisConnection implements RedisConnection { } } - + public void discard() { try { client.discard(); @@ -511,7 +550,7 @@ public class JedisConnection implements RedisConnection { } } - + public List exec() { try { if (isPipelined()) { @@ -524,7 +563,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean exists(byte[] key) { try { if (isQueueing()) { @@ -541,7 +580,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean expire(byte[] key, long seconds) { try { if (isQueueing()) { @@ -558,7 +597,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean expireAt(byte[] key, long unixTime) { try { if (isQueueing()) { @@ -575,7 +614,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set keys(byte[] pattern) { try { if (isQueueing()) { @@ -592,7 +631,7 @@ public class JedisConnection implements RedisConnection { } } - + public void multi() { if (isQueueing()) { return; @@ -608,7 +647,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean persist(byte[] key) { try { if (isQueueing()) { @@ -625,7 +664,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean move(byte[] key, int dbIndex) { try { if (isQueueing()) { @@ -642,7 +681,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] randomKey() { try { if (isQueueing()) { @@ -657,7 +696,7 @@ public class JedisConnection implements RedisConnection { } } - + public void rename(byte[] oldName, byte[] newName) { try { if (isQueueing()) { @@ -674,7 +713,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean renameNX(byte[] oldName, byte[] newName) { try { if (isQueueing()) { @@ -691,7 +730,7 @@ public class JedisConnection implements RedisConnection { } } - + public void select(int dbIndex) { try { if (isQueueing()) { @@ -706,7 +745,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long ttl(byte[] key) { try { if (isQueueing()) { @@ -723,7 +762,7 @@ public class JedisConnection implements RedisConnection { } } - + public DataType type(byte[] key) { try { if (isQueueing()) { @@ -740,7 +779,7 @@ public class JedisConnection implements RedisConnection { } } - + public void unwatch() { try { jedis.unwatch(); @@ -749,7 +788,7 @@ public class JedisConnection implements RedisConnection { } } - + public void watch(byte[]... keys) { if (isQueueing()) { throw new UnsupportedOperationException(); @@ -772,7 +811,7 @@ public class JedisConnection implements RedisConnection { // String commands // - + public byte[] get(byte[] key) { try { if (isQueueing()) { @@ -790,7 +829,7 @@ public class JedisConnection implements RedisConnection { } } - + public void set(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -808,7 +847,7 @@ public class JedisConnection implements RedisConnection { } - + public byte[] getSet(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -825,7 +864,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long append(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -842,7 +881,7 @@ public class JedisConnection implements RedisConnection { } } - + public List mGet(byte[]... keys) { try { if (isQueueing()) { @@ -859,7 +898,7 @@ public class JedisConnection implements RedisConnection { } } - + public void mSet(Map tuples) { try { if (isQueueing()) { @@ -876,7 +915,7 @@ public class JedisConnection implements RedisConnection { } } - + public void mSetNX(Map tuples) { try { if (isQueueing()) { @@ -893,7 +932,7 @@ public class JedisConnection implements RedisConnection { } } - + public void setEx(byte[] key, long time, byte[] value) { try { if (isQueueing()) { @@ -910,7 +949,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean setNX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -927,7 +966,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] getRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -944,7 +983,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long decr(byte[] key) { try { if (isQueueing()) { @@ -961,7 +1000,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long decrBy(byte[] key, long value) { try { if (isQueueing()) { @@ -978,7 +1017,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long incr(byte[] key) { try { if (isQueueing()) { @@ -995,7 +1034,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long incrBy(byte[] key, long value) { try { if (isQueueing()) { @@ -1012,7 +1051,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean getBit(byte[] key, long offset) { try { if (isQueueing()) { @@ -1025,7 +1064,7 @@ public class JedisConnection implements RedisConnection { Object getBit = jedis.getbit(key, offset); // Jedis 2.0 if (getBit instanceof Long) { - return (((Long)getBit) == 0 ? Boolean.FALSE : Boolean.TRUE); + return (((Long) getBit) == 0 ? Boolean.FALSE : Boolean.TRUE); } // Jedis 2.1 return ((Boolean) getBit); @@ -1034,7 +1073,7 @@ public class JedisConnection implements RedisConnection { } } - + public void setBit(byte[] key, long offset, boolean value) { try { if (isQueueing()) { @@ -1049,7 +1088,7 @@ public class JedisConnection implements RedisConnection { } } - + public void setRange(byte[] key, byte[] value, long start) { try { if (isQueueing()) { @@ -1064,7 +1103,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long strLen(byte[] key) { try { if (isQueueing()) { @@ -1085,7 +1124,7 @@ public class JedisConnection implements RedisConnection { // List commands // - + public Long lPush(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1102,7 +1141,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long rPush(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1119,7 +1158,7 @@ public class JedisConnection implements RedisConnection { } } - + public List bLPop(int timeout, byte[]... keys) { try { if (isQueueing()) { @@ -1136,7 +1175,7 @@ public class JedisConnection implements RedisConnection { } } - + public List bRPop(int timeout, byte[]... keys) { try { if (isQueueing()) { @@ -1152,7 +1191,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] lIndex(byte[] key, long index) { try { if (isQueueing()) { @@ -1169,7 +1208,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { try { if (isQueueing()) { @@ -1186,7 +1225,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long lLen(byte[] key) { try { if (isQueueing()) { @@ -1203,7 +1242,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] lPop(byte[] key) { try { if (isQueueing()) { @@ -1220,7 +1259,7 @@ public class JedisConnection implements RedisConnection { } } - + public List lRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1237,7 +1276,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long lRem(byte[] key, long count, byte[] value) { try { if (isQueueing()) { @@ -1254,7 +1293,7 @@ public class JedisConnection implements RedisConnection { } } - + public void lSet(byte[] key, long index, byte[] value) { try { if (isQueueing()) { @@ -1271,7 +1310,7 @@ public class JedisConnection implements RedisConnection { } } - + public void lTrim(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1288,7 +1327,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] rPop(byte[] key) { try { if (isQueueing()) { @@ -1305,7 +1344,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { if (isQueueing()) { @@ -1322,7 +1361,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { try { if (isQueueing()) { @@ -1339,7 +1378,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long lPushX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1356,7 +1395,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long rPushX(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1378,7 +1417,7 @@ public class JedisConnection implements RedisConnection { // Set commands // - + public Boolean sAdd(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1395,7 +1434,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long sCard(byte[] key) { try { if (isQueueing()) { @@ -1412,7 +1451,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set sDiff(byte[]... keys) { try { if (isQueueing()) { @@ -1429,7 +1468,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long sDiffStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1446,7 +1485,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set sInter(byte[]... keys) { try { if (isQueueing()) { @@ -1463,7 +1502,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long sInterStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1480,7 +1519,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean sIsMember(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1497,7 +1536,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set sMembers(byte[] key) { try { if (isQueueing()) { @@ -1514,7 +1553,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { if (isQueueing()) { @@ -1531,7 +1570,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] sPop(byte[] key) { try { if (isQueueing()) { @@ -1548,7 +1587,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] sRandMember(byte[] key) { try { if (isQueueing()) { @@ -1565,7 +1604,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean sRem(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1582,7 +1621,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set sUnion(byte[]... keys) { try { if (isQueueing()) { @@ -1599,7 +1638,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long sUnionStore(byte[] destKey, byte[]... keys) { try { if (isQueueing()) { @@ -1620,7 +1659,7 @@ public class JedisConnection implements RedisConnection { // ZSet commands // - + public Boolean zAdd(byte[] key, double score, byte[] value) { try { if (isQueueing()) { @@ -1637,7 +1676,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zCard(byte[] key) { try { if (isQueueing()) { @@ -1654,7 +1693,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zCount(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1671,7 +1710,7 @@ public class JedisConnection implements RedisConnection { } } - + public Double zIncrBy(byte[] key, double increment, byte[] value) { try { if (isQueueing()) { @@ -1688,7 +1727,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { ZParams zparams = new ZParams().weights(weights).aggregate( @@ -1708,7 +1747,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zInterStore(byte[] destKey, byte[]... sets) { try { if (isQueueing()) { @@ -1725,7 +1764,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1742,7 +1781,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRangeWithScores(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1759,7 +1798,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRangeByScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1776,7 +1815,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRangeByScoreWithScores(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1793,7 +1832,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRevRangeWithScores(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1810,7 +1849,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { @@ -1827,7 +1866,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { @@ -1844,7 +1883,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { @@ -1859,7 +1898,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRevRangeByScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1874,7 +1913,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { try { if (isQueueing()) { @@ -1890,7 +1929,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1905,7 +1944,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zRank(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1922,7 +1961,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean zRem(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -1939,7 +1978,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zRemRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1956,7 +1995,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zRemRangeByScore(byte[] key, double min, double max) { try { if (isQueueing()) { @@ -1973,7 +2012,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set zRevRange(byte[] key, long start, long end) { try { if (isQueueing()) { @@ -1990,7 +2029,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zRevRank(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -2007,7 +2046,7 @@ public class JedisConnection implements RedisConnection { } } - + public Double zScore(byte[] key, byte[] value) { try { if (isQueueing()) { @@ -2024,7 +2063,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { try { ZParams zparams = new ZParams().weights(weights).aggregate( @@ -2044,7 +2083,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long zUnionStore(byte[] destKey, byte[]... sets) { try { if (isQueueing()) { @@ -2065,7 +2104,7 @@ public class JedisConnection implements RedisConnection { // Hash commands // - + public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { if (isQueueing()) { @@ -2082,7 +2121,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { try { if (isQueueing()) { @@ -2099,7 +2138,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean hDel(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -2116,7 +2155,7 @@ public class JedisConnection implements RedisConnection { } } - + public Boolean hExists(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -2133,7 +2172,7 @@ public class JedisConnection implements RedisConnection { } } - + public byte[] hGet(byte[] key, byte[] field) { try { if (isQueueing()) { @@ -2150,7 +2189,7 @@ public class JedisConnection implements RedisConnection { } } - + public Map hGetAll(byte[] key) { try { if (isQueueing()) { @@ -2167,7 +2206,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long hIncrBy(byte[] key, byte[] field, long delta) { try { if (isQueueing()) { @@ -2184,7 +2223,7 @@ public class JedisConnection implements RedisConnection { } } - + public Set hKeys(byte[] key) { try { if (isQueueing()) { @@ -2201,7 +2240,7 @@ public class JedisConnection implements RedisConnection { } } - + public Long hLen(byte[] key) { try { if (isQueueing()) { @@ -2218,7 +2257,7 @@ public class JedisConnection implements RedisConnection { } } - + public List hMGet(byte[] key, byte[]... fields) { try { if (isQueueing()) { @@ -2235,7 +2274,7 @@ public class JedisConnection implements RedisConnection { } } - + public void hMSet(byte[] key, Map tuple) { try { if (isQueueing()) { @@ -2252,7 +2291,7 @@ public class JedisConnection implements RedisConnection { } } - + public List hVals(byte[] key) { try { if (isQueueing()) { @@ -2273,7 +2312,7 @@ public class JedisConnection implements RedisConnection { // // Pub/Sub functionality // - + public Long publish(byte[] channel, byte[] message) { try { if (isQueueing()) { @@ -2289,17 +2328,17 @@ public class JedisConnection implements RedisConnection { } } - + public Subscription getSubscription() { return subscription; } - + public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } - + public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( @@ -2324,7 +2363,7 @@ public class JedisConnection implements RedisConnection { } } - + public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index 4b4d3276f..6dc0354a9 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -16,7 +16,12 @@ package org.springframework.data.redis.connection; -import static org.junit.Assert.*; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.List; @@ -34,12 +39,6 @@ import org.springframework.dao.DataAccessException; import org.springframework.data.redis.Address; import org.springframework.data.redis.ConnectionFactoryTracker; import org.springframework.data.redis.Person; -import org.springframework.data.redis.connection.DefaultStringRedisConnection; -import org.springframework.data.redis.connection.Message; -import org.springframework.data.redis.connection.MessageListener; -import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.StringRedisConnection; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer; @@ -333,4 +332,9 @@ public abstract class AbstractConnectionIntegrationTests { th.start(); connection.pSubscribe(listener, expectedPattern); } + + @Test + public void testExecuteNative() throws Exception { + connection.execute("ZADD", getClass() + "#testExecuteNative", "0.9090", "item"); + } } \ No newline at end of file From 42c0ed804fefb5a9f7c078085feaddda1652d5de Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 21 Jun 2012 17:33:31 +0300 Subject: [PATCH 19/22] add jredis implementation for execute native --- .../connection/jredis/JredisConnection.java | 290 ++++++++++-------- .../AbstractConnectionIntegrationTests.java | 3 + 2 files changed, 160 insertions(+), 133 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java index 2ea1d5556..e82608e4a 100644 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java @@ -15,6 +15,8 @@ */ package org.springframework.data.redis.connection.jredis; +import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -28,7 +30,9 @@ import org.jredis.JRedis; import org.jredis.Query.Support; import org.jredis.RedisException; import org.jredis.Sort; +import org.jredis.protocol.Command; import org.jredis.ri.alphazero.JRedisService; +import org.jredis.ri.alphazero.JRedisSupport; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.RedisSystemException; import org.springframework.data.redis.connection.DataType; @@ -37,6 +41,7 @@ import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; import org.springframework.util.Assert; +import org.springframework.util.ReflectionUtils; /** * {@code RedisConnection} implementation on top of JRedis library. @@ -45,10 +50,18 @@ import org.springframework.util.Assert; */ public class JredisConnection implements RedisConnection { + private static final Method SERVICE_REQUEST; + private final JRedis jredis; private final boolean isPool; private boolean isClosed = false; + static { + SERVICE_REQUEST = ReflectionUtils.findMethod(JRedisSupport.class, "serviceRequest", Command.class, + byte[][].class); + ReflectionUtils.makeAccessible(SERVICE_REQUEST); + } + /** * Constructs a new JredisConnection instance. * @@ -73,7 +86,18 @@ public class JredisConnection implements RedisConnection { return new RedisSystemException("Unknown JRedis exception", ex); } - + public Object execute(String command, byte[]... args) { + Assert.hasText(command, "a valid command needs to be specified"); + List mArgs = new ArrayList(); + if (args != null) { + Collections.addAll(mArgs, args); + } + + return ReflectionUtils.invokeMethod(SERVICE_REQUEST, jredis, Command.valueOf(command.trim().toUpperCase()), + mArgs.toArray(new byte[mArgs.size()][])); + + } + public void close() throws RedisSystemException { isClosed = true; @@ -88,37 +112,37 @@ public class JredisConnection implements RedisConnection { } } - + public JRedis getNativeConnection() { return jredis; } - + public boolean isClosed() { return isClosed; } - + public boolean isQueueing() { return false; } - + public boolean isPipelined() { return false; } - + public void openPipeline() { throw new UnsupportedOperationException("Pipelining not supported by JRedis"); } - + public List closePipeline() { return Collections.emptyList(); } - + public List sort(byte[] key, SortParameters params) { Sort sort = jredis.sort(JredisUtils.decode(key)); JredisUtils.applySortingParams(sort, params, null); @@ -129,7 +153,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long sort(byte[] key, SortParameters params, byte[] storeKey) { Sort sort = jredis.sort(JredisUtils.decode(key)); JredisUtils.applySortingParams(sort, params, null); @@ -140,7 +164,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long dbSize() { try { return jredis.dbsize(); @@ -149,7 +173,7 @@ public class JredisConnection implements RedisConnection { } } - + public void flushDb() { try { jredis.flushdb(); @@ -158,7 +182,7 @@ public class JredisConnection implements RedisConnection { } } - + public void flushAll() { try { jredis.flushall(); @@ -167,7 +191,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] echo(byte[] message) { try { return jredis.echo(message); @@ -176,7 +200,7 @@ public class JredisConnection implements RedisConnection { } } - + public String ping() { try { jredis.ping(); @@ -186,7 +210,7 @@ public class JredisConnection implements RedisConnection { } } - + public void bgSave() { try { jredis.bgsave(); @@ -195,7 +219,7 @@ public class JredisConnection implements RedisConnection { } } - + public void bgWriteAof() { try { jredis.bgrewriteaof(); @@ -204,7 +228,7 @@ public class JredisConnection implements RedisConnection { } } - + public void save() { try { jredis.save(); @@ -213,12 +237,12 @@ public class JredisConnection implements RedisConnection { } } - + public List getConfig(String pattern) { throw new UnsupportedOperationException(); } - + public Properties info() { try { return JredisUtils.info(jredis.info()); @@ -227,7 +251,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long lastSave() { try { return jredis.lastsave(); @@ -236,22 +260,22 @@ public class JredisConnection implements RedisConnection { } } - + public void setConfig(String param, String value) { throw new UnsupportedOperationException(); } - + public void resetConfigStats() { throw new UnsupportedOperationException(); } - + public void shutdown() { throw new UnsupportedOperationException(); } - + public Long del(byte[]... keys) { try { return jredis.del(JredisUtils.decodeMultiple(keys)); @@ -260,7 +284,7 @@ public class JredisConnection implements RedisConnection { } } - + public void discard() { try { jredis.discard(); @@ -269,12 +293,12 @@ public class JredisConnection implements RedisConnection { } } - + public List exec() { throw new UnsupportedOperationException(); } - + public Boolean exists(byte[] key) { try { return jredis.exists(JredisUtils.decode(key)); @@ -283,7 +307,7 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean expire(byte[] key, long seconds) { try { return jredis.expire(JredisUtils.decode(key), (int) seconds); @@ -292,7 +316,7 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean expireAt(byte[] key, long unixTime) { try { return jredis.expireat(JredisUtils.decode(key), unixTime); @@ -301,7 +325,7 @@ public class JredisConnection implements RedisConnection { } } - + public Set keys(byte[] pattern) { try { return JredisUtils.convertToSet(jredis.keys(JredisUtils.decode(pattern))); @@ -310,18 +334,18 @@ public class JredisConnection implements RedisConnection { } } - + public void multi() { throw new UnsupportedOperationException(); } - + public Boolean persist(byte[] key) { throw new UnsupportedOperationException(); } - + public Boolean move(byte[] key, int dbIndex) { try { return jredis.move(JredisUtils.decode(key), dbIndex); @@ -330,7 +354,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] randomKey() { try { return JredisUtils.encode(jredis.randomkey()); @@ -339,7 +363,7 @@ public class JredisConnection implements RedisConnection { } } - + public void rename(byte[] oldName, byte[] newName) { try { jredis.rename(JredisUtils.decode(oldName), JredisUtils.decode(newName)); @@ -348,7 +372,7 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean renameNX(byte[] oldName, byte[] newName) { try { return jredis.renamenx(JredisUtils.decode(oldName), JredisUtils.decode(newName)); @@ -357,12 +381,12 @@ public class JredisConnection implements RedisConnection { } } - + public void select(int dbIndex) { throw new UnsupportedOperationException(); } - + public Long ttl(byte[] key) { try { return jredis.ttl(JredisUtils.decode(key)); @@ -371,7 +395,7 @@ public class JredisConnection implements RedisConnection { } } - + public DataType type(byte[] key) { try { return JredisUtils.convertDataType(jredis.type(JredisUtils.decode(key))); @@ -380,12 +404,12 @@ public class JredisConnection implements RedisConnection { } } - + public void unwatch() { throw new UnsupportedOperationException(); } - + public void watch(byte[]... keys) { throw new UnsupportedOperationException(); } @@ -394,7 +418,7 @@ public class JredisConnection implements RedisConnection { // String operations // - + public byte[] get(byte[] key) { try { return jredis.get(JredisUtils.decode(key)); @@ -403,7 +427,7 @@ public class JredisConnection implements RedisConnection { } } - + public void set(byte[] key, byte[] value) { try { jredis.set(JredisUtils.decode(key), value); @@ -412,7 +436,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] getSet(byte[] key, byte[] value) { try { return jredis.getset(JredisUtils.decode(key), value); @@ -421,7 +445,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long append(byte[] key, byte[] value) { try { return jredis.append(JredisUtils.decode(key), value); @@ -430,7 +454,7 @@ public class JredisConnection implements RedisConnection { } } - + public List mGet(byte[]... keys) { try { return jredis.mget(JredisUtils.decodeMultiple(keys)); @@ -439,7 +463,7 @@ public class JredisConnection implements RedisConnection { } } - + public void mSet(Map tuple) { try { jredis.mset(JredisUtils.decodeMap(tuple)); @@ -448,7 +472,7 @@ public class JredisConnection implements RedisConnection { } } - + public void mSetNX(Map tuple) { try { jredis.msetnx(JredisUtils.decodeMap(tuple)); @@ -457,12 +481,12 @@ public class JredisConnection implements RedisConnection { } } - + public void setEx(byte[] key, long seconds, byte[] value) { throw new UnsupportedOperationException(); } - + public Boolean setNX(byte[] key, byte[] value) { try { return jredis.setnx(JredisUtils.decode(key), value); @@ -471,7 +495,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] getRange(byte[] key, long start, long end) { try { return jredis.substr(JredisUtils.decode(key), start, end); @@ -480,7 +504,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long decr(byte[] key) { try { return jredis.decr(JredisUtils.decode(key)); @@ -489,7 +513,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long decrBy(byte[] key, long value) { try { return jredis.decrby(JredisUtils.decode(key), (int) value); @@ -498,7 +522,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long incr(byte[] key) { try { return jredis.incr(JredisUtils.decode(key)); @@ -507,7 +531,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long incrBy(byte[] key, long value) { try { return jredis.incrby(JredisUtils.decode(key), (int) value); @@ -516,22 +540,22 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean getBit(byte[] key, long offset) { throw new UnsupportedOperationException(); } - + public void setBit(byte[] key, long offset, boolean value) { throw new UnsupportedOperationException(); } - + public void setRange(byte[] key, byte[] value, long start) { throw new UnsupportedOperationException(); } - + public Long strLen(byte[] key) { throw new UnsupportedOperationException(); } @@ -540,17 +564,17 @@ public class JredisConnection implements RedisConnection { // List commands // - + public List bLPop(int timeout, byte[]... keys) { throw new UnsupportedOperationException(); } - + public List bRPop(int timeout, byte[]... keys) { throw new UnsupportedOperationException(); } - + public byte[] lIndex(byte[] key, long index) { try { return jredis.lindex(JredisUtils.decode(key), index); @@ -559,7 +583,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long lLen(byte[] key) { try { return jredis.llen(JredisUtils.decode(key)); @@ -568,7 +592,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] lPop(byte[] key) { try { return jredis.lpop(JredisUtils.decode(key)); @@ -577,7 +601,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long lPush(byte[] key, byte[] value) { try { jredis.lpush(JredisUtils.decode(key), value); @@ -587,7 +611,7 @@ public class JredisConnection implements RedisConnection { } } - + public List lRange(byte[] key, long start, long end) { try { List lrange = jredis.lrange(JredisUtils.decode(key), start, end); @@ -598,7 +622,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long lRem(byte[] key, long count, byte[] value) { try { return jredis.lrem(JredisUtils.decode(key), value, (int) count); @@ -607,7 +631,7 @@ public class JredisConnection implements RedisConnection { } } - + public void lSet(byte[] key, long index, byte[] value) { try { jredis.lset(JredisUtils.decode(key), index, value); @@ -616,7 +640,7 @@ public class JredisConnection implements RedisConnection { } } - + public void lTrim(byte[] key, long start, long end) { try { jredis.ltrim(JredisUtils.decode(key), start, end); @@ -625,7 +649,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] rPop(byte[] key) { try { return jredis.rpop(JredisUtils.decode(key)); @@ -634,7 +658,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { try { return jredis.rpoplpush(JredisUtils.decode(srcKey), JredisUtils.decode(dstKey)); @@ -643,7 +667,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long rPush(byte[] key, byte[] value) { try { jredis.rpush(JredisUtils.decode(key), value); @@ -653,22 +677,22 @@ public class JredisConnection implements RedisConnection { } } - + public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { throw new UnsupportedOperationException(); } - + public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { throw new UnsupportedOperationException(); } - + public Long lPushX(byte[] key, byte[] value) { throw new UnsupportedOperationException(); } - + public Long rPushX(byte[] key, byte[] value) { throw new UnsupportedOperationException(); } @@ -678,7 +702,7 @@ public class JredisConnection implements RedisConnection { // Set commands // - + public Boolean sAdd(byte[] key, byte[] value) { try { return jredis.sadd(JredisUtils.decode(key), value); @@ -687,7 +711,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long sCard(byte[] key) { try { return jredis.scard(JredisUtils.decode(key)); @@ -696,7 +720,7 @@ public class JredisConnection implements RedisConnection { } } - + public Set sDiff(byte[]... keys) { String destKey = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -709,7 +733,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long sDiffStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -722,7 +746,7 @@ public class JredisConnection implements RedisConnection { } } - + public Set sInter(byte[]... keys) { String set1 = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -735,7 +759,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long sInterStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -748,7 +772,7 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean sIsMember(byte[] key, byte[] value) { try { return jredis.sismember(JredisUtils.decode(key), value); @@ -757,7 +781,7 @@ public class JredisConnection implements RedisConnection { } } - + public Set sMembers(byte[] key) { try { return new LinkedHashSet(jredis.smembers(JredisUtils.decode(key))); @@ -766,7 +790,7 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { try { return jredis.smove(JredisUtils.decode(srcKey), JredisUtils.decode(destKey), value); @@ -775,7 +799,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] sPop(byte[] key) { try { return jredis.spop(JredisUtils.decode(key)); @@ -784,7 +808,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] sRandMember(byte[] key) { try { return jredis.srandmember(JredisUtils.decode(key)); @@ -793,7 +817,7 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean sRem(byte[] key, byte[] value) { try { return jredis.srem(JredisUtils.decode(key), value); @@ -802,7 +826,7 @@ public class JredisConnection implements RedisConnection { } } - + public Set sUnion(byte[]... keys) { String set1 = JredisUtils.decode(keys[0]); String[] sets = JredisUtils.decodeMultiple(Arrays.copyOfRange(keys, 1, keys.length)); @@ -814,7 +838,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long sUnionStore(byte[] destKey, byte[]... keys) { String destSet = JredisUtils.decode(destKey); String[] sets = JredisUtils.decodeMultiple(keys); @@ -832,7 +856,7 @@ public class JredisConnection implements RedisConnection { // ZSet commands // - + public Boolean zAdd(byte[] key, double score, byte[] value) { try { return jredis.zadd(JredisUtils.decode(key), score, value); @@ -841,7 +865,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long zCard(byte[] key) { try { return jredis.zcard(JredisUtils.decode(key)); @@ -850,7 +874,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long zCount(byte[] key, double min, double max) { try { return jredis.zcount(JredisUtils.decode(key), min, max); @@ -859,7 +883,7 @@ public class JredisConnection implements RedisConnection { } } - + public Double zIncrBy(byte[] key, double increment, byte[] value) { try { return jredis.zincrby(JredisUtils.decode(key), increment, value); @@ -868,17 +892,17 @@ public class JredisConnection implements RedisConnection { } } - + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } - + public Long zInterStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } - + public Set zRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrange(JredisUtils.decode(key), start, end)); @@ -887,12 +911,12 @@ public class JredisConnection implements RedisConnection { } } - + public Set zRangeWithScores(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } - + public Set zRangeByScore(byte[] key, double min, double max) { try { return new LinkedHashSet(jredis.zrangebyscore(JredisUtils.decode(key), min, max)); @@ -901,42 +925,42 @@ public class JredisConnection implements RedisConnection { } } - + public Set zRangeByScoreWithScores(byte[] key, double min, double max) { throw new UnsupportedOperationException(); } - + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - + public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - + public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - + public Set zRevRangeByScore(byte[] key, double min, double max) { throw new UnsupportedOperationException(); } - + public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { throw new UnsupportedOperationException(); } - + public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { throw new UnsupportedOperationException(); } - + public Long zRank(byte[] key, byte[] value) { try { return jredis.zrank(JredisUtils.decode(key), value); @@ -945,7 +969,7 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean zRem(byte[] key, byte[] value) { try { return jredis.zrem(JredisUtils.decode(key), value); @@ -954,7 +978,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long zRemRange(byte[] key, long start, long end) { try { return jredis.zremrangebyrank(JredisUtils.decode(key), start, end); @@ -963,7 +987,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long zRemRangeByScore(byte[] key, double min, double max) { try { return jredis.zremrangebyscore(JredisUtils.decode(key), min, max); @@ -972,7 +996,7 @@ public class JredisConnection implements RedisConnection { } } - + public Set zRevRange(byte[] key, long start, long end) { try { return new LinkedHashSet(jredis.zrevrange(JredisUtils.decode(key), start, end)); @@ -981,12 +1005,12 @@ public class JredisConnection implements RedisConnection { } } - + public Set zRevRangeWithScores(byte[] key, long start, long end) { throw new UnsupportedOperationException(); } - + public Long zRevRank(byte[] key, byte[] value) { try { return jredis.zrevrank(JredisUtils.decode(key), value); @@ -995,7 +1019,7 @@ public class JredisConnection implements RedisConnection { } } - + public Double zScore(byte[] key, byte[] value) { try { return jredis.zscore(JredisUtils.decode(key), value); @@ -1009,17 +1033,17 @@ public class JredisConnection implements RedisConnection { // Hash commands // - + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { throw new UnsupportedOperationException(); } - + public Long zUnionStore(byte[] destKey, byte[]... sets) { throw new UnsupportedOperationException(); } - + public Boolean hDel(byte[] key, byte[] field) { try { return jredis.hdel(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -1028,7 +1052,7 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean hExists(byte[] key, byte[] field) { try { return jredis.hexists(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -1037,7 +1061,7 @@ public class JredisConnection implements RedisConnection { } } - + public byte[] hGet(byte[] key, byte[] field) { try { return jredis.hget(JredisUtils.decode(key), JredisUtils.decode(field)); @@ -1046,7 +1070,7 @@ public class JredisConnection implements RedisConnection { } } - + public Map hGetAll(byte[] key) { try { return JredisUtils.encodeMap(jredis.hgetall(JredisUtils.decode(key))); @@ -1055,12 +1079,12 @@ public class JredisConnection implements RedisConnection { } } - + public Long hIncrBy(byte[] key, byte[] field, long delta) { throw new UnsupportedOperationException(); } - + public Set hKeys(byte[] key) { try { return new LinkedHashSet(JredisUtils.convertToSet(jredis.hkeys(JredisUtils.decode(key)))); @@ -1069,7 +1093,7 @@ public class JredisConnection implements RedisConnection { } } - + public Long hLen(byte[] key) { try { return jredis.hlen(JredisUtils.decode(key)); @@ -1078,17 +1102,17 @@ public class JredisConnection implements RedisConnection { } } - + public List hMGet(byte[] key, byte[]... fields) { throw new UnsupportedOperationException(); } - + public void hMSet(byte[] key, Map values) { throw new UnsupportedOperationException(); } - + public Boolean hSet(byte[] key, byte[] field, byte[] value) { try { return jredis.hset(JredisUtils.decode(key), JredisUtils.decode(field), value); @@ -1097,12 +1121,12 @@ public class JredisConnection implements RedisConnection { } } - + public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { throw new UnsupportedOperationException(); } - + public List hVals(byte[] key) { try { return jredis.hvals(JredisUtils.decode(key)); @@ -1115,27 +1139,27 @@ public class JredisConnection implements RedisConnection { // PubSub commands // - + public Subscription getSubscription() { return null; } - + public boolean isSubscribed() { return false; } - + public void pSubscribe(MessageListener listener, byte[]... patterns) { throw new UnsupportedOperationException(); } - + public Long publish(byte[] channel, byte[] message) { throw new UnsupportedOperationException(); } - + public void subscribe(MessageListener listener, byte[]... channels) { throw new UnsupportedOperationException(); } diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index 6dc0354a9..94badf377 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -336,5 +336,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test public void testExecuteNative() throws Exception { connection.execute("ZADD", getClass() + "#testExecuteNative", "0.9090", "item"); + //connection.execute("PiNg"); + connection.execute("iNFo"); + connection.execute("SET ", getClass() + "testSetNative", UUID.randomUUID().toString()); } } \ No newline at end of file From 05c4d6c7935ed4d5699e11ca96ffd6687894e979 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 21 Jun 2012 17:33:54 +0300 Subject: [PATCH 20/22] add disambiguating method on StringRedisConnection --- .../data/redis/connection/DefaultStringRedisConnection.java | 4 ++++ .../data/redis/connection/StringRedisConnection.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 9714e51c2..42d2bf091 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -1154,6 +1154,10 @@ public class DefaultStringRedisConnection implements StringRedisConnection { } + public Object execute(String command) { + return execute(command, (byte[][]) null); + } + public Object execute(String command, byte[]... args) { return delegate.execute(command, args); } diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java index 4d92b09f7..39794900d 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -44,6 +44,8 @@ public interface StringRedisConnection extends RedisConnection { Object execute(String command, String... args); + Object execute(String command); + Boolean exists(String key); Long del(String... keys); From 68ef9bcb93e72dc53230bffb95664dff4504a2d7 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 21 Jun 2012 17:34:35 +0300 Subject: [PATCH 21/22] improve array check --- .../data/redis/connection/jedis/JedisConnection.java | 6 ++---- .../data/redis/connection/jredis/JredisConnection.java | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java index 2ad170877..746f6178d 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -34,6 +34,7 @@ import org.springframework.data.redis.connection.RedisSubscribedConnectionExcept import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; import redis.clients.jedis.BinaryJedis; @@ -135,10 +136,7 @@ public class JedisConnection implements RedisConnection { public Object execute(String command, byte[]... args) { Assert.hasText(command, "a valid command needs to be specified"); List mArgs = new ArrayList(); - if (args == null) { - mArgs.add(new byte[0]); - } - else { + if (!ObjectUtils.isEmpty(args)) { Collections.addAll(mArgs, args); } diff --git a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java index e82608e4a..f0cdc25d1 100644 --- a/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jredis/JredisConnection.java @@ -41,6 +41,7 @@ import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; /** @@ -89,7 +90,7 @@ public class JredisConnection implements RedisConnection { public Object execute(String command, byte[]... args) { Assert.hasText(command, "a valid command needs to be specified"); List mArgs = new ArrayList(); - if (args != null) { + if (!ObjectUtils.isEmpty(args)) { Collections.addAll(mArgs, args); } From 2fc50d466d1eed951e52bea3130ccd90aa07478e Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 21 Jun 2012 18:35:13 +0300 Subject: [PATCH 22/22] add execute native for RjcConnection --- .../redis/connection/rjc/RjcConnection.java | 276 +++++++++--------- 1 file changed, 143 insertions(+), 133 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/rjc/RjcConnection.java b/src/main/java/org/springframework/data/redis/connection/rjc/RjcConnection.java index 67a3b5801..621dc9591 100644 --- a/src/main/java/org/springframework/data/redis/connection/rjc/RjcConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/rjc/RjcConnection.java @@ -28,6 +28,7 @@ import org.idevlab.rjc.SessionFactoryImpl; import org.idevlab.rjc.SortingParams; import org.idevlab.rjc.ZParams; import org.idevlab.rjc.message.RedisNodeSubscriber; +import org.idevlab.rjc.protocol.Protocol.Command; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.RedisSystemException; import org.springframework.data.redis.connection.DataType; @@ -36,6 +37,8 @@ import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisSubscribedConnectionException; import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; /** * {@code RedisConnection} implementation on top of rjc library. @@ -49,6 +52,7 @@ public class RjcConnection implements RedisConnection { private final Client client; private final Session session; + private final org.idevlab.rjc.ds.RedisConnection connection; private volatile Client pipeline; private volatile RjcSubscription subscription; @@ -60,6 +64,7 @@ public class RjcConnection implements RedisConnection { subscriber = new RedisNodeSubscriber(); subscriber.setDataSource(new SingleDataSource(new CloseSuppressingRjcConnection(connection))); client = new Client(connection); + this.connection = connection; this.dbIndex = dbIndex; @@ -76,7 +81,13 @@ public class RjcConnection implements RedisConnection { return new RedisSystemException("Unknown rjc exception", ex); } - + public Object execute(String command, byte[]... args) { + Assert.hasText(command, "a valid command needs to be specified"); + connection.sendCommand(Command.valueOf(command.trim().toUpperCase()), + (ObjectUtils.isEmpty(args) ? new byte[0][] : args)); + return connection.getAll(); + } + public void close() throws DataAccessException { isClosed = true; @@ -94,27 +105,27 @@ public class RjcConnection implements RedisConnection { } - + public boolean isClosed() { return isClosed; } - + public Session getNativeConnection() { return session; } - + public boolean isQueueing() { return client.isInMulti(); } - + public boolean isPipelined() { return (pipeline != null); } - + public void openPipeline() { if (pipeline == null) { pipeline = client; @@ -122,7 +133,6 @@ public class RjcConnection implements RedisConnection { } @SuppressWarnings("unchecked") - public List closePipeline() { if (pipeline != null) { List execute = client.getAll(); @@ -133,7 +143,7 @@ public class RjcConnection implements RedisConnection { return Collections.emptyList(); } - + public List sort(byte[] key, SortParameters params) { SortingParams sortParams = RjcUtils.convertSortParams(params); @@ -157,7 +167,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long sort(byte[] key, SortParameters params, byte[] sortKey) { SortingParams sortParams = RjcUtils.convertSortParams(params); @@ -182,7 +192,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long dbSize() { try { if (isPipelined()) { @@ -196,7 +206,7 @@ public class RjcConnection implements RedisConnection { } - + public void flushDb() { try { if (isPipelined()) { @@ -209,7 +219,7 @@ public class RjcConnection implements RedisConnection { } } - + public void flushAll() { try { if (isPipelined()) { @@ -222,7 +232,7 @@ public class RjcConnection implements RedisConnection { } } - + public void bgSave() { try { if (isPipelined()) { @@ -235,7 +245,7 @@ public class RjcConnection implements RedisConnection { } } - + public void bgWriteAof() { try { if (isPipelined()) { @@ -248,7 +258,7 @@ public class RjcConnection implements RedisConnection { } } - + public void save() { try { if (isPipelined()) { @@ -261,7 +271,7 @@ public class RjcConnection implements RedisConnection { } } - + public List getConfig(String param) { try { if (isPipelined()) { @@ -274,7 +284,7 @@ public class RjcConnection implements RedisConnection { } } - + public Properties info() { try { if (isPipelined()) { @@ -287,7 +297,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long lastSave() { try { if (isPipelined()) { @@ -300,7 +310,7 @@ public class RjcConnection implements RedisConnection { } } - + public void setConfig(String param, String value) { try { if (isPipelined()) { @@ -314,7 +324,7 @@ public class RjcConnection implements RedisConnection { } - + public void resetConfigStats() { try { if (isPipelined()) { @@ -328,7 +338,7 @@ public class RjcConnection implements RedisConnection { } } - + public void shutdown() { try { if (isPipelined()) { @@ -341,7 +351,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] echo(byte[] message) { String stringMsg = RjcUtils.decode(message); try { @@ -355,7 +365,7 @@ public class RjcConnection implements RedisConnection { } } - + public String ping() { try { if (isPipelined()) { @@ -367,7 +377,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long del(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -382,7 +392,7 @@ public class RjcConnection implements RedisConnection { } } - + public void discard() { try { if (isPipelined()) { @@ -396,7 +406,7 @@ public class RjcConnection implements RedisConnection { } } - + public List exec() { try { if (isPipelined()) { @@ -409,7 +419,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean exists(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -424,7 +434,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean expire(byte[] key, long seconds) { String stringKey = RjcUtils.decode(key); @@ -439,7 +449,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean expireAt(byte[] key, long unixTime) { String stringKey = RjcUtils.decode(key); @@ -454,7 +464,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set keys(byte[] pattern) { String stringKey = RjcUtils.decode(pattern); @@ -469,7 +479,7 @@ public class RjcConnection implements RedisConnection { } } - + public void multi() { if (isQueueing()) { return; @@ -485,7 +495,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean persist(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -500,7 +510,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean move(byte[] key, int dbIndex) { String stringKey = RjcUtils.decode(key); @@ -515,7 +525,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] randomKey() { try { if (isPipelined()) { @@ -528,7 +538,7 @@ public class RjcConnection implements RedisConnection { } } - + public void rename(byte[] oldName, byte[] newName) { String stringOldKey = RjcUtils.decode(oldName); String stringNewKey = RjcUtils.decode(newName); @@ -544,7 +554,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean renameNX(byte[] oldName, byte[] newName) { String stringOldKey = RjcUtils.decode(oldName); String stringNewKey = RjcUtils.decode(newName); @@ -560,7 +570,7 @@ public class RjcConnection implements RedisConnection { } } - + public void select(int dbIndex) { try { if (isPipelined()) { @@ -573,7 +583,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long ttl(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -588,7 +598,7 @@ public class RjcConnection implements RedisConnection { } } - + public DataType type(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -603,7 +613,7 @@ public class RjcConnection implements RedisConnection { } } - + public void unwatch() { try { if (isPipelined()) { @@ -617,7 +627,7 @@ public class RjcConnection implements RedisConnection { } } - + public void watch(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -641,7 +651,7 @@ public class RjcConnection implements RedisConnection { // String commands // - + public byte[] get(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -657,7 +667,7 @@ public class RjcConnection implements RedisConnection { } } - + public void set(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -674,7 +684,7 @@ public class RjcConnection implements RedisConnection { } - + public byte[] getSet(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -690,7 +700,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long append(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -706,7 +716,7 @@ public class RjcConnection implements RedisConnection { } } - + public List mGet(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -721,7 +731,7 @@ public class RjcConnection implements RedisConnection { } } - + public void mSet(Map tuples) { String[] decodeMap = RjcUtils.flatten(tuples); @@ -736,7 +746,7 @@ public class RjcConnection implements RedisConnection { } } - + public void mSetNX(Map tuples) { String[] decodeMap = RjcUtils.flatten(tuples); @@ -752,7 +762,7 @@ public class RjcConnection implements RedisConnection { } } - + public void setEx(byte[] key, long time, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -768,7 +778,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean setNX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -784,7 +794,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] getRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -799,7 +809,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long decr(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -814,7 +824,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long decrBy(byte[] key, long value) { String stringKey = RjcUtils.decode(key); try { @@ -829,7 +839,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long incr(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -845,7 +855,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long incrBy(byte[] key, long value) { String stringKey = RjcUtils.decode(key); @@ -861,7 +871,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean getBit(byte[] key, long offset) { String stringKey = RjcUtils.decode(key); @@ -876,7 +886,7 @@ public class RjcConnection implements RedisConnection { } } - + public void setBit(byte[] key, long offset, boolean value) { String stringKey = RjcUtils.decode(key); @@ -891,7 +901,7 @@ public class RjcConnection implements RedisConnection { } } - + public void setRange(byte[] key, byte[] value, long offset) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -907,7 +917,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long strLen(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -926,7 +936,7 @@ public class RjcConnection implements RedisConnection { // List commands // - + public Long lPush(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -942,7 +952,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long rPush(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -959,7 +969,7 @@ public class RjcConnection implements RedisConnection { } } - + public List bLPop(int timeout, byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -974,7 +984,7 @@ public class RjcConnection implements RedisConnection { } } - + public List bRPop(int timeout, byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -989,7 +999,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] lIndex(byte[] key, long index) { String stringKey = RjcUtils.decode(key); @@ -1005,7 +1015,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1023,7 +1033,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long lLen(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1039,7 +1049,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] lPop(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1055,7 +1065,7 @@ public class RjcConnection implements RedisConnection { } } - + public List lRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -1071,7 +1081,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long lRem(byte[] key, long count, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1088,7 +1098,7 @@ public class RjcConnection implements RedisConnection { } } - + public void lSet(byte[] key, long index, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1104,7 +1114,7 @@ public class RjcConnection implements RedisConnection { } } - + public void lTrim(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); @@ -1120,7 +1130,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] rPop(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1136,7 +1146,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { String stringKey = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(dstKey); @@ -1153,7 +1163,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { String stringKey = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(dstKey); @@ -1169,7 +1179,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long lPushX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1184,7 +1194,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long rPushX(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1204,7 +1214,7 @@ public class RjcConnection implements RedisConnection { // Set commands // - + public Boolean sAdd(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1221,7 +1231,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long sCard(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1237,7 +1247,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set sDiff(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1253,7 +1263,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long sDiffStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1270,7 +1280,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set sInter(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); try { @@ -1285,7 +1295,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long sInterStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1301,7 +1311,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean sIsMember(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1318,7 +1328,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set sMembers(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1333,7 +1343,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { String stringSrc = RjcUtils.decode(srcKey); String stringDest = RjcUtils.decode(destKey); @@ -1351,7 +1361,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] sPop(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1366,7 +1376,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] sRandMember(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1381,7 +1391,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean sRem(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1398,7 +1408,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set sUnion(byte[]... keys) { String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1414,7 +1424,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long sUnionStore(byte[] destKey, byte[]... keys) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(keys); @@ -1435,7 +1445,7 @@ public class RjcConnection implements RedisConnection { // ZSet commands // - + public Boolean zAdd(byte[] key, double score, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1451,7 +1461,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zCard(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1466,7 +1476,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zCount(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); try { @@ -1481,7 +1491,7 @@ public class RjcConnection implements RedisConnection { } } - + public Double zIncrBy(byte[] key, double increment, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1497,7 +1507,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1515,7 +1525,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zInterStore(byte[] destKey, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1531,7 +1541,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1546,7 +1556,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRangeWithScores(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1561,7 +1571,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRangeByScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1578,7 +1588,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1597,7 +1607,7 @@ public class RjcConnection implements RedisConnection { } - + public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1615,7 +1625,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRevRangeByScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1632,7 +1642,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRangeByScoreWithScores(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1649,7 +1659,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRevRangeWithScores(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); String minString = Long.toString(start); @@ -1667,7 +1677,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1686,7 +1696,7 @@ public class RjcConnection implements RedisConnection { } - + public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1705,7 +1715,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1723,7 +1733,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zRank(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1739,7 +1749,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean zRem(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1755,7 +1765,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zRemRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1769,7 +1779,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zRemRangeByScore(byte[] key, double min, double max) { String stringKey = RjcUtils.decode(key); String minString = Double.toString(min); @@ -1786,7 +1796,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set zRevRange(byte[] key, long start, long end) { String stringKey = RjcUtils.decode(key); try { @@ -1801,7 +1811,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zRevRank(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1817,7 +1827,7 @@ public class RjcConnection implements RedisConnection { } } - + public Double zScore(byte[] key, byte[] value) { String stringKey = RjcUtils.decode(key); String stringValue = RjcUtils.decode(value); @@ -1833,7 +1843,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(destKey); @@ -1851,7 +1861,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long zUnionStore(byte[] destKey, byte[]... sets) { String stringKey = RjcUtils.decode(destKey); String[] stringKeys = RjcUtils.decodeMultiple(sets); @@ -1871,7 +1881,7 @@ public class RjcConnection implements RedisConnection { // Hash commands // - + public Boolean hSet(byte[] key, byte[] field, byte[] value) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1888,7 +1898,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1905,7 +1915,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean hDel(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1921,7 +1931,7 @@ public class RjcConnection implements RedisConnection { } } - + public Boolean hExists(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1937,7 +1947,7 @@ public class RjcConnection implements RedisConnection { } } - + public byte[] hGet(byte[] key, byte[] field) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1953,7 +1963,7 @@ public class RjcConnection implements RedisConnection { } } - + public Map hGetAll(byte[] key) { String stringKey = RjcUtils.decode(key); @@ -1968,7 +1978,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long hIncrBy(byte[] key, byte[] field, long delta) { String stringKey = RjcUtils.decode(key); String stringField = RjcUtils.decode(field); @@ -1984,7 +1994,7 @@ public class RjcConnection implements RedisConnection { } } - + public Set hKeys(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -1998,7 +2008,7 @@ public class RjcConnection implements RedisConnection { } } - + public Long hLen(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -2012,7 +2022,7 @@ public class RjcConnection implements RedisConnection { } } - + public List hMGet(byte[] key, byte[]... fields) { String stringKey = RjcUtils.decode(key); String[] stringKeys = RjcUtils.decodeMultiple(fields); @@ -2028,7 +2038,7 @@ public class RjcConnection implements RedisConnection { } } - + public void hMSet(byte[] key, Map tuple) { String stringKey = RjcUtils.decode(key); Map stringTuple = RjcUtils.decodeMap(tuple); @@ -2044,7 +2054,7 @@ public class RjcConnection implements RedisConnection { } } - + public List hVals(byte[] key) { String stringKey = RjcUtils.decode(key); try { @@ -2063,7 +2073,7 @@ public class RjcConnection implements RedisConnection { // // Pub/Sub functionality // - + public Long publish(byte[] channel, byte[] message) { try { if (isQueueing()) { @@ -2078,17 +2088,17 @@ public class RjcConnection implements RedisConnection { } } - + public Subscription getSubscription() { return subscription; } - + public boolean isSubscribed() { return (subscription != null && subscription.isAlive()); } - + public void pSubscribe(MessageListener listener, byte[]... patterns) { if (isSubscribed()) { throw new RedisSubscribedConnectionException( @@ -2112,7 +2122,7 @@ public class RjcConnection implements RedisConnection { } } - + public void subscribe(MessageListener listener, byte[]... channels) { if (isSubscribed()) { throw new RedisSubscribedConnectionException(