From b492f7ef573a92b090c8688efbb41e76a3682a20 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Fri, 25 Mar 2016 17:39:54 -0700 Subject: [PATCH 01/15] DATAREDIS-444 DefaultHashOperation does not return value --- .../data/redis/core/DefaultHashOperations.java | 9 ++++----- .../springframework/data/redis/core/HashOperations.java | 2 +- .../data/redis/core/DefaultHashOperationsTests.java | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java index dcba9aadc7..94c5e96762 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultHashOperations.java @@ -201,15 +201,14 @@ public List doInRedis(RedisConnection connection) { return deserializeHashValues(rawValues); } - public void delete(K key, Object... hashKeys) { + public Long delete(K key, Object... hashKeys) { final byte[] rawKey = rawKey(key); final byte[][] rawHashKeys = rawHashKeys(hashKeys); - execute(new RedisCallback() { + return execute(new RedisCallback() { - public Object doInRedis(RedisConnection connection) { - connection.hDel(rawKey, rawHashKeys); - return null; + public Long doInRedis(RedisConnection connection) { + return connection.hDel(rawKey, rawHashKeys); } }, true); } diff --git a/src/main/java/org/springframework/data/redis/core/HashOperations.java b/src/main/java/org/springframework/data/redis/core/HashOperations.java index 37ae67966c..8757137562 100644 --- a/src/main/java/org/springframework/data/redis/core/HashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/HashOperations.java @@ -28,7 +28,7 @@ */ public interface HashOperations { - void delete(H key, Object... hashKeys); + Long delete(H key, Object... hashKeys); Boolean hasKey(H key, Object hashKey); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java index b721eb76d7..a2299be3ba 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java @@ -134,8 +134,9 @@ public void testDelete() { HV val2 = hashValueFactory.instance(); hashOps.put(key, key1, val1); hashOps.put(key, key2, val2); - hashOps.delete(key, key1, key2); + Long numDeleted = hashOps.delete(key, key1, key2); assertTrue(hashOps.keys(key).isEmpty()); + assertEquals(2L, numDeleted.longValue()); } /** From cf65de45f349be9a0703684a7c7d21ea4b5e0347 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Sun, 27 Mar 2016 10:08:59 -0700 Subject: [PATCH 02/15] DATAREDIS-444 DefaultHashOperation does not return value --- .../data/redis/core/BoundHashOperations.java | 2 +- .../data/redis/core/DefaultBoundHashOperations.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/BoundHashOperations.java b/src/main/java/org/springframework/data/redis/core/BoundHashOperations.java index ccc23dd12d..d61d816824 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundHashOperations.java @@ -52,7 +52,7 @@ public interface BoundHashOperations extends BoundKeyOperations { Long size(); - void delete(Object... keys); + Long delete(Object... keys); Map entries(); diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java index 647714324d..51ab3eaca3 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundHashOperations.java @@ -38,15 +38,15 @@ class DefaultBoundHashOperations extends DefaultBoundKeyOperations * Constructs a new DefaultBoundHashOperations instance. * * @param key - * @param template + * @param operations */ public DefaultBoundHashOperations(H key, RedisOperations operations) { super(key, operations); this.ops = operations.opsForHash(); } - public void delete(Object... keys) { - ops.delete(getKey(), keys); + public Long delete(Object... keys) { + return ops.delete(getKey(), keys); } public HV get(Object key) { From 73e371b638b7f7fd41c490b332919d5290b93f56 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Sun, 27 Mar 2016 14:58:18 -0700 Subject: [PATCH 03/15] DATAREDIS-438 Add support for geo commands. --- .../DefaultStringRedisConnection.java | 12 +++ .../data/redis/connection/RedisCommands.java | 2 +- .../redis/connection/RedisGeoCommands.java | 38 ++++++++ .../jedis/JedisClusterConnection.java | 9 ++ .../connection/jedis/JedisConnection.java | 22 +++++ .../connection/jredis/JredisConnection.java | 20 +++- .../connection/lettuce/LettuceConnection.java | 20 ++++ .../redis/connection/srp/SrpConnection.java | 7 +- .../data/redis/core/BoundGeoOperations.java | 25 +++++ .../redis/core/DefaultBoundGeoOperations.java | 49 ++++++++++ .../data/redis/core/DefaultGeoOperations.java | 42 +++++++++ .../data/redis/core/GeoOperations.java | 25 +++++ .../data/redis/core/GeoOperationsEditor.java | 34 +++++++ .../data/redis/core/RedisCommand.java | 1 + .../data/redis/core/RedisOperations.java | 15 +++ .../data/redis/core/RedisTemplate.java | 22 ++++- .../connection/RedisConnectionUnitTests.java | 6 +- .../redis/core/DefaultGeoOperationsTests.java | 94 +++++++++++++++++++ 18 files changed, 431 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java create mode 100644 src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java create mode 100644 src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java create mode 100644 src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java create mode 100644 src/main/java/org/springframework/data/redis/core/GeoOperations.java create mode 100644 src/main/java/org/springframework/data/redis/core/GeoOperationsEditor.java create mode 100644 src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java 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 91b6e92f87..18d3dab368 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -280,6 +280,14 @@ public void flushDb() { delegate.flushDb(); } + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member){ + Long result = delegate.geoAdd(key, longitude, latitude, member); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + public byte[] get(byte[] key) { byte[] result = delegate.get(key); if (isFutureConversion()) { @@ -1507,6 +1515,10 @@ public Boolean expireAt(String key, long unixTime) { return result; } + public Long geoAdd(String key, double longitude, double latitude, String member){ + return delegate.geoAdd(serialize(key), longitude, latitude, serialize(member)); + } + public String get(String key) { byte[] result = delegate.get(serialize(key)); if (isFutureConversion()) { 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 1da8cda6f3..47a9579fe8 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisCommands.java @@ -24,7 +24,7 @@ */ public interface RedisCommands extends RedisKeyCommands, RedisStringCommands, RedisListCommands, RedisSetCommands, RedisZSetCommands, RedisHashCommands, RedisTxCommands, RedisPubSubCommands, RedisConnectionCommands, - RedisServerCommands, RedisScriptingCommands, HyperLogLogCommands { + RedisServerCommands, RedisScriptingCommands, RedisGeoCommands, HyperLogLogCommands { /** * 'Native' or 'raw' execution of the given command along-side the given arguments. The command is executed as is, diff --git a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java new file mode 100644 index 0000000000..13d30b56b0 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java @@ -0,0 +1,38 @@ +/* + * Copyright 2011-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.connection; + +/** + * Geo-specific Redis commands. + * + * @author Ninad Divadkar + */ +public interface RedisGeoCommands { + /** + * Add latitude and longitude for a given key with a name. + * Returns the number of elements added to the sorted set, not including elements already existing for which the + * score was updated. + *

+ * @see http://redis.io/commands/geoadd + * + * @param key + * @param member + * @param longitude + * @param latitude + * @return + */ + Long geoAdd(byte[] key, double longitude, double latitude, byte[] member); +} diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java index f7a87624b8..4b29f7f124 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java @@ -2511,6 +2511,15 @@ public void pSubscribe(MessageListener listener, byte[]... patterns) { } } + @Override + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member){ + try { + return cluster.geoadd(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisConnectionCommands#select(int) 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 94ffd486a1..ce4abc8b0f 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 @@ -3078,6 +3078,28 @@ public void subscribe(MessageListener listener, byte[]... channels) { } } + // + // Geo commands + // + + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member){ + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.geoadd(key, longitude, latitude, member))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.geoadd(key, longitude, latitude, member))); + return null; + } + + return jedis.geoadd(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + // // Scripting commands // 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 9f44e22fb9..e739f25dc7 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 @@ -1187,14 +1187,24 @@ public Long publish(byte[] channel, byte[] message) { throw new UnsupportedOperationException(); } - // + public void subscribe(MessageListener listener, byte[]... channels) { + throw new UnsupportedOperationException(); + } + + // + // Geo commands + // + + @Override + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) { + throw new UnsupportedOperationException(); + } + + + // // Scripting commands // - public void subscribe(MessageListener listener, byte[]... channels) { - throw new UnsupportedOperationException(); - } - public void scriptFlush() { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index d7b312ca25..5018fa6abb 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -3079,6 +3079,26 @@ public void subscribe(MessageListener listener, byte[]... channels) { } } + // + // Geo functionality + // + @Override + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) { + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().geoadd(key, longitude, latitude, member))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().geoadd(key, longitude, latitude, member))); + return null; + } + return getConnection().geoadd(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisServerCommands#time() diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java index acbc966ecb..8ff97f3b4e 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java @@ -2241,7 +2241,12 @@ public void subscribe(MessageListener listener, byte[]... channels) { } } - /** + @Override + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) { + throw new UnsupportedOperationException(); + } + + /** * Specifies if pipelined results should be converted to the expected data type. If false, results of * {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Lettuce driver * diff --git a/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java new file mode 100644 index 0000000000..162e70e8ac --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core; + +/** + * Hash operations bound to a certain key. + * + * @author Ninad Divadkar + */ +public interface BoundGeoOperations extends BoundKeyOperations { + Long geoAdd(K key, double longitude, double latitude, M member); +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java new file mode 100644 index 0000000000..3611f82724 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java @@ -0,0 +1,49 @@ +/* + * Copyright 2011-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core; + +import org.springframework.data.redis.connection.DataType; + +import java.util.concurrent.TimeUnit; + +/** + * @author Ninad Divadkar + */ +class DefaultBoundGeoOperations extends DefaultBoundKeyOperations implements BoundGeoOperations { + + private final GeoOperations ops; + + /** + * Constructs a new DefaultBoundGeoOperations instance. + * + * @param key + * @param operations + */ + public DefaultBoundGeoOperations(K key, RedisOperations operations) { + super(key, operations); + this.ops = operations.opsForGeo(); + } + + @Override + public Long geoAdd(K key, double longitude, double latitude, M member) { + return ops.geoAdd(key, longitude, latitude, member); + } + + @Override + public DataType getType() { + return DataType.STRING; + } +} diff --git a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java new file mode 100644 index 0000000000..0790a75af8 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java @@ -0,0 +1,42 @@ +/* + * Copyright 2011-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core; + +import org.springframework.data.redis.connection.RedisConnection; + +/** + * Default implementation of {@link GeoOperations}. + * + * @author Ninad Divadkar + */ +public class DefaultGeoOperations extends AbstractOperations implements GeoOperations { + DefaultGeoOperations(RedisTemplate template) { + super(template); + } + + @Override + public Long geoAdd(K key, final double longitude, final double latitude, M member) { + final byte[] rawKey = rawKey(key); + final byte[] rawMember = rawValue(member); + + return execute(new RedisCallback() { + + public Long doInRedis(RedisConnection connection) { + return connection.geoAdd(rawKey, longitude, latitude, rawMember); + } + }, true); + } +} diff --git a/src/main/java/org/springframework/data/redis/core/GeoOperations.java b/src/main/java/org/springframework/data/redis/core/GeoOperations.java new file mode 100644 index 0000000000..9f99d11463 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/GeoOperations.java @@ -0,0 +1,25 @@ +/* + * Copyright 2011-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core; + +/** + * Redis operations for simple (or in Redis terminology 'string') values. + * + * @author Ninad Divadkar + */ +public interface GeoOperations { + Long geoAdd(K key, double longitude, double latitude, M member); +} diff --git a/src/main/java/org/springframework/data/redis/core/GeoOperationsEditor.java b/src/main/java/org/springframework/data/redis/core/GeoOperationsEditor.java new file mode 100644 index 0000000000..e36a02364f --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/GeoOperationsEditor.java @@ -0,0 +1,34 @@ +/* + * Copyright 2011-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core; + +import java.beans.PropertyEditorSupport; + +/** + * PropertyEditor allowing for easy injection of {@link org.springframework.data.redis.core.GeoOperations} from {@link org.springframework.data.redis.core.RedisOperations}. + * + * @author Ninad Divadkar + */ +class GeoOperationsEditor extends PropertyEditorSupport { + + public void setValue(Object value) { + if (value instanceof RedisOperations) { + super.setValue(((RedisOperations) value).opsForGeo()); + } else { + throw new IllegalArgumentException("Editor supports only conversion of type " + RedisOperations.class); + } + } +} diff --git a/src/main/java/org/springframework/data/redis/core/RedisCommand.java b/src/main/java/org/springframework/data/redis/core/RedisCommand.java index 061b47e56f..8f006c817f 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisCommand.java +++ b/src/main/java/org/springframework/data/redis/core/RedisCommand.java @@ -78,6 +78,7 @@ public enum RedisCommand { GETBIT("r", 2, 2), // GETRANGE("r", 3, 3), // GETSET("rw", 2, 2), // + GEOADD("w", 3, 2), // -- H HDEL("rw", 2), // HEXISTS("r", 2, 2), // diff --git a/src/main/java/org/springframework/data/redis/core/RedisOperations.java b/src/main/java/org/springframework/data/redis/core/RedisOperations.java index 446df60da5..d0e5e69981 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/RedisOperations.java @@ -283,6 +283,21 @@ T execute(RedisScript script, RedisSerializer argsSerializer, RedisSer */ BoundHashOperations boundHashOps(K key); + /** + * Returns the operations performed on geo values. + * + * @return geo operations + */ + GeoOperations opsForGeo(); + + /** + * Returns the operations performed on hash values bound to the given key. + * + * @param key Redis key + * @return hash operations bound to the given key. + */ + BoundGeoOperations boundGeoOps(K key); + /** * Returns the cluster specific operations interface. * 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 7a9dcb9ade..5aafbe1bb7 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -96,6 +96,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation private ListOperations listOps; private SetOperations setOps; private ZSetOperations zSetOps; + private GeoOperations geoOps; private HyperLogLogOperations hllOps; /** @@ -995,10 +996,23 @@ public ZSetOperations opsForZSet() { return zSetOps; } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#opsForHyperLogLog() - */ + @Override + public GeoOperations opsForGeo() { + if (geoOps == null) { + geoOps = new DefaultGeoOperations(this); + } + return geoOps; + } + + @Override + public BoundGeoOperations boundGeoOps(K key) { + return new DefaultBoundGeoOperations(key, this); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#opsForHyperLogLog() + */ @Override public HyperLogLogOperations opsForHyperLogLog() { diff --git a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java index cb2d660c60..0832f3fdf6 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java @@ -260,7 +260,11 @@ public void subscribe(MessageListener listener, byte[]... channels) { delegate.subscribe(listener, channels); } - public Set keys(byte[] pattern) { + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) { + return delegate.geoAdd(key, longitude, latitude, member); + } + + public Set keys(byte[] pattern) { return delegate.keys(pattern); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java new file mode 100644 index 0000000000..3c9bcd7d4a --- /dev/null +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java @@ -0,0 +1,94 @@ +/* + * Copyright 2013-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.core; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.springframework.data.redis.ObjectFactory; +import org.springframework.data.redis.RedisTestProfileValueSource; +import org.springframework.data.redis.TestCondition; +import org.springframework.data.redis.connection.RedisConnection; + +import java.text.DecimalFormat; +import java.util.*; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.*; +import static org.junit.Assume.assumeTrue; +import static org.springframework.data.redis.SpinBarrier.waitFor; +import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual; + +/** + * Integration test of {@link org.springframework.data.redis.core.DefaultValueOperations} + * + * @author Jennifer Hickey + * @author Christoph Strobl + * @author David Liu + * @author Thomas Darimont + */ +@RunWith(Parameterized.class) +public class DefaultGeoOperationsTests { + + private RedisTemplate redisTemplate; + + private ObjectFactory keyFactory; + + private ObjectFactory valueFactory; + + private GeoOperations geoOperations; + + public DefaultGeoOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + ObjectFactory valueFactory) { + this.redisTemplate = redisTemplate; + this.keyFactory = keyFactory; + this.valueFactory = valueFactory; + } + + @Parameters + public static Collection testParams() { + return AbstractOperationsTestParams.testParams(); + } + + @Before + public void setUp() { + geoOperations = redisTemplate.opsForGeo(); + } + + @After + public void tearDown() { + redisTemplate.execute(new RedisCallback() { + public Object doInRedis(RedisConnection connection) { + connection.flushDb(); + return null; + } + }); + } + + @Test + public void testGeoAdd() throws Exception { + K key = keyFactory.instance(); + V v1 = valueFactory.instance(); + Long numAdded = geoOperations.geoAdd(key, 13.361389, 38.115556, v1); + assertEquals(numAdded.longValue(), 1L); + +// numAdded = geoOperations.geoAdd("Sicily", 15.087269, 37.502669, "Catania"); +// assertEquals(numAdded.longValue(), 2L); + } +} From 9991f04d1d7ddc388c14f64a66c9a6052ba6139c Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Sun, 27 Mar 2016 14:58:18 -0700 Subject: [PATCH 04/15] DATAREDIS-438 Add support for geo commands. --- .../data/redis/core/GeoOperations.java | 2 +- .../data/redis/core/RedisOperations.java | 4 ++-- .../redis/core/DefaultGeoOperationsTests.java | 21 ++++++++----------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/core/GeoOperations.java b/src/main/java/org/springframework/data/redis/core/GeoOperations.java index 9f99d11463..a3cfc9bfd9 100644 --- a/src/main/java/org/springframework/data/redis/core/GeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/GeoOperations.java @@ -16,7 +16,7 @@ package org.springframework.data.redis.core; /** - * Redis operations for simple (or in Redis terminology 'string') values. + * Redis operations for geo commands. * * @author Ninad Divadkar */ diff --git a/src/main/java/org/springframework/data/redis/core/RedisOperations.java b/src/main/java/org/springframework/data/redis/core/RedisOperations.java index d0e5e69981..0a827c3478 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/RedisOperations.java @@ -291,10 +291,10 @@ T execute(RedisScript script, RedisSerializer argsSerializer, RedisSer GeoOperations opsForGeo(); /** - * Returns the operations performed on hash values bound to the given key. + * Returns the operations performed on values bound to the given key. * * @param key Redis key - * @return hash operations bound to the given key. + * @return geo operations bound to the given key. */ BoundGeoOperations boundGeoOps(K key); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java index 3c9bcd7d4a..c8cc9d8687 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java @@ -36,26 +36,23 @@ import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual; /** - * Integration test of {@link org.springframework.data.redis.core.DefaultValueOperations} + * Integration test of {@link org.springframework.data.redis.core.DefaultGeoOperations} * - * @author Jennifer Hickey - * @author Christoph Strobl - * @author David Liu - * @author Thomas Darimont + * @author Ninad Divadkar */ @RunWith(Parameterized.class) -public class DefaultGeoOperationsTests { +public class DefaultGeoOperationsTests { - private RedisTemplate redisTemplate; + private RedisTemplate redisTemplate; private ObjectFactory keyFactory; - private ObjectFactory valueFactory; + private ObjectFactory valueFactory; - private GeoOperations geoOperations; + private GeoOperations geoOperations; - public DefaultGeoOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, - ObjectFactory valueFactory) { + public DefaultGeoOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; this.valueFactory = valueFactory; @@ -84,7 +81,7 @@ public Object doInRedis(RedisConnection connection) { @Test public void testGeoAdd() throws Exception { K key = keyFactory.instance(); - V v1 = valueFactory.instance(); + M v1 = valueFactory.instance(); Long numAdded = geoOperations.geoAdd(key, 13.361389, 38.115556, v1); assertEquals(numAdded.longValue(), 1L); From 6badb0828933348820bab04bc22f865a4f651003 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Wed, 30 Mar 2016 12:49:51 -0700 Subject: [PATCH 05/15] DATAREDIS-438 Add support for geo commands. Adding support for geoAdd, geoDist, geoPos and geoHash --- .../redis/connection/RedisGeoCommands.java | 29 + .../jedis/JedisClusterConnection.java | 98 +- .../connection/jedis/JedisConnection.java | 5480 +++++++++-------- .../connection/jedis/JedisConverters.java | 32 + .../connection/jredis/JredisConnection.java | 27 + .../connection/lettuce/LettuceConnection.java | 154 +- .../data/redis/core/GeoCoordinate.java | 22 + .../data/redis/core/GeoRadiusParam.java | 64 + .../data/redis/core/GeoUnit.java | 11 + 9 files changed, 3239 insertions(+), 2678 deletions(-) create mode 100644 src/main/java/org/springframework/data/redis/core/GeoCoordinate.java create mode 100644 src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java create mode 100644 src/main/java/org/springframework/data/redis/core/GeoUnit.java diff --git a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java index 13d30b56b0..5d5e790244 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java @@ -15,6 +15,13 @@ */ package org.springframework.data.redis.connection; + +import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoUnit; + +import java.util.List; +import java.util.Map; + /** * Geo-specific Redis commands. * @@ -35,4 +42,26 @@ public interface RedisGeoCommands { * @return */ Long geoAdd(byte[] key, double longitude, double latitude, byte[] member); + + Long geoadd(byte[] key, Map memberCoordinateMap); + + Double geodist(byte[] key, byte[] member1, byte[] member2); + + Double geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit); + + List geohash(byte[] key, byte[]... members); + + List geopos(byte[] key, byte[]... members); + +// List georadius(byte[] key, double longitude, double latitude, +// double radius, GeoUnit unit); +// +// List georadius(byte[] key, double longitude, double latitude, +// double radius, GeoUnit unit, GeoRadiusParam param); +// +// List georadiusByMember(byte[] key, byte[] member, double radius, +// GeoUnit unit); +// +// List georadiusByMember(byte[] key, byte[] member, double radius, +// GeoUnit unit, GeoRadiusParam param); } diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java index 4b29f7f124..6b31337dfe 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java @@ -70,12 +70,8 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; -import redis.clients.jedis.BinaryJedisPubSub; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisCluster; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.ScanParams; -import redis.clients.jedis.ZParams; +import redis.clients.jedis.*; +import redis.clients.jedis.params.geo.GeoRadiusParam; /** * {@link RedisClusterConnection} implementation on top of {@link JedisCluster}.
@@ -2520,7 +2516,95 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) } } - /* + @Override + public Long geoadd(byte[] key, Map memberCoordinateMap){ + try { + return cluster.geoadd(key, memberCoordinateMap); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + + @Override + public Double geodist(byte[] key, byte[] member1, byte[] member2) { + try { + return cluster.geodist(key, member1, member2); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public Double geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + try { + return cluster.geodist(key, member1, member2, unit); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List geohash(byte[] key, byte[]... members) { + try { + return cluster.geohash(key, members); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List geopos(byte[] key, byte[]... members) { + try { + return cluster.geopos(key, members); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, + double radius, GeoUnit unit) { + try { + return cluster.georadius(key, longitude, latitude, radius, unit); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, + double radius, GeoUnit unit, GeoRadiusParam param) { + try { + return cluster.georadius(key, longitude, latitude, radius, unit, param); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, + GeoUnit unit) { + try { + return cluster.georadiusByMember(key, member, radius, unit); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, + GeoUnit unit, GeoRadiusParam param) { + + try { + return cluster.georadiusByMember(key, member, radius, unit, param); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisConnectionCommands#select(int) */ 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 ce4abc8b0f..d8a499b5e8 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,17 +17,8 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Properties; -import java.util.Queue; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.springframework.core.convert.converter.Converter; @@ -49,11 +40,8 @@ import org.springframework.data.redis.connection.Subscription; import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.connection.convert.TransactionResultConverter; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.KeyBoundCursor; -import org.springframework.data.redis.core.ScanCursor; -import org.springframework.data.redis.core.ScanIteration; -import org.springframework.data.redis.core.ScanOptions; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.core.GeoCoordinate; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; @@ -61,23 +49,11 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; -import redis.clients.jedis.BinaryJedis; -import redis.clients.jedis.BinaryJedisPubSub; -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; +import redis.clients.jedis.*; +import redis.clients.jedis.GeoUnit; import redis.clients.jedis.Protocol.Command; -import redis.clients.jedis.Queable; -import redis.clients.jedis.Response; -import redis.clients.jedis.ScanParams; -import redis.clients.jedis.ScanResult; -import redis.clients.jedis.SortingParams; -import redis.clients.jedis.Transaction; -import redis.clients.jedis.ZParams; import redis.clients.jedis.exceptions.JedisDataException; +import redis.clients.jedis.params.geo.GeoRadiusParam; import redis.clients.util.Pool; /** @@ -95,696 +71,698 @@ */ public class JedisConnection extends AbstractRedisConnection { - private static final Field CLIENT_FIELD; - private static final Method SEND_COMMAND; - private static final Method GET_RESPONSE; + private static final Field CLIENT_FIELD; + private static final Method SEND_COMMAND; + private static final Method GET_RESPONSE; - private static final String SHUTDOWN_SCRIPT = "return redis.call('SHUTDOWN','%s')"; + private static final String SHUTDOWN_SCRIPT = "return redis.call('SHUTDOWN','%s')"; - private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy( - JedisConverters.exceptionConverter()); + private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy( + JedisConverters.exceptionConverter()); - static { + static { - CLIENT_FIELD = ReflectionUtils.findField(BinaryJedis.class, "client", Client.class); - ReflectionUtils.makeAccessible(CLIENT_FIELD); + CLIENT_FIELD = ReflectionUtils.findField(BinaryJedis.class, "client", Client.class); + ReflectionUtils.makeAccessible(CLIENT_FIELD); - try { - Class commandType = ClassUtils.isPresent("redis.clients.jedis.ProtocolCommand", null) ? ClassUtils.forName( - "redis.clients.jedis.ProtocolCommand", null) : ClassUtils.forName("redis.clients.jedis.Protocol$Command", - null); + try { + Class commandType = ClassUtils.isPresent("redis.clients.jedis.ProtocolCommand", null) ? ClassUtils.forName( + "redis.clients.jedis.ProtocolCommand", null) : ClassUtils.forName("redis.clients.jedis.Protocol$Command", + null); + + SEND_COMMAND = ReflectionUtils.findMethod(Connection.class, "sendCommand", new Class[]{commandType, + byte[][].class}); + } catch (Exception e) { + throw new NoClassDefFoundError( + "Could not find required flavor of command required by 'redis.clients.jedis.Connection#sendCommand'."); + } - SEND_COMMAND = ReflectionUtils.findMethod(Connection.class, "sendCommand", new Class[] { commandType, - byte[][].class }); - } catch (Exception e) { - throw new NoClassDefFoundError( - "Could not find required flavor of command required by 'redis.clients.jedis.Connection#sendCommand'."); - } + ReflectionUtils.makeAccessible(SEND_COMMAND); - ReflectionUtils.makeAccessible(SEND_COMMAND); + GET_RESPONSE = ReflectionUtils.findMethod(Queable.class, "getResponse", Builder.class); + ReflectionUtils.makeAccessible(GET_RESPONSE); + } - GET_RESPONSE = ReflectionUtils.findMethod(Queable.class, "getResponse", Builder.class); - ReflectionUtils.makeAccessible(GET_RESPONSE); - } + private final Jedis jedis; + private final Client client; + private Transaction transaction; + private final Pool pool; + /** + * flag indicating whether the connection needs to be dropped or not + */ + private boolean broken = false; + private volatile JedisSubscription subscription; + private volatile Pipeline pipeline; + private final int dbIndex; + private boolean convertPipelineAndTxResults = true; + private List>> pipelinedResults = new ArrayList>>(); + private Queue>> txResults = new LinkedList>>(); + + private class JedisResult extends FutureResult> { + public JedisResult(Response resultHolder, Converter converter) { + super(resultHolder, converter); + } - private final Jedis jedis; - private final Client client; - private Transaction transaction; - private final Pool pool; - /** flag indicating whether the connection needs to be dropped or not */ - private boolean broken = false; - private volatile JedisSubscription subscription; - private volatile Pipeline pipeline; - private final int dbIndex; - private boolean convertPipelineAndTxResults = true; - private List>> pipelinedResults = new ArrayList>>(); - private Queue>> txResults = new LinkedList>>(); - - private class JedisResult extends FutureResult> { - public JedisResult(Response resultHolder, Converter converter) { - super(resultHolder, converter); - } + public JedisResult(Response resultHolder) { + super(resultHolder); + } - public JedisResult(Response resultHolder) { - super(resultHolder); - } + @SuppressWarnings("unchecked") + public Object get() { + if (convertPipelineAndTxResults && converter != null) { + return converter.convert(resultHolder.get()); + } + return resultHolder.get(); + } + } - @SuppressWarnings("unchecked") - public Object get() { - if (convertPipelineAndTxResults && converter != null) { - return converter.convert(resultHolder.get()); - } - return resultHolder.get(); - } - } + private class JedisStatusResult extends JedisResult { + public JedisStatusResult(Response resultHolder) { + super(resultHolder); + setStatus(true); + } + } - private class JedisStatusResult extends JedisResult { - public JedisStatusResult(Response resultHolder) { - super(resultHolder); - setStatus(true); - } - } + /** + * Constructs a new JedisConnection instance. + * + * @param jedis Jedis entity + */ + public JedisConnection(Jedis jedis) { + this(jedis, null, 0); + } - /** - * Constructs a new JedisConnection instance. - * - * @param jedis Jedis entity - */ - public JedisConnection(Jedis jedis) { - this(jedis, null, 0); - } + /** + * Constructs a new JedisConnection instance backed by a jedis pool. + * + * @param jedis + * @param pool can be null, if no pool is used + */ + public JedisConnection(Jedis jedis, Pool pool, int dbIndex) { + this.jedis = jedis; + // extract underlying connection for batch operations + client = (Client) ReflectionUtils.getField(CLIENT_FIELD, jedis); + + this.pool = pool; + + this.dbIndex = dbIndex; + + // select the db + // if this fail, do manual clean-up before propagating the exception + // as we're inside the constructor + if (dbIndex > 0) { + try { + select(dbIndex); + } catch (DataAccessException ex) { + close(); + throw ex; + } + } + } - /** - * Constructs a new JedisConnection instance backed by a jedis pool. - * - * @param jedis - * @param pool can be null, if no pool is used - */ - public JedisConnection(Jedis jedis, Pool pool, int dbIndex) { - this.jedis = jedis; - // extract underlying connection for batch operations - client = (Client) ReflectionUtils.getField(CLIENT_FIELD, jedis); - - this.pool = pool; - - this.dbIndex = dbIndex; - - // select the db - // if this fail, do manual clean-up before propagating the exception - // as we're inside the constructor - if (dbIndex > 0) { - try { - select(dbIndex); - } catch (DataAccessException ex) { - close(); - throw ex; - } - } - } + protected DataAccessException convertJedisAccessException(Exception ex) { - protected DataAccessException convertJedisAccessException(Exception ex) { + if (ex instanceof NullPointerException) { + // An NPE before flush will leave data in the OutputStream of a pooled connection + broken = true; + } - if (ex instanceof NullPointerException) { - // An NPE before flush will leave data in the OutputStream of a pooled connection - broken = true; - } + DataAccessException exception = EXCEPTION_TRANSLATION.translate(ex); + if (exception instanceof RedisConnectionFailureException) { + broken = true; + } - DataAccessException exception = EXCEPTION_TRANSLATION.translate(ex); - if (exception instanceof RedisConnectionFailureException) { - broken = true; - } + return exception; + } - return exception; - } + public Object execute(String command, byte[]... args) { + Assert.hasText(command, "a valid command needs to be specified"); + try { + List mArgs = new ArrayList(); + if (!ObjectUtils.isEmpty(args)) { + Collections.addAll(mArgs, args); + } - public Object execute(String command, byte[]... args) { - Assert.hasText(command, "a valid command needs to be specified"); - try { - List mArgs = new ArrayList(); - if (!ObjectUtils.isEmpty(args)) { - Collections.addAll(mArgs, args); - } + ReflectionUtils.invokeMethod(SEND_COMMAND, client, Command.valueOf(command.trim().toUpperCase()), + mArgs.toArray(new byte[mArgs.size()][])); + if (isQueueing() || isPipelined()) { + Object target = (isPipelined() ? pipeline : transaction); + @SuppressWarnings("unchecked") + Response result = (Response) ReflectionUtils.invokeMethod(GET_RESPONSE, target, + new Builder() { + public Object build(Object data) { + return data; + } + + public String toString() { + return "Object"; + } + }); + if (isPipelined()) { + pipeline(new JedisResult(result)); + } else { + transaction(new JedisResult(result)); + } + return null; + } + return client.getOne(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - ReflectionUtils.invokeMethod(SEND_COMMAND, client, Command.valueOf(command.trim().toUpperCase()), - mArgs.toArray(new byte[mArgs.size()][])); - if (isQueueing() || isPipelined()) { - Object target = (isPipelined() ? pipeline : transaction); - @SuppressWarnings("unchecked") - Response result = (Response) ReflectionUtils.invokeMethod(GET_RESPONSE, target, - new Builder() { - public Object build(Object data) { - return data; - } - - public String toString() { - return "Object"; - } - }); - if (isPipelined()) { - pipeline(new JedisResult(result)); - } else { - transaction(new JedisResult(result)); - } - return null; - } - return client.getOne(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void close() throws DataAccessException { + super.close(); + // return the connection to the pool + if (pool != null) { + if (!broken) { + // reset the connection + try { + if (dbIndex > 0) { + jedis.select(0); + } + pool.returnResource(jedis); + return; + } catch (Exception ex) { + DataAccessException dae = convertJedisAccessException(ex); + if (broken) { + pool.returnBrokenResource(jedis); + } else { + pool.returnResource(jedis); + } + throw dae; + } + } else { + pool.returnBrokenResource(jedis); + return; + } + } + // else close the connection normally (doing the try/catch dance) + Exception exc = null; + if (isQueueing()) { + try { + client.quit(); + } catch (Exception ex) { + exc = ex; + } + try { + client.disconnect(); + } catch (Exception ex) { + exc = ex; + } + return; + } + try { + jedis.quit(); + } catch (Exception ex) { + exc = ex; + } + try { + jedis.disconnect(); + } catch (Exception ex) { + exc = ex; + } + if (exc != null) + throw convertJedisAccessException(exc); + } - public void close() throws DataAccessException { - super.close(); - // return the connection to the pool - if (pool != null) { - if (!broken) { - // reset the connection - try { - if (dbIndex > 0) { - jedis.select(0); - } - pool.returnResource(jedis); - return; - } catch (Exception ex) { - DataAccessException dae = convertJedisAccessException(ex); - if (broken) { - pool.returnBrokenResource(jedis); - } else { - pool.returnResource(jedis); - } - throw dae; - } - } else { - pool.returnBrokenResource(jedis); - return; - } - } - // else close the connection normally (doing the try/catch dance) - Exception exc = null; - if (isQueueing()) { - try { - client.quit(); - } catch (Exception ex) { - exc = ex; - } - try { - client.disconnect(); - } catch (Exception ex) { - exc = ex; - } - return; - } - try { - jedis.quit(); - } catch (Exception ex) { - exc = ex; - } - try { - jedis.disconnect(); - } catch (Exception ex) { - exc = ex; - } - if (exc != null) - throw convertJedisAccessException(exc); - } + public Jedis getNativeConnection() { + return jedis; + } - public Jedis getNativeConnection() { - return jedis; - } + public boolean isClosed() { + try { + return !jedis.isConnected(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public boolean isClosed() { - try { - return !jedis.isConnected(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public boolean isQueueing() { + return client.isInMulti(); + } - public boolean isQueueing() { - return client.isInMulti(); - } + public boolean isPipelined() { + return (pipeline != null); + } - public boolean isPipelined() { - return (pipeline != null); - } + public void openPipeline() { + if (pipeline == null) { + pipeline = jedis.pipelined(); + } + } - public void openPipeline() { - if (pipeline == null) { - pipeline = jedis.pipelined(); - } - } + public List closePipeline() { + if (pipeline != null) { + try { + return convertPipelineResults(); + } finally { + pipeline = null; + pipelinedResults.clear(); + } + } + return Collections.emptyList(); + } - public List closePipeline() { - if (pipeline != null) { - try { - return convertPipelineResults(); - } finally { - pipeline = null; - pipelinedResults.clear(); - } - } - return Collections.emptyList(); - } + private List convertPipelineResults() { + List results = new ArrayList(); + pipeline.sync(); + Exception cause = null; + for (FutureResult> result : pipelinedResults) { + try { + Object data = result.get(); + if (!convertPipelineAndTxResults || !(result.isStatus())) { + results.add(data); + } + } catch (JedisDataException e) { + DataAccessException dataAccessException = convertJedisAccessException(e); + if (cause == null) { + cause = dataAccessException; + } + results.add(dataAccessException); + } catch (DataAccessException e) { + if (cause == null) { + cause = e; + } + results.add(e); + } + } + if (cause != null) { + throw new RedisPipelineException(cause, results); + } + return results; + } - private List convertPipelineResults() { - List results = new ArrayList(); - pipeline.sync(); - Exception cause = null; - for (FutureResult> result : pipelinedResults) { - try { - Object data = result.get(); - if (!convertPipelineAndTxResults || !(result.isStatus())) { - results.add(data); - } - } catch (JedisDataException e) { - DataAccessException dataAccessException = convertJedisAccessException(e); - if (cause == null) { - cause = dataAccessException; - } - results.add(dataAccessException); - } catch (DataAccessException e) { - if (cause == null) { - cause = e; - } - results.add(e); - } - } - if (cause != null) { - throw new RedisPipelineException(cause, results); - } - return results; - } + private void doPipelined(Response response) { + pipeline(new JedisStatusResult(response)); + } - private void doPipelined(Response response) { - pipeline(new JedisStatusResult(response)); - } + private void pipeline(FutureResult> result) { + if (isQueueing()) { + transaction(result); + } else { + pipelinedResults.add(result); + } + } - private void pipeline(FutureResult> result) { - if (isQueueing()) { - transaction(result); - } else { - pipelinedResults.add(result); - } - } + private void doQueued(Response response) { + transaction(new JedisStatusResult(response)); + } - private void doQueued(Response response) { - transaction(new JedisStatusResult(response)); - } + private void transaction(FutureResult> result) { + txResults.add(result); + } - private void transaction(FutureResult> result) { - txResults.add(result); - } + public List sort(byte[] key, SortParameters params) { - public List sort(byte[] key, SortParameters params) { + SortingParams sortParams = JedisConverters.toSortingParams(params); - SortingParams sortParams = JedisConverters.toSortingParams(params); + try { + if (isPipelined()) { + if (sortParams != null) { + pipeline(new JedisResult(pipeline.sort(key, sortParams))); + } else { + pipeline(new JedisResult(pipeline.sort(key))); + } - try { - if (isPipelined()) { - if (sortParams != null) { - pipeline(new JedisResult(pipeline.sort(key, sortParams))); - } else { - pipeline(new JedisResult(pipeline.sort(key))); - } + return null; + } + if (isQueueing()) { + if (sortParams != null) { + transaction(new JedisResult(transaction.sort(key, sortParams))); + } else { + transaction(new JedisResult(transaction.sort(key))); + } - return null; - } - if (isQueueing()) { - if (sortParams != null) { - transaction(new JedisResult(transaction.sort(key, sortParams))); - } else { - transaction(new JedisResult(transaction.sort(key))); - } + return null; + } + return (sortParams != null ? jedis.sort(key, sortParams) : jedis.sort(key)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - return null; - } - return (sortParams != null ? jedis.sort(key, sortParams) : jedis.sort(key)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long sort(byte[] key, SortParameters params, byte[] storeKey) { - public Long sort(byte[] key, SortParameters params, byte[] storeKey) { + SortingParams sortParams = JedisConverters.toSortingParams(params); - SortingParams sortParams = JedisConverters.toSortingParams(params); + try { + if (isPipelined()) { + if (sortParams != null) { + pipeline(new JedisResult(pipeline.sort(key, sortParams, storeKey))); + } else { + pipeline(new JedisResult(pipeline.sort(key, storeKey))); + } - try { - if (isPipelined()) { - if (sortParams != null) { - pipeline(new JedisResult(pipeline.sort(key, sortParams, storeKey))); - } else { - pipeline(new JedisResult(pipeline.sort(key, storeKey))); - } + return null; + } + if (isQueueing()) { + if (sortParams != null) { + transaction(new JedisResult(transaction.sort(key, sortParams, storeKey))); + } else { + transaction(new JedisResult(transaction.sort(key, storeKey))); + } - return null; - } - if (isQueueing()) { - if (sortParams != null) { - transaction(new JedisResult(transaction.sort(key, sortParams, storeKey))); - } else { - transaction(new JedisResult(transaction.sort(key, storeKey))); - } + return null; + } + return (sortParams != null ? jedis.sort(key, sortParams, storeKey) : jedis.sort(key, storeKey)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - return null; - } - return (sortParams != null ? jedis.sort(key, sortParams, storeKey) : jedis.sort(key, storeKey)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long dbSize() { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.dbSize())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.dbSize())); + return null; + } + return jedis.dbSize(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long dbSize() { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.dbSize())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.dbSize())); - return null; - } - return jedis.dbSize(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void flushDb() { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.flushDB())); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.flushDB())); + return; + } + jedis.flushDB(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void flushDb() { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.flushDB())); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.flushDB())); - return; - } - jedis.flushDB(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void flushAll() { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.flushAll())); + return; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.flushAll())); + return; + } + jedis.flushAll(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void flushAll() { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.flushAll())); - return; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.flushAll())); - return; - } - jedis.flushAll(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void bgSave() { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.bgsave())); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.bgsave())); + return; + } + jedis.bgsave(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void bgSave() { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.bgsave())); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.bgsave())); - return; - } - jedis.bgsave(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - @Override - public void bgReWriteAof() { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.bgrewriteaof())); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.bgrewriteaof())); - return; - } - jedis.bgrewriteaof(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + @Override + public void bgReWriteAof() { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.bgrewriteaof())); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.bgrewriteaof())); + return; + } + jedis.bgrewriteaof(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /** - * @deprecated As of 1.3, use {@link #bgReWriteAof}. - */ - @Deprecated - public void bgWriteAof() { - bgReWriteAof(); - } + /** + * @deprecated As of 1.3, use {@link #bgReWriteAof}. + */ + @Deprecated + public void bgWriteAof() { + bgReWriteAof(); + } - public void save() { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.save())); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.save())); - return; - } - jedis.save(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void save() { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.save())); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.save())); + return; + } + jedis.save(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public List getConfig(String param) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.configGet(param))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.configGet(param))); - return null; - } - return jedis.configGet(param); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public List getConfig(String param) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.configGet(param))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.configGet(param))); + return null; + } + return jedis.configGet(param); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Properties info() { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.info(), JedisConverters.stringToProps())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.info(), JedisConverters.stringToProps())); - return null; - } - return JedisConverters.toProperties(jedis.info()); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Properties info() { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.info(), JedisConverters.stringToProps())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.info(), JedisConverters.stringToProps())); + return null; + } + return JedisConverters.toProperties(jedis.info()); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Properties info(String section) { - if (isPipelined()) { - throw new UnsupportedOperationException(); - } - if (isQueueing()) { - throw new UnsupportedOperationException(); - } - try { - return JedisConverters.toProperties(jedis.info(section)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Properties info(String section) { + if (isPipelined()) { + throw new UnsupportedOperationException(); + } + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + try { + return JedisConverters.toProperties(jedis.info(section)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long lastSave() { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.lastsave())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.lastsave())); - return null; - } - return jedis.lastsave(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long lastSave() { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.lastsave())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.lastsave())); + return null; + } + return jedis.lastsave(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void setConfig(String param, String value) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.configSet(param, value))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.configSet(param, value))); - return; - } - jedis.configSet(param, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void setConfig(String param, String value) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.configSet(param, value))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.configSet(param, value))); + return; + } + jedis.configSet(param, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void resetConfigStats() { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.configResetStat())); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.configResetStat())); - return; - } - jedis.configResetStat(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void resetConfigStats() { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.configResetStat())); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.configResetStat())); + return; + } + jedis.configResetStat(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void shutdown() { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.shutdown())); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.shutdown())); - return; - } - jedis.shutdown(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void shutdown() { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.shutdown())); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.shutdown())); + return; + } + jedis.shutdown(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisServerCommands#shutdown(org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption) */ - @Override - public void shutdown(ShutdownOption option) { + @Override + public void shutdown(ShutdownOption option) { - if (option == null) { - shutdown(); - return; - } + if (option == null) { + shutdown(); + return; + } - eval(String.format(SHUTDOWN_SCRIPT, option.name()).getBytes(), ReturnType.STATUS, 0); - } + eval(String.format(SHUTDOWN_SCRIPT, option.name()).getBytes(), ReturnType.STATUS, 0); + } - public byte[] echo(byte[] message) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.echo(message))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.echo(message))); - return null; - } - return jedis.echo(message); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] echo(byte[] message) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.echo(message))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.echo(message))); + return null; + } + return jedis.echo(message); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public String ping() { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.ping())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.ping())); - return null; - } - return jedis.ping(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public String ping() { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.ping())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.ping())); + return null; + } + return jedis.ping(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long del(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.del(keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.del(keys))); - return null; - } - return jedis.del(keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long del(byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.del(keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.del(keys))); + return null; + } + return jedis.del(keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void discard() { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.discard())); - return; - } - transaction.discard(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } finally { - txResults.clear(); - transaction = null; - } - } + public void discard() { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.discard())); + return; + } + transaction.discard(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } finally { + txResults.clear(); + transaction = null; + } + } - public List exec() { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.exec(), new TransactionResultConverter>( - new LinkedList>>(txResults), JedisConverters.exceptionConverter()))); - return null; - } + public List exec() { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.exec(), new TransactionResultConverter>( + new LinkedList>>(txResults), JedisConverters.exceptionConverter()))); + return null; + } - if (transaction == null) { - throw new InvalidDataAccessApiUsageException("No ongoing transaction. Did you forget to call multi?"); - } - List results = transaction.exec(); - return convertPipelineAndTxResults ? new TransactionResultConverter>(txResults, - JedisConverters.exceptionConverter()).convert(results) : results; - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } finally { - txResults.clear(); - transaction = null; - } - } + if (transaction == null) { + throw new InvalidDataAccessApiUsageException("No ongoing transaction. Did you forget to call multi?"); + } + List results = transaction.exec(); + return convertPipelineAndTxResults ? new TransactionResultConverter>(txResults, + JedisConverters.exceptionConverter()).convert(results) : results; + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } finally { + txResults.clear(); + transaction = null; + } + } - public Boolean exists(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.exists(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.exists(key))); - return null; - } - return jedis.exists(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean exists(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.exists(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.exists(key))); + return null; + } + return jedis.exists(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean expire(byte[] key, long seconds) { + public Boolean expire(byte[] key, long seconds) { /* * @see DATAREDIS-286 to avoid overflow in Jedis @@ -792,2297 +770,2297 @@ public Boolean expire(byte[] key, long seconds) { * TODO Remove this workaround when we upgrade to a Jedis version that contains a * fix for: https://github.com/xetorthio/jedis/pull/575 */ - if (seconds > Integer.MAX_VALUE) { - - return pExpireAt(key, time() + TimeUnit.SECONDS.toMillis(seconds)); - } + if (seconds > Integer.MAX_VALUE) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.expire(key, (int) seconds), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.expire(key, (int) seconds), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.expire(key, (int) seconds)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + return pExpireAt(key, time() + TimeUnit.SECONDS.toMillis(seconds)); + } - public Boolean expireAt(byte[] key, long unixTime) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.expireAt(key, unixTime), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.expireAt(key, unixTime), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.expireAt(key, unixTime)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.expire(key, (int) seconds), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.expire(key, (int) seconds), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.expire(key, (int) seconds)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Set keys(byte[] pattern) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.keys(pattern))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.keys(pattern))); - return null; - } - return (jedis.keys(pattern)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean expireAt(byte[] key, long unixTime) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.expireAt(key, unixTime), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.expireAt(key, unixTime), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.expireAt(key, unixTime)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void multi() { - if (isQueueing()) { - return; - } - try { - if (isPipelined()) { - pipeline.multi(); - return; - } - this.transaction = jedis.multi(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Set keys(byte[] pattern) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.keys(pattern))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.keys(pattern))); + return null; + } + return (jedis.keys(pattern)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean persist(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.persist(key), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.persist(key), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.persist(key)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void multi() { + if (isQueueing()) { + return; + } + try { + if (isPipelined()) { + pipeline.multi(); + return; + } + this.transaction = jedis.multi(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean move(byte[] key, int dbIndex) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.move(key, dbIndex), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.move(key, dbIndex), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.move(key, dbIndex)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean persist(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.persist(key), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.persist(key), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.persist(key)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] randomKey() { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.randomKeyBinary())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.randomKeyBinary())); - return null; - } - return jedis.randomBinaryKey(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean move(byte[] key, int dbIndex) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.move(key, dbIndex), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.move(key, dbIndex), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.move(key, dbIndex)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void rename(byte[] oldName, byte[] newName) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.rename(oldName, newName))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.rename(oldName, newName))); - return; - } - jedis.rename(oldName, newName); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] randomKey() { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.randomKeyBinary())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.randomKeyBinary())); + return null; + } + return jedis.randomBinaryKey(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean renameNX(byte[] oldName, byte[] newName) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.renamenx(oldName, newName), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.renamenx(oldName, newName), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.renamenx(oldName, newName)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void rename(byte[] oldName, byte[] newName) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.rename(oldName, newName))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.rename(oldName, newName))); + return; + } + jedis.rename(oldName, newName); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void select(int dbIndex) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.select(dbIndex))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.select(dbIndex))); - return; - } - jedis.select(dbIndex); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - public Long ttl(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.ttl(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.ttl(key))); - return null; - } - return jedis.ttl(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - public Boolean pExpire(byte[] key, long millis) { - - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.pexpire(key, millis), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.pexpire(key, millis), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.pexpire(key, millis)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.pexpireAt(key, unixTimeInMillis)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean renameNX(byte[] oldName, byte[] newName) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.renamenx(oldName, newName), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.renamenx(oldName, newName), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.renamenx(oldName, newName)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long pTtl(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.pttl(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.pttl(key))); - return null; - } - return jedis.pttl(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void select(int dbIndex) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.select(dbIndex))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.select(dbIndex))); + return; + } + jedis.select(dbIndex); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] dump(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.dump(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.dump(key))); - return null; - } - return jedis.dump(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long ttl(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.ttl(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.ttl(key))); + return null; + } + return jedis.ttl(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) { + public Boolean pExpire(byte[] key, long millis) { - if (ttlInMillis > Integer.MAX_VALUE) { - throw new IllegalArgumentException("TtlInMillis must be less than Integer.MAX_VALUE for restore in Jedis."); - } - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.restore(key, (int) ttlInMillis, serializedValue))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.restore(key, (int) ttlInMillis, serializedValue))); - return; - } - jedis.restore(key, (int) ttlInMillis, serializedValue); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.pexpire(key, millis), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.pexpire(key, millis), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.pexpire(key, millis)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public DataType type(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.type(key), JedisConverters.stringToDataType())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.type(key), JedisConverters.stringToDataType())); - return null; - } - return JedisConverters.toDataType(jedis.type(key)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean pExpireAt(byte[] key, long unixTimeInMillis) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.pexpireAt(key, unixTimeInMillis), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.pexpireAt(key, unixTimeInMillis)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void unwatch() { - try { - jedis.unwatch(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long pTtl(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.pttl(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.pttl(key))); + return null; + } + return jedis.pttl(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void watch(byte[]... keys) { - if (isQueueing()) { - throw new UnsupportedOperationException(); - } - try { - for (byte[] key : keys) { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.watch(key))); - } else { - jedis.watch(key); - } - } - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] dump(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.dump(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.dump(key))); + return null; + } + return jedis.dump(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - // - // String commands - // + public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) { - public byte[] get(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.get(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.get(key))); - return null; - } + if (ttlInMillis > Integer.MAX_VALUE) { + throw new IllegalArgumentException("TtlInMillis must be less than Integer.MAX_VALUE for restore in Jedis."); + } + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.restore(key, (int) ttlInMillis, serializedValue))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.restore(key, (int) ttlInMillis, serializedValue))); + return; + } + jedis.restore(key, (int) ttlInMillis, serializedValue); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - return jedis.get(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public DataType type(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.type(key), JedisConverters.stringToDataType())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.type(key), JedisConverters.stringToDataType())); + return null; + } + return JedisConverters.toDataType(jedis.type(key)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void set(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.set(key, value))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.set(key, value))); - return; - } - jedis.set(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void unwatch() { + try { + jedis.unwatch(); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[], org.springframework.data.redis.core.types.Expiration, org.springframework.data.redis.connection.RedisStringCommands.SetOption) - */ - @Override - public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) { + public void watch(byte[]... keys) { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + try { + for (byte[] key : keys) { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.watch(key))); + } else { + jedis.watch(key); + } + } + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - if (expiration == null || expiration.isPersistent()) { + // + // String commands + // - if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) { - set(key, value); - } else { + public byte[] get(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.get(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.get(key))); + return null; + } - try { + return jedis.get(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - byte[] nxxx = JedisConverters.toSetCommandNxXxArgument(option); + public void set(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.set(key, value))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.set(key, value))); + return; + } + jedis.set(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - if (isPipelined()) { + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisStringCommands#set(byte[], byte[], org.springframework.data.redis.core.types.Expiration, org.springframework.data.redis.connection.RedisStringCommands.SetOption) + */ + @Override + public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) { - pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx))); - return; - } - if (isQueueing()) { + if (expiration == null || expiration.isPersistent()) { - transaction(new JedisStatusResult(transaction.set(key, value, nxxx))); - return; - } + if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) { + set(key, value); + } else { - jedis.set(key, value, nxxx); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + try { - } else { + byte[] nxxx = JedisConverters.toSetCommandNxXxArgument(option); - if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) { + if (isPipelined()) { - if (ObjectUtils.nullSafeEquals(TimeUnit.MILLISECONDS, expiration.getTimeUnit())) { - pSetEx(key, expiration.getExpirationTime(), value); - } else { - setEx(key, expiration.getExpirationTime(), value); - } - } else { + pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx))); + return; + } + if (isQueueing()) { - byte[] nxxx = JedisConverters.toSetCommandNxXxArgument(option); - byte[] expx = JedisConverters.toSetCommandExPxArgument(expiration); + transaction(new JedisStatusResult(transaction.set(key, value, nxxx))); + return; + } - try { - if (isPipelined()) { + jedis.set(key, value, nxxx); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - if (expiration.getExpirationTime() > Integer.MAX_VALUE) { + } else { - throw new IllegalArgumentException( - "Expiration.expirationTime must be less than Integer.MAX_VALUE for pipeline in Jedis."); - } + if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) { - pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx, expx, (int) expiration.getExpirationTime()))); - return; - } - if (isQueueing()) { + if (ObjectUtils.nullSafeEquals(TimeUnit.MILLISECONDS, expiration.getTimeUnit())) { + pSetEx(key, expiration.getExpirationTime(), value); + } else { + setEx(key, expiration.getExpirationTime(), value); + } + } else { - if (expiration.getExpirationTime() > Integer.MAX_VALUE) { - throw new IllegalArgumentException( - "Expiration.expirationTime must be less than Integer.MAX_VALUE for transactions in Jedis."); - } + byte[] nxxx = JedisConverters.toSetCommandNxXxArgument(option); + byte[] expx = JedisConverters.toSetCommandExPxArgument(expiration); - transaction(new JedisStatusResult(transaction.set(key, value, nxxx, expx, - (int) expiration.getExpirationTime()))); - return; - } + try { + if (isPipelined()) { - jedis.set(key, value, nxxx, expx, expiration.getExpirationTime()); + if (expiration.getExpirationTime() > Integer.MAX_VALUE) { - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - } - } + throw new IllegalArgumentException( + "Expiration.expirationTime must be less than Integer.MAX_VALUE for pipeline in Jedis."); + } - public byte[] getSet(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.getSet(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.getSet(key, value))); - return null; - } - return jedis.getSet(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx, expx, (int) expiration.getExpirationTime()))); + return; + } + if (isQueueing()) { - public Long append(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.append(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.append(key, value))); - return null; - } - return jedis.append(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + if (expiration.getExpirationTime() > Integer.MAX_VALUE) { + throw new IllegalArgumentException( + "Expiration.expirationTime must be less than Integer.MAX_VALUE for transactions in Jedis."); + } - public List mGet(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.mget(keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.mget(keys))); - return null; - } - return jedis.mget(keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + transaction(new JedisStatusResult(transaction.set(key, value, nxxx, expx, + (int) expiration.getExpirationTime()))); + return; + } - public void mSet(Map tuples) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.mset(JedisConverters.toByteArrays(tuples)))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.mset(JedisConverters.toByteArrays(tuples)))); - return; - } - jedis.mset(JedisConverters.toByteArrays(tuples)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + jedis.set(key, value, nxxx, expx, expiration.getExpirationTime()); - public Boolean mSetNX(Map tuples) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.msetnx(JedisConverters.toByteArrays(tuples)), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.msetnx(JedisConverters.toByteArrays(tuples)), - JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.msetnx(JedisConverters.toByteArrays(tuples))); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + } + } - public void setEx(byte[] key, long time, byte[] value) { + public byte[] getSet(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.getSet(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.getSet(key, value))); + return null; + } + return jedis.getSet(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - if (time > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Time must be less than Integer.MAX_VALUE for setEx in Jedis."); - } + public Long append(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.append(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.append(key, value))); + return null; + } + return jedis.append(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.setex(key, (int) time, value))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.setex(key, (int) time, value))); - return; - } - jedis.setex(key, (int) time, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public List mGet(byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.mget(keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.mget(keys))); + return null; + } + return jedis.mget(keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + public void mSet(Map tuples) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.mset(JedisConverters.toByteArrays(tuples)))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.mset(JedisConverters.toByteArrays(tuples)))); + return; + } + jedis.mset(JedisConverters.toByteArrays(tuples)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + public Boolean mSetNX(Map tuples) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.msetnx(JedisConverters.toByteArrays(tuples)), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.msetnx(JedisConverters.toByteArrays(tuples)), + JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.msetnx(JedisConverters.toByteArrays(tuples))); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + public void setEx(byte[] key, long time, byte[] value) { + + if (time > Integer.MAX_VALUE) { + throw new IllegalArgumentException("Time must be less than Integer.MAX_VALUE for setEx in Jedis."); + } + + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.setex(key, (int) time, value))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.setex(key, (int) time, value))); + return; + } + jedis.setex(key, (int) time, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisStringCommands#pSetEx(byte[], long, byte[]) */ - @Override - public void pSetEx(byte[] key, long milliseconds, byte[] value) { + @Override + public void pSetEx(byte[] key, long milliseconds, byte[] value) { - try { - if (isPipelined()) { - doPipelined(pipeline.psetex(key, milliseconds, value)); - return; - } - if (isQueueing()) { - doQueued(transaction.psetex(key, milliseconds, value)); - return; - } - jedis.psetex(key, milliseconds, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + try { + if (isPipelined()) { + doPipelined(pipeline.psetex(key, milliseconds, value)); + return; + } + if (isQueueing()) { + doQueued(transaction.psetex(key, milliseconds, value)); + return; + } + jedis.psetex(key, milliseconds, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean setNX(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.setnx(key, value), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.setnx(key, value), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.setnx(key, value)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean setNX(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.setnx(key, value), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.setnx(key, value), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.setnx(key, value)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] getRange(byte[] key, long start, long end) { + public byte[] getRange(byte[] key, long start, long end) { - if (start > Integer.MAX_VALUE || end > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Start and end must be less than Integer.MAX_VALUE for getRange in Jedis."); - } + if (start > Integer.MAX_VALUE || end > Integer.MAX_VALUE) { + throw new IllegalArgumentException("Start and end must be less than Integer.MAX_VALUE for getRange in Jedis."); + } - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.substr(key, (int) start, (int) end), JedisConverters.stringToBytes())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.substr(key, (int) start, (int) end), JedisConverters.stringToBytes())); - return null; - } - return jedis.substr(key, (int) start, (int) end); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.substr(key, (int) start, (int) end), JedisConverters.stringToBytes())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.substr(key, (int) start, (int) end), JedisConverters.stringToBytes())); + return null; + } + return jedis.substr(key, (int) start, (int) end); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long decr(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.decr(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.decr(key))); - return null; - } - return jedis.decr(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long decr(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.decr(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.decr(key))); + return null; + } + return jedis.decr(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long decrBy(byte[] key, long value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.decrBy(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.decrBy(key, value))); - return null; - } - return jedis.decrBy(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - public Long incr(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.incr(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.incr(key))); - return null; - } - return jedis.incr(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long decrBy(byte[] key, long value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.decrBy(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.decrBy(key, value))); + return null; + } + return jedis.decrBy(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long incrBy(byte[] key, long value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.incrBy(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.incrBy(key, value))); - return null; - } - return jedis.incrBy(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long incr(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.incr(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.incr(key))); + return null; + } + return jedis.incr(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Double incrBy(byte[] key, double value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.incrByFloat(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.incrByFloat(key, value))); - return null; - } - return jedis.incrByFloat(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long incrBy(byte[] key, long value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.incrBy(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.incrBy(key, value))); + return null; + } + return jedis.incrBy(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean getBit(byte[] key, long offset) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.getbit(key, offset))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.getbit(key, offset))); - return null; - } - // 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); - } - } + public Double incrBy(byte[] key, double value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.incrByFloat(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.incrByFloat(key, value))); + return null; + } + return jedis.incrByFloat(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean setBit(byte[] key, long offset, boolean value) { - try { - if (isPipelined()) { + public Boolean getBit(byte[] key, long offset) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.getbit(key, offset))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.getbit(key, offset))); + return null; + } + // 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); + } + } - pipeline(new JedisResult(pipeline.setbit(key, offset, JedisConverters.toBit(value)))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.setbit(key, offset, JedisConverters.toBit(value)))); - return null; - } - return jedis.setbit(key, offset, JedisConverters.toBit(value)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean setBit(byte[] key, long offset, boolean value) { + try { + if (isPipelined()) { - public void setRange(byte[] key, byte[] value, long start) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.setrange(key, start, value))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.setrange(key, start, value))); - return; - } - jedis.setrange(key, start, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + pipeline(new JedisResult(pipeline.setbit(key, offset, JedisConverters.toBit(value)))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.setbit(key, offset, JedisConverters.toBit(value)))); + return null; + } + return jedis.setbit(key, offset, JedisConverters.toBit(value)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long strLen(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.strlen(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.strlen(key))); - return null; - } - return jedis.strlen(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void setRange(byte[] key, byte[] value, long start) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.setrange(key, start, value))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.setrange(key, start, value))); + return; + } + jedis.setrange(key, start, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long bitCount(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.bitcount(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.bitcount(key))); - return null; - } - return jedis.bitcount(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long strLen(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.strlen(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.strlen(key))); + return null; + } + return jedis.strlen(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long bitCount(byte[] key, long begin, long end) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.bitcount(key, begin, end))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.bitcount(key, begin, end))); - return null; - } - return jedis.bitcount(key, begin, end); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long bitCount(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.bitcount(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.bitcount(key))); + return null; + } + return jedis.bitcount(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { - if (op == BitOperation.NOT && keys.length > 1) { - throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); - } - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.bitop(JedisConverters.toBitOp(op), destination, keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.bitop(JedisConverters.toBitOp(op), destination, keys))); - return null; - } - return jedis.bitop(JedisConverters.toBitOp(op), destination, keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long bitCount(byte[] key, long begin, long end) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.bitcount(key, begin, end))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.bitcount(key, begin, end))); + return null; + } + return jedis.bitcount(key, begin, end); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - // - // List commands - // + public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) { + if (op == BitOperation.NOT && keys.length > 1) { + throw new UnsupportedOperationException("Bitop NOT should only be performed against one key"); + } + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.bitop(JedisConverters.toBitOp(op), destination, keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.bitop(JedisConverters.toBitOp(op), destination, keys))); + return null; + } + return jedis.bitop(JedisConverters.toBitOp(op), destination, keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long lPush(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.lpush(key, values))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.lpush(key, values))); - return null; - } - return jedis.lpush(key, values); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + // + // List commands + // - public Long rPush(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.rpush(key, values))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.rpush(key, values))); - return null; - } - return jedis.rpush(key, values); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - public List bLPop(int timeout, byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.blpop(bXPopArgs(timeout, keys)))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.blpop(bXPopArgs(timeout, keys)))); - return null; - } - return jedis.blpop(timeout, keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long lPush(byte[] key, byte[]... values) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.lpush(key, values))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.lpush(key, values))); + return null; + } + return jedis.lpush(key, values); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public List bRPop(int timeout, byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.brpop(bXPopArgs(timeout, keys)))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.brpop(bXPopArgs(timeout, keys)))); - return null; - } - return jedis.brpop(timeout, keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long rPush(byte[] key, byte[]... values) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.rpush(key, values))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.rpush(key, values))); + return null; + } + return jedis.rpush(key, values); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] lIndex(byte[] key, long index) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.lindex(key, index))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.lindex(key, index))); - return null; - } - return jedis.lindex(key, index); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public List bLPop(int timeout, byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.blpop(bXPopArgs(timeout, keys)))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.blpop(bXPopArgs(timeout, keys)))); + return null; + } + return jedis.blpop(timeout, keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.linsert(key, JedisConverters.toListPosition(where), pivot, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.linsert(key, JedisConverters.toListPosition(where), pivot, value))); - return null; - } - return jedis.linsert(key, JedisConverters.toListPosition(where), pivot, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public List bRPop(int timeout, byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.brpop(bXPopArgs(timeout, keys)))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.brpop(bXPopArgs(timeout, keys)))); + return null; + } + return jedis.brpop(timeout, keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long lLen(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.llen(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.llen(key))); - return null; - } - return jedis.llen(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] lIndex(byte[] key, long index) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.lindex(key, index))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.lindex(key, index))); + return null; + } + return jedis.lindex(key, index); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] lPop(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.lpop(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.lpop(key))); - return null; - } - return jedis.lpop(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.linsert(key, JedisConverters.toListPosition(where), pivot, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.linsert(key, JedisConverters.toListPosition(where), pivot, value))); + return null; + } + return jedis.linsert(key, JedisConverters.toListPosition(where), pivot, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public List lRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.lrange(key, start, end))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.lrange(key, start, end))); - return null; - } - return jedis.lrange(key, start, end); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long lLen(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.llen(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.llen(key))); + return null; + } + return jedis.llen(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long lRem(byte[] key, long count, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.lrem(key, count, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.lrem(key, count, value))); - return null; - } - return jedis.lrem(key, count, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] lPop(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.lpop(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.lpop(key))); + return null; + } + return jedis.lpop(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void lSet(byte[] key, long index, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.lset(key, index, value))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.lset(key, index, value))); - return; - } - jedis.lset(key, index, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public List lRange(byte[] key, long start, long end) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.lrange(key, start, end))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.lrange(key, start, end))); + return null; + } + return jedis.lrange(key, start, end); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void lTrim(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.ltrim(key, start, end))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.ltrim(key, start, end))); - return; - } - jedis.ltrim(key, start, end); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long lRem(byte[] key, long count, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.lrem(key, count, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.lrem(key, count, value))); + return null; + } + return jedis.lrem(key, count, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] rPop(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.rpop(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.rpop(key))); - return null; - } - return jedis.rpop(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void lSet(byte[] key, long index, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.lset(key, index, value))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.lset(key, index, value))); + return; + } + jedis.lset(key, index, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.rpoplpush(srcKey, dstKey))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.rpoplpush(srcKey, dstKey))); - return null; - } - return jedis.rpoplpush(srcKey, dstKey); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void lTrim(byte[] key, long start, long end) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.ltrim(key, start, end))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.ltrim(key, start, end))); + return; + } + jedis.ltrim(key, start, end); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.brpoplpush(srcKey, dstKey, timeout))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.brpoplpush(srcKey, dstKey, timeout))); - return null; - } - return jedis.brpoplpush(srcKey, dstKey, timeout); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] rPop(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.rpop(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.rpop(key))); + return null; + } + return jedis.rpop(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long lPushX(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.lpushx(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.lpushx(key, value))); - return null; - } - return jedis.lpushx(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.rpoplpush(srcKey, dstKey))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.rpoplpush(srcKey, dstKey))); + return null; + } + return jedis.rpoplpush(srcKey, dstKey); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long rPushX(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.rpushx(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.rpushx(key, value))); - return null; - } - return jedis.rpushx(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] bRPopLPush(int timeout, byte[] srcKey, byte[] dstKey) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.brpoplpush(srcKey, dstKey, timeout))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.brpoplpush(srcKey, dstKey, timeout))); + return null; + } + return jedis.brpoplpush(srcKey, dstKey, timeout); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - // - // Set commands - // + public Long lPushX(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.lpushx(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.lpushx(key, value))); + return null; + } + return jedis.lpushx(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long sAdd(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.sadd(key, values))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.sadd(key, values))); - return null; - } - return jedis.sadd(key, values); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long rPushX(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.rpushx(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.rpushx(key, value))); + return null; + } + return jedis.rpushx(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long sCard(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.scard(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.scard(key))); - return null; - } - return jedis.scard(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + // + // Set commands + // - public Set sDiff(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.sdiff(keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.sdiff(keys))); - return null; - } - return jedis.sdiff(keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long sAdd(byte[] key, byte[]... values) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.sadd(key, values))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.sadd(key, values))); + return null; + } + return jedis.sadd(key, values); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long sDiffStore(byte[] destKey, byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.sdiffstore(destKey, keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.sdiffstore(destKey, keys))); - return null; - } - return jedis.sdiffstore(destKey, keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long sCard(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.scard(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.scard(key))); + return null; + } + return jedis.scard(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Set sInter(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.sinter(keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.sinter(keys))); - return null; - } - return jedis.sinter(keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Set sDiff(byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.sdiff(keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.sdiff(keys))); + return null; + } + return jedis.sdiff(keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long sInterStore(byte[] destKey, byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.sinterstore(destKey, keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.sinterstore(destKey, keys))); - return null; - } - return jedis.sinterstore(destKey, keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long sDiffStore(byte[] destKey, byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.sdiffstore(destKey, keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.sdiffstore(destKey, keys))); + return null; + } + return jedis.sdiffstore(destKey, keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean sIsMember(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.sismember(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.sismember(key, value))); - return null; - } - return jedis.sismember(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Set sInter(byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.sinter(keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.sinter(keys))); + return null; + } + return jedis.sinter(keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Set sMembers(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.smembers(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.smembers(key))); - return null; - } - return jedis.smembers(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long sInterStore(byte[] destKey, byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.sinterstore(destKey, keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.sinterstore(destKey, keys))); + return null; + } + return jedis.sinterstore(destKey, keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.smove(srcKey, destKey, value), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.smove(srcKey, destKey, value), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.smove(srcKey, destKey, value)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean sIsMember(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.sismember(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.sismember(key, value))); + return null; + } + return jedis.sismember(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] sPop(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.spop(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.spop(key))); - return null; - } - return jedis.spop(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Set sMembers(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.smembers(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.smembers(key))); + return null; + } + return jedis.smembers(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] sRandMember(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.srandmember(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.srandmember(key))); - return null; - } - return jedis.srandmember(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean sMove(byte[] srcKey, byte[] destKey, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.smove(srcKey, destKey, value), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.smove(srcKey, destKey, value), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.smove(srcKey, destKey, value)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public List sRandMember(byte[] key, long count) { + public byte[] sPop(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.spop(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.spop(key))); + return null; + } + return jedis.spop(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - if (count > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Count must be less than Integer.MAX_VALUE for sRandMember in Jedis."); - } + public byte[] sRandMember(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.srandmember(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.srandmember(key))); + return null; + } + return jedis.srandmember(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.srandmember(key, (int) count))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.srandmember(key, (int) count))); - return null; - } - return jedis.srandmember(key, (int) count); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public List sRandMember(byte[] key, long count) { - public Long sRem(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.srem(key, values))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.srem(key, values))); - return null; - } - return jedis.srem(key, values); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + if (count > Integer.MAX_VALUE) { + throw new IllegalArgumentException("Count must be less than Integer.MAX_VALUE for sRandMember in Jedis."); + } - public Set sUnion(byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.sunion(keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.sunion(keys))); - return null; - } - return jedis.sunion(keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.srandmember(key, (int) count))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.srandmember(key, (int) count))); + return null; + } + return jedis.srandmember(key, (int) count); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long sUnionStore(byte[] destKey, byte[]... keys) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.sunionstore(destKey, keys))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.sunionstore(destKey, keys))); - return null; - } - return jedis.sunionstore(destKey, keys); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long sRem(byte[] key, byte[]... values) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.srem(key, values))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.srem(key, values))); + return null; + } + return jedis.srem(key, values); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - // - // ZSet commands - // + public Set sUnion(byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.sunion(keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.sunion(keys))); + return null; + } + return jedis.sunion(keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean zAdd(byte[] key, double score, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zadd(key, score, value), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zadd(key, score, value), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.zadd(key, score, value)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long sUnionStore(byte[] destKey, byte[]... keys) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.sunionstore(destKey, keys))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.sunionstore(destKey, keys))); + return null; + } + return jedis.sunionstore(destKey, keys); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zAdd(byte[] key, Set tuples) { - if (isPipelined() || isQueueing()) { - throw new UnsupportedOperationException("zAdd of multiple fields not supported " + "in pipeline or transaction"); - } - Map args = zAddArgs(tuples); - try { - return jedis.zadd(key, args); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + // + // ZSet commands + // + + public Boolean zAdd(byte[] key, double score, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zadd(key, score, value), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zadd(key, score, value), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.zadd(key, score, value)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zCard(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zcard(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zcard(key))); - return null; - } - return jedis.zcard(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long zAdd(byte[] key, Set tuples) { + if (isPipelined() || isQueueing()) { + throw new UnsupportedOperationException("zAdd of multiple fields not supported " + "in pipeline or transaction"); + } + Map args = zAddArgs(tuples); + try { + return jedis.zadd(key, args); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zCount(byte[] key, double min, double max) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zcount(key, min, max))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zcount(key, min, max))); - return null; - } - return jedis.zcount(key, min, max); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long zCard(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zcard(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zcard(key))); + return null; + } + return jedis.zcard(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + public Long zCount(byte[] key, double min, double max) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zcount(key, min, max))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zcount(key, min, max))); + return null; + } + return jedis.zcount(key, min, max); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) */ - @Override - public Long zCount(byte[] key, Range range) { + @Override + public Long zCount(byte[] key, Range range) { - if (isPipelined() || isQueueing()) { - throw new UnsupportedOperationException( - "ZCOUNT not implemented in jedis for binary protocol on transaction and pipeline"); - } + if (isPipelined() || isQueueing()) { + throw new UnsupportedOperationException( + "ZCOUNT not implemented in jedis for binary protocol on transaction and pipeline"); + } - byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); - byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); + byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); + byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); - return jedis.zcount(key, min, max); - } + return jedis.zcount(key, min, max); + } - public Double zIncrBy(byte[] key, double increment, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zincrby(key, increment, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zincrby(key, increment, value))); - return null; - } - return jedis.zincrby(key, increment, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Double zIncrBy(byte[] key, double increment, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zincrby(key, increment, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zincrby(key, increment, value))); + return null; + } + return jedis.zincrby(key, increment, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - try { - ZParams zparams = new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name())); + public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + try { + ZParams zparams = new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name())); - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zinterstore(destKey, zparams, sets))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zinterstore(destKey, zparams, sets))); - return null; - } - return jedis.zinterstore(destKey, zparams, sets); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zinterstore(destKey, zparams, sets))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zinterstore(destKey, zparams, sets))); + return null; + } + return jedis.zinterstore(destKey, zparams, sets); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zInterStore(byte[] destKey, byte[]... sets) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zinterstore(destKey, sets))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zinterstore(destKey, sets))); - return null; - } - return jedis.zinterstore(destKey, sets); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long zInterStore(byte[] destKey, byte[]... sets) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zinterstore(destKey, sets))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zinterstore(destKey, sets))); + return null; + } + return jedis.zinterstore(destKey, sets); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Set zRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrange(key, start, end))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zrange(key, start, end))); - return null; - } - return jedis.zrange(key, start, end); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Set zRange(byte[] key, long start, long end) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zrange(key, start, end))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zrange(key, start, end))); + return null; + } + return jedis.zrange(key, start, end); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Set zRangeWithScores(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); - return null; - } - return JedisConverters.toTupleSet(jedis.zrangeWithScores(key, start, end)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Set zRangeWithScores(byte[] key, long start, long end) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); + return null; + } + return JedisConverters.toTupleSet(jedis.zrangeWithScores(key, start, end)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[]) */ - public Set zRangeByLex(byte[] key) { - return zRangeByLex(key, Range.unbounded()); - } + public Set zRangeByLex(byte[] key) { + return zRangeByLex(key, Range.unbounded()); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) */ - public Set zRangeByLex(byte[] key, Range range) { - return zRangeByLex(key, range, null); - } + public Set zRangeByLex(byte[] key, Range range) { + return zRangeByLex(key, range, null); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByLex(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ - public Set zRangeByLex(byte[] key, Range range, Limit limit) { + public Set zRangeByLex(byte[] key, Range range, Limit limit) { - Assert.notNull(range, "Range cannot be null for ZRANGEBYLEX."); + Assert.notNull(range, "Range cannot be null for ZRANGEBYLEX."); - byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES); - byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES); + byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES); + byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES); - try { - if (isPipelined()) { - if (limit != null) { - pipeline(new JedisResult(pipeline.zrangeByLex(key, min, max, limit.getOffset(), limit.getCount()))); - } else { - pipeline(new JedisResult(pipeline.zrangeByLex(key, min, max))); - } - return null; - } + try { + if (isPipelined()) { + if (limit != null) { + pipeline(new JedisResult(pipeline.zrangeByLex(key, min, max, limit.getOffset(), limit.getCount()))); + } else { + pipeline(new JedisResult(pipeline.zrangeByLex(key, min, max))); + } + return null; + } - if (isQueueing()) { - if (limit != null) { - transaction(new JedisResult(transaction.zrangeByLex(key, min, max, limit.getOffset(), limit.getCount()))); - } else { - transaction(new JedisResult(transaction.zrangeByLex(key, min, max))); - } - return null; - } + if (isQueueing()) { + if (limit != null) { + transaction(new JedisResult(transaction.zrangeByLex(key, min, max, limit.getOffset(), limit.getCount()))); + } else { + transaction(new JedisResult(transaction.zrangeByLex(key, min, max))); + } + return null; + } - if (limit != null) { - return jedis.zrangeByLex(key, min, max, limit.getOffset(), limit.getCount()); - } - return jedis.zrangeByLex(key, min, max); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + if (limit != null) { + return jedis.zrangeByLex(key, min, max, limit.getOffset(), limit.getCount()); + } + return jedis.zrangeByLex(key, min, max); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], double, double) */ - public Set zRangeByScore(byte[] key, double min, double max) { - return zRangeByScore(key, new Range().gte(min).lte(max)); - } + public Set zRangeByScore(byte[] key, double min, double max) { + return zRangeByScore(key, new Range().gte(min).lte(max)); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) */ - @Override - public Set zRangeByScore(byte[] key, Range range) { - return zRangeByScore(key, range, null); - } + @Override + public Set zRangeByScore(byte[] key, Range range) { + return zRangeByScore(key, range, null); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ - @Override - public Set zRangeByScore(byte[] key, Range range, Limit limit) { + @Override + public Set zRangeByScore(byte[] key, Range range, Limit limit) { - Assert.notNull(range, "Range cannot be null for ZRANGEBYSCORE."); + Assert.notNull(range, "Range cannot be null for ZRANGEBYSCORE."); - byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); - byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); + byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); + byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); - try { - if (isPipelined()) { - if (limit != null) { - pipeline(new JedisResult(pipeline.zrangeByScore(key, min, max, limit.getOffset(), limit.getCount()))); - } else { - pipeline(new JedisResult(pipeline.zrangeByScore(key, min, max))); - } - return null; - } + try { + if (isPipelined()) { + if (limit != null) { + pipeline(new JedisResult(pipeline.zrangeByScore(key, min, max, limit.getOffset(), limit.getCount()))); + } else { + pipeline(new JedisResult(pipeline.zrangeByScore(key, min, max))); + } + return null; + } - if (isQueueing()) { - if (limit != null) { - transaction(new JedisResult(transaction.zrangeByScore(key, min, max, limit.getOffset(), limit.getCount()))); - } else { - transaction(new JedisResult(transaction.zrangeByScore(key, min, max))); - } - return null; - } + if (isQueueing()) { + if (limit != null) { + transaction(new JedisResult(transaction.zrangeByScore(key, min, max, limit.getOffset(), limit.getCount()))); + } else { + transaction(new JedisResult(transaction.zrangeByScore(key, min, max))); + } + return null; + } - if (limit != null) { - return jedis.zrangeByScore(key, min, max, limit.getOffset(), limit.getCount()); - } - return jedis.zrangeByScore(key, min, max); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + if (limit != null) { + return jedis.zrangeByScore(key, min, max, limit.getOffset(), limit.getCount()); + } + return jedis.zrangeByScore(key, min, max); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScoreWithScores(byte[], double, double) */ - public Set zRangeByScoreWithScores(byte[] key, double min, double max) { - return zRangeByScoreWithScores(key, new Range().gte(min).lte(max)); - } + public Set zRangeByScoreWithScores(byte[] key, double min, double max) { + return zRangeByScoreWithScores(key, new Range().gte(min).lte(max)); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) */ - @Override - public Set zRangeByScoreWithScores(byte[] key, Range range) { - return zRangeByScoreWithScores(key, range, null); - } + @Override + public Set zRangeByScoreWithScores(byte[] key, Range range) { + return zRangeByScoreWithScores(key, range, null); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) - */ - @Override - public Set zRangeByScoreWithScores(byte[] key, Range range, Limit limit) { - - Assert.notNull(range, "Range cannot be null for ZRANGEBYSCOREWITHSCORES."); - - byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); - byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); - - try { - if (isPipelined()) { - if (limit != null) { - pipeline(new JedisResult( - pipeline.zrangeByScoreWithScores(key, min, max, limit.getOffset(), limit.getCount()), - JedisConverters.tupleSetToTupleSet())); - } else { - pipeline(new JedisResult(pipeline.zrangeByScoreWithScores(key, min, max), - JedisConverters.tupleSetToTupleSet())); - } - return null; - } + */ + @Override + public Set zRangeByScoreWithScores(byte[] key, Range range, Limit limit) { - if (isQueueing()) { - if (limit != null) { - transaction(new JedisResult(transaction.zrangeByScoreWithScores(key, min, max, limit.getOffset(), - limit.getCount()), JedisConverters.tupleSetToTupleSet())); - } else { - transaction(new JedisResult(transaction.zrangeByScoreWithScores(key, min, max), - JedisConverters.tupleSetToTupleSet())); - } - return null; - } + Assert.notNull(range, "Range cannot be null for ZRANGEBYSCOREWITHSCORES."); - if (limit != null) { - return JedisConverters.toTupleSet(jedis.zrangeByScoreWithScores(key, min, max, limit.getOffset(), - limit.getCount())); - } - return JedisConverters.toTupleSet(jedis.zrangeByScoreWithScores(key, min, max)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); + byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); - public Set zRevRangeWithScores(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrevrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zrevrangeWithScores(key, start, end), - JedisConverters.tupleSetToTupleSet())); - return null; - } - return JedisConverters.toTupleSet(jedis.zrevrangeWithScores(key, start, end)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } + try { + if (isPipelined()) { + if (limit != null) { + pipeline(new JedisResult( + pipeline.zrangeByScoreWithScores(key, min, max, limit.getOffset(), limit.getCount()), + JedisConverters.tupleSetToTupleSet())); + } else { + pipeline(new JedisResult(pipeline.zrangeByScoreWithScores(key, min, max), + JedisConverters.tupleSetToTupleSet())); + } + return null; + } - } + if (isQueueing()) { + if (limit != null) { + transaction(new JedisResult(transaction.zrangeByScoreWithScores(key, min, max, limit.getOffset(), + limit.getCount()), JedisConverters.tupleSetToTupleSet())); + } else { + transaction(new JedisResult(transaction.zrangeByScoreWithScores(key, min, max), + JedisConverters.tupleSetToTupleSet())); + } + return null; + } - /* + if (limit != null) { + return JedisConverters.toTupleSet(jedis.zrangeByScoreWithScores(key, min, max, limit.getOffset(), + limit.getCount())); + } + return JedisConverters.toTupleSet(jedis.zrangeByScoreWithScores(key, min, max)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + public Set zRevRangeWithScores(byte[] key, long start, long end) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zrevrangeWithScores(key, start, end), JedisConverters.tupleSetToTupleSet())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zrevrangeWithScores(key, start, end), + JedisConverters.tupleSetToTupleSet())); + return null; + } + return JedisConverters.toTupleSet(jedis.zrevrangeWithScores(key, start, end)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + + } + + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScore(byte[], double, double, long, long) */ - @Override - public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { + @Override + public Set zRangeByScore(byte[] key, double min, double max, long offset, long count) { - return zRangeByScore(key, new Range().gte(min).lte(max), - new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); - } + return zRangeByScore(key, new Range().gte(min).lte(max), + new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRangeByScoreWithScores(byte[], double, double, long, long) */ - @Override - public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { + @Override + public Set zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { - return zRangeByScoreWithScores(key, new Range().gte(min).lte(max), - new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); - } + return zRangeByScoreWithScores(key, new Range().gte(min).lte(max), + new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScore(byte[], double, double, long, long) */ - @Override - public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { + @Override + public Set zRevRangeByScore(byte[] key, double min, double max, long offset, long count) { - return zRevRangeByScore(key, new Range().gte(min).lte(max), new Limit().offset(Long.valueOf(offset).intValue()) - .count(Long.valueOf(count).intValue())); - } + return zRevRangeByScore(key, new Range().gte(min).lte(max), new Limit().offset(Long.valueOf(offset).intValue()) + .count(Long.valueOf(count).intValue())); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScore(byte[], double, double) */ - @Override - public Set zRevRangeByScore(byte[] key, double min, double max) { - return zRevRangeByScore(key, new Range().gte(min).lte(max)); - } + @Override + public Set zRevRangeByScore(byte[] key, double min, double max) { + return zRevRangeByScore(key, new Range().gte(min).lte(max)); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) */ - @Override - public Set zRevRangeByScore(byte[] key, Range range) { - return zRevRangeByScore(key, range, null); - } + @Override + public Set zRevRangeByScore(byte[] key, Range range) { + return zRevRangeByScore(key, range, null); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ - @Override - public Set zRevRangeByScore(byte[] key, Range range, Limit limit) { + @Override + public Set zRevRangeByScore(byte[] key, Range range, Limit limit) { - Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCORE."); + Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCORE."); - byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); - byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); + byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); + byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); - try { - if (isPipelined()) { - if (limit != null) { - pipeline(new JedisResult(pipeline.zrevrangeByScore(key, max, min, limit.getOffset(), limit.getCount()))); - } else { - pipeline(new JedisResult(pipeline.zrevrangeByScore(key, max, min))); - } - return null; - } + try { + if (isPipelined()) { + if (limit != null) { + pipeline(new JedisResult(pipeline.zrevrangeByScore(key, max, min, limit.getOffset(), limit.getCount()))); + } else { + pipeline(new JedisResult(pipeline.zrevrangeByScore(key, max, min))); + } + return null; + } - if (isQueueing()) { - if (limit != null) { - transaction(new JedisResult(transaction.zrevrangeByScore(key, max, min, limit.getOffset(), limit.getCount()))); - } else { - transaction(new JedisResult(transaction.zrevrangeByScore(key, max, min))); - } - return null; - } + if (isQueueing()) { + if (limit != null) { + transaction(new JedisResult(transaction.zrevrangeByScore(key, max, min, limit.getOffset(), limit.getCount()))); + } else { + transaction(new JedisResult(transaction.zrevrangeByScore(key, max, min))); + } + return null; + } - if (limit != null) { - return jedis.zrevrangeByScore(key, max, min, limit.getOffset(), limit.getCount()); - } - return jedis.zrevrangeByScore(key, max, min); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + if (limit != null) { + return jedis.zrevrangeByScore(key, max, min, limit.getOffset(), limit.getCount()); + } + return jedis.zrevrangeByScore(key, max, min); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScoreWithScores(byte[], double, double, long, long) */ - @Override - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { + @Override + public Set zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) { - return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max), - new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); - } + return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max), + new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue())); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) */ - @Override - public Set zRevRangeByScoreWithScores(byte[] key, Range range) { - return zRevRangeByScoreWithScores(key, range, null); - } + @Override + public Set zRevRangeByScoreWithScores(byte[] key, Range range) { + return zRevRangeByScoreWithScores(key, range, null); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScoreWithScores(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit) */ - @Override - public Set zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) { + @Override + public Set zRevRangeByScoreWithScores(byte[] key, Range range, Limit limit) { - Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCOREWITHSCORES."); + Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCOREWITHSCORES."); - byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); - byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); + byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); + byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); - try { - if (isPipelined()) { - if (limit != null) { - pipeline(new JedisResult(pipeline.zrevrangeByScoreWithScores(key, max, min, limit.getOffset(), - limit.getCount()), JedisConverters.tupleSetToTupleSet())); - } else { - pipeline(new JedisResult(pipeline.zrevrangeByScoreWithScores(key, max, min), - JedisConverters.tupleSetToTupleSet())); - } - return null; - } + try { + if (isPipelined()) { + if (limit != null) { + pipeline(new JedisResult(pipeline.zrevrangeByScoreWithScores(key, max, min, limit.getOffset(), + limit.getCount()), JedisConverters.tupleSetToTupleSet())); + } else { + pipeline(new JedisResult(pipeline.zrevrangeByScoreWithScores(key, max, min), + JedisConverters.tupleSetToTupleSet())); + } + return null; + } - if (isQueueing()) { - if (limit != null) { - transaction(new JedisResult(transaction.zrevrangeByScoreWithScores(key, max, min, limit.getOffset(), - limit.getCount()), JedisConverters.tupleSetToTupleSet())); - } else { - transaction(new JedisResult(transaction.zrevrangeByScoreWithScores(key, max, min), - JedisConverters.tupleSetToTupleSet())); - } - return null; - } + if (isQueueing()) { + if (limit != null) { + transaction(new JedisResult(transaction.zrevrangeByScoreWithScores(key, max, min, limit.getOffset(), + limit.getCount()), JedisConverters.tupleSetToTupleSet())); + } else { + transaction(new JedisResult(transaction.zrevrangeByScoreWithScores(key, max, min), + JedisConverters.tupleSetToTupleSet())); + } + return null; + } - if (limit != null) { - return JedisConverters.toTupleSet(jedis.zrevrangeByScoreWithScores(key, max, min, limit.getOffset(), - limit.getCount())); - } - return JedisConverters.toTupleSet(jedis.zrevrangeByScoreWithScores(key, max, min)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + if (limit != null) { + return JedisConverters.toTupleSet(jedis.zrevrangeByScoreWithScores(key, max, min, limit.getOffset(), + limit.getCount())); + } + return JedisConverters.toTupleSet(jedis.zrevrangeByScoreWithScores(key, max, min)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRevRangeByScoreWithScores(byte[], double, double) */ - public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { - return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max), null); - } + public Set zRevRangeByScoreWithScores(byte[] key, double min, double max) { + return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max), null); + } - public Long zRank(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrank(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zrank(key, value))); - return null; - } - return jedis.zrank(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long zRank(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zrank(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zrank(key, value))); + return null; + } + return jedis.zrank(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zRem(byte[] key, byte[]... values) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrem(key, values))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zrem(key, values))); - return null; - } - return jedis.zrem(key, values); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long zRem(byte[] key, byte[]... values) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zrem(key, values))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zrem(key, values))); + return null; + } + return jedis.zrem(key, values); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zRemRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zremrangeByRank(key, start, end))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zremrangeByRank(key, start, end))); - return null; - } - return jedis.zremrangeByRank(key, start, end); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long zRemRange(byte[] key, long start, long end) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zremrangeByRank(key, start, end))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zremrangeByRank(key, start, end))); + return null; + } + return jedis.zremrangeByRank(key, start, end); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRemRangeByScore(byte[], double, double) */ - @Override - public Long zRemRangeByScore(byte[] key, double min, double max) { - return zRemRangeByScore(key, new Range().gte(min).lte(max)); - } + @Override + public Long zRemRangeByScore(byte[] key, double min, double max) { + return zRemRangeByScore(key, new Range().gte(min).lte(max)); + } - /* + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisZSetCommands#zRemRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range) */ - @Override - public Long zRemRangeByScore(byte[] key, Range range) { + @Override + public Long zRemRangeByScore(byte[] key, Range range) { - Assert.notNull(range, "Range cannot be null for ZREMRANGEBYSCORE."); + Assert.notNull(range, "Range cannot be null for ZREMRANGEBYSCORE."); - byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); - byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); - - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zremrangeByScore(key, min, max))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zremrangeByScore(key, min, max))); - return null; - } - return jedis.zremrangeByScore(key, min, max); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES); + byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES); - public Set zRevRange(byte[] key, long start, long end) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrevrange(key, start, end))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zrevrange(key, start, end))); - return null; - } - return jedis.zrevrange(key, start, end); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zremrangeByScore(key, min, max))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zremrangeByScore(key, min, max))); + return null; + } + return jedis.zremrangeByScore(key, min, max); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zRevRank(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zrevrank(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zrevrank(key, value))); - return null; - } - return jedis.zrevrank(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Set zRevRange(byte[] key, long start, long end) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zrevrange(key, start, end))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zrevrange(key, start, end))); + return null; + } + return jedis.zrevrange(key, start, end); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Double zScore(byte[] key, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zscore(key, value))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zscore(key, value))); - return null; - } - return jedis.zscore(key, value); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long zRevRank(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zrevrank(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zrevrank(key, value))); + return null; + } + return jedis.zrevrank(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { - try { - ZParams zparams = new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name())); + public Double zScore(byte[] key, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zscore(key, value))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zscore(key, value))); + return null; + } + return jedis.zscore(key, value); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zunionstore(destKey, zparams, sets))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zunionstore(destKey, zparams, sets))); - return null; - } - return jedis.zunionstore(destKey, zparams, sets); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) { + try { + ZParams zparams = new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name())); - public Long zUnionStore(byte[] destKey, byte[]... sets) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.zunionstore(destKey, sets))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.zunionstore(destKey, sets))); - return null; - } - return jedis.zunionstore(destKey, sets); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zunionstore(destKey, zparams, sets))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zunionstore(destKey, zparams, sets))); + return null; + } + return jedis.zunionstore(destKey, zparams, sets); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - // - // Hash commands - // + public Long zUnionStore(byte[] destKey, byte[]... sets) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.zunionstore(destKey, sets))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.zunionstore(destKey, sets))); + return null; + } + return jedis.zunionstore(destKey, sets); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean hSet(byte[] key, byte[] field, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hset(key, field, value), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hset(key, field, value), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.hset(key, field, value)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + // + // Hash commands + // - public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hsetnx(key, field, value), JedisConverters.longToBoolean())); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hsetnx(key, field, value), JedisConverters.longToBoolean())); - return null; - } - return JedisConverters.toBoolean(jedis.hsetnx(key, field, value)); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean hSet(byte[] key, byte[] field, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hset(key, field, value), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hset(key, field, value), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.hset(key, field, value)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long hDel(byte[] key, byte[]... fields) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hdel(key, fields))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hdel(key, fields))); - return null; - } - return jedis.hdel(key, fields); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean hSetNX(byte[] key, byte[] field, byte[] value) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hsetnx(key, field, value), JedisConverters.longToBoolean())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hsetnx(key, field, value), JedisConverters.longToBoolean())); + return null; + } + return JedisConverters.toBoolean(jedis.hsetnx(key, field, value)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Boolean hExists(byte[] key, byte[] field) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hexists(key, field))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hexists(key, field))); - return null; - } - return jedis.hexists(key, field); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long hDel(byte[] key, byte[]... fields) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hdel(key, fields))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hdel(key, fields))); + return null; + } + return jedis.hdel(key, fields); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public byte[] hGet(byte[] key, byte[] field) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hget(key, field))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hget(key, field))); - return null; - } - return jedis.hget(key, field); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Boolean hExists(byte[] key, byte[] field) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hexists(key, field))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hexists(key, field))); + return null; + } + return jedis.hexists(key, field); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Map hGetAll(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hgetAll(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hgetAll(key))); - return null; - } - return jedis.hgetAll(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public byte[] hGet(byte[] key, byte[] field) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hget(key, field))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hget(key, field))); + return null; + } + return jedis.hget(key, field); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long hIncrBy(byte[] key, byte[] field, long delta) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hincrBy(key, field, delta))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hincrBy(key, field, delta))); - return null; - } - return jedis.hincrBy(key, field, delta); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Map hGetAll(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hgetAll(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hgetAll(key))); + return null; + } + return jedis.hgetAll(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Double hIncrBy(byte[] key, byte[] field, double delta) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hincrByFloat(key, field, delta))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hincrByFloat(key, field, delta))); - return null; - } - return jedis.hincrByFloat(key, field, delta); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long hIncrBy(byte[] key, byte[] field, long delta) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hincrBy(key, field, delta))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hincrBy(key, field, delta))); + return null; + } + return jedis.hincrBy(key, field, delta); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + public Double hIncrBy(byte[] key, byte[] field, double delta) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hincrByFloat(key, field, delta))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hincrByFloat(key, field, delta))); + return null; + } + return jedis.hincrByFloat(key, field, delta); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Set hKeys(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hkeys(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hkeys(key))); - return null; - } - return jedis.hkeys(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Set hKeys(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hkeys(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hkeys(key))); + return null; + } + return jedis.hkeys(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Long hLen(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hlen(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hlen(key))); - return null; - } - return jedis.hlen(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long hLen(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hlen(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hlen(key))); + return null; + } + return jedis.hlen(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public List hMGet(byte[] key, byte[]... fields) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hmget(key, fields))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hmget(key, fields))); - return null; - } - return jedis.hmget(key, fields); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public List hMGet(byte[] key, byte[]... fields) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hmget(key, fields))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hmget(key, fields))); + return null; + } + return jedis.hmget(key, fields); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void hMSet(byte[] key, Map tuple) { - try { - if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.hmset(key, tuple))); - return; - } - if (isQueueing()) { - transaction(new JedisStatusResult(transaction.hmset(key, tuple))); - return; - } - jedis.hmset(key, tuple); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void hMSet(byte[] key, Map tuple) { + try { + if (isPipelined()) { + pipeline(new JedisStatusResult(pipeline.hmset(key, tuple))); + return; + } + if (isQueueing()) { + transaction(new JedisStatusResult(transaction.hmset(key, tuple))); + return; + } + jedis.hmset(key, tuple); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public List hVals(byte[] key) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.hvals(key))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.hvals(key))); - return null; - } - return jedis.hvals(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public List hVals(byte[] key) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.hvals(key))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.hvals(key))); + return null; + } + return jedis.hvals(key); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - // - // Pub/Sub functionality - // + // + // Pub/Sub functionality + // - public Long publish(byte[] channel, byte[] message) { - try { - if (isPipelined()) { - pipeline(new JedisResult(pipeline.publish(channel, message))); - return null; - } - if (isQueueing()) { - transaction(new JedisResult(transaction.publish(channel, message))); - return null; - } - return jedis.publish(channel, message); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public Long publish(byte[] channel, byte[] message) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.publish(channel, message))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.publish(channel, message))); + return null; + } + return jedis.publish(channel, message); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public Subscription getSubscription() { - return subscription; - } + public Subscription getSubscription() { + return subscription; + } - public boolean isSubscribed() { - return (subscription != null && subscription.isAlive()); - } + public boolean isSubscribed() { + return (subscription != null && subscription.isAlive()); + } - public void pSubscribe(MessageListener listener, byte[]... patterns) { - if (isSubscribed()) { - throw new RedisSubscribedConnectionException( - "Connection already subscribed; use the connection Subscription to cancel or add new channels"); - } - if (isQueueing()) { - throw new UnsupportedOperationException(); - } - if (isPipelined()) { - throw new UnsupportedOperationException(); - } + public void pSubscribe(MessageListener listener, byte[]... patterns) { + if (isSubscribed()) { + throw new RedisSubscribedConnectionException( + "Connection already subscribed; use the connection Subscription to cancel or add new channels"); + } + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + if (isPipelined()) { + throw new UnsupportedOperationException(); + } - try { - BinaryJedisPubSub jedisPubSub = new JedisMessageListener(listener); + try { + BinaryJedisPubSub jedisPubSub = new JedisMessageListener(listener); - subscription = new JedisSubscription(listener, jedisPubSub, null, patterns); - jedis.psubscribe(jedisPubSub, patterns); + subscription = new JedisSubscription(listener, jedisPubSub, null, patterns); + jedis.psubscribe(jedisPubSub, patterns); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - public void subscribe(MessageListener listener, byte[]... channels) { - if (isSubscribed()) { - throw new RedisSubscribedConnectionException( - "Connection already subscribed; use the connection Subscription to cancel or add new channels"); - } + public void subscribe(MessageListener listener, byte[]... channels) { + if (isSubscribed()) { + throw new RedisSubscribedConnectionException( + "Connection already subscribed; use the connection Subscription to cancel or add new channels"); + } - if (isQueueing()) { - throw new UnsupportedOperationException(); - } - if (isPipelined()) { - throw new UnsupportedOperationException(); - } + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + if (isPipelined()) { + throw new UnsupportedOperationException(); + } - try { - BinaryJedisPubSub jedisPubSub = new JedisMessageListener(listener); + try { + BinaryJedisPubSub jedisPubSub = new JedisMessageListener(listener); - subscription = new JedisSubscription(listener, jedisPubSub, channels, null); - jedis.subscribe(jedisPubSub, channels); + subscription = new JedisSubscription(listener, jedisPubSub, channels, null); + jedis.subscribe(jedisPubSub, channels); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } // // Geo commands // - - public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member){ + @Override + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) { try { if (isPipelined()) { pipeline(new JedisResult(pipeline.geoadd(key, longitude, latitude, member))); @@ -3099,6 +3077,178 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) } } + @Override + public Long geoadd(byte[] key, Map memberCoordinateMap){ + try { + Map redisGeoCoordinateMap = new HashMap(); + for(byte[] mapKey : memberCoordinateMap.keySet()){ + redisGeoCoordinateMap.put(mapKey, JedisConverters.toGeoCoordinate(memberCoordinateMap.get(mapKey))); + } + + if (isPipelined()) { + pipeline(new JedisResult(pipeline.geoadd(key, redisGeoCoordinateMap))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.geoadd(key, redisGeoCoordinateMap))); + return null; + } + + return jedis.geoadd(key, redisGeoCoordinateMap); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + + @Override + public Double geodist(byte[] key, byte[] member1, byte[] member2) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.geodist(key, member1, member2))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.geodist(key, member1, member2))); + return null; + } + + return jedis.geodist(key, member1, member2); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public Double geodist(byte[] key, byte[] member1, byte[] member2, org.springframework.data.redis.core.GeoUnit unit) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.geodist(key, member1, member2))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.geodist(key, member1, member2))); + return null; + } + + return jedis.geodist(key, member1, member2); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List geohash(byte[] key, byte[]... members) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.geohash(key, members))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.geohash(key, members))); + return null; + } + + return jedis.geohash(key, members); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List geopos(byte[] key, byte[]... members) { + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.geopos(key, members))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.geopos(key, members))); + return null; + } + + return JedisConverters.geoCoordinateListToGeoCoordinateList().convert(jedis.geopos(key, members)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + +// @Override +// public List georadius(byte[] key, double longitude, double latitude, +// double radius, GeoUnit unit) { +// try { +// if (isPipelined()) { +// pipeline(new JedisResult(pipeline.georadius(key, longitude, latitude, radius, unit))); +// return null; +// } +// if (isQueueing()) { +// transaction(new JedisResult(transaction.georadius(key, longitude, latitude, radius, unit))); +// return null; +// } +// +// return jedis.georadius(key, longitude, latitude, radius, unit); +// } catch (Exception ex) { +// throw convertJedisAccessException(ex); +// } +// } +// +// @Override +// public List georadius(byte[] key, double longitude, double latitude, +// double radius, GeoUnit unit, GeoRadiusParam param) { +// try { +// if (isPipelined()) { +// pipeline(new JedisResult(pipeline.georadius(key, longitude, latitude, radius, unit, param))); +// return null; +// } +// if (isQueueing()) { +// transaction(new JedisResult(transaction.georadius(key, longitude, latitude, radius, unit, param))); +// return null; +// } +// +// return jedis.georadius(key, longitude, latitude, radius, unit, param); +// } catch (Exception ex) { +// throw convertJedisAccessException(ex); +// } +// } +// +// @Override +// public List georadiusByMember(byte[] key, byte[] member, double radius, +// GeoUnit unit) { +// try { +// if (isPipelined()) { +// pipeline(new JedisResult(pipeline.georadiusByMember(key, member, radius, unit))); +// return null; +// } +// if (isQueueing()) { +// transaction(new JedisResult(transaction.georadiusByMember(key, member, radius, unit))); +// return null; +// } +// +// return jedis.georadiusByMember(key, member, radius, unit); +// } catch (Exception ex) { +// throw convertJedisAccessException(ex); +// } +// } +// +// @Override +// public List georadiusByMember(byte[] key, byte[] member, double radius, +// GeoUnit unit, GeoRadiusParam param) { +// +// try { +// if (isPipelined()) { +// pipeline(new JedisResult(pipeline.georadiusByMember(key, member, radius, unit, param))); +// return null; +// } +// if (isQueueing()) { +// transaction(new JedisResult(transaction.georadiusByMember(key, member, radius, unit, param))); +// return null; +// } +// return jedis.georadiusByMember(key, member, radius, unit, param); +// } catch (Exception ex) { +// throw convertJedisAccessException(ex); +// } +// } + // // Scripting commands diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java index c241c60a6c..a881a24bb1 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java @@ -42,6 +42,8 @@ import org.springframework.data.redis.connection.convert.MapConverter; import org.springframework.data.redis.connection.convert.SetConverter; import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter; +import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; @@ -79,6 +81,8 @@ abstract public class JedisConverters extends Converters { private static final Converter OBJECT_TO_CLUSTER_NODE_CONVERTER; private static final Converter EXPIRATION_TO_COMMAND_OPTION_CONVERTER; private static final Converter SET_OPTION_TO_COMMAND_OPTION_CONVERTER; + private static final Converter GEO_COORDINATE_CONVERTER; + private static final ListConverter GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; public static final byte[] PLUS_BYTES; public static final byte[] MINUS_BYTES; @@ -165,6 +169,14 @@ public byte[] convert(SetOption source) { } }; + + GEO_COORDINATE_CONVERTER = new Converter() { + @Override + public GeoCoordinate convert(redis.clients.jedis.GeoCoordinate geoCoordinate) { + return geoCoordinate != null ? new GeoCoordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()) : null; + } + }; + GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST = new ListConverter(GEO_COORDINATE_CONVERTER); } public static Converter stringToBytes() { @@ -201,6 +213,8 @@ public static Converter exceptionConverter() { return EXCEPTION_CONVERTER; } + public static ListConverter geoCoordinateListToGeoCoordinateList() { return GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; } + public static String[] toStrings(byte[][] source) { String[] result = new String[source.length]; for (int i = 0; i < source.length; i++) { @@ -456,4 +470,22 @@ public static ScanParams toScanParams(ScanOptions options) { return sp; } + public static redis.clients.jedis.GeoUnit toGeoUnit(GeoUnit geoUnit){ + switch (geoUnit){ + case Meters: return redis.clients.jedis.GeoUnit.M; + case KiloMeters: return redis.clients.jedis.GeoUnit.KM; + case Miles: return redis.clients.jedis.GeoUnit.M; + case Feet: return redis.clients.jedis.GeoUnit.FT; + default: throw new IllegalArgumentException("geoUnit not supported"); + } + } + + public static redis.clients.jedis.GeoCoordinate toGeoCoordinate(GeoCoordinate geoCoordinate){ + return new redis.clients.jedis.GeoCoordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()); + } + +// public static redis.clients.jedis.params.geo.GeoRadiusParam toGeoRadiusParam(GeoRadiusParam geoRadiusParam){ +// redis.clients.jedis.params.geo.GeoRadiusParam param = new redis.clients.jedis.params.geo.GeoRadiusParam(); +// +// } } 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 e739f25dc7..b414a34581 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 @@ -46,6 +46,7 @@ import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; import org.springframework.data.redis.core.Cursor; +import org.springframework.data.redis.core.GeoCoordinate; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; @@ -1200,6 +1201,32 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) throw new UnsupportedOperationException(); } + @Override + public Long geoadd(byte[] key, Map memberCoordinateMap){ + throw new UnsupportedOperationException(); + } + + + @Override + public Double geodist(byte[] key, byte[] member1, byte[] member2) { + throw new UnsupportedOperationException(); + } + + @Override + public Double geodist(byte[] key, byte[] member1, byte[] member2, org.springframework.data.redis.core.GeoUnit unit) { + throw new UnsupportedOperationException(); + } + + @Override + public List geohash(byte[] key, byte[]... members) { + throw new UnsupportedOperationException(); + } + + @Override + public List geopos(byte[] key, byte[]... members) { + throw new UnsupportedOperationException(); + } + // // Scripting commands diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index 5018fa6abb..ecb63f67c9 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -56,12 +56,7 @@ import org.springframework.data.redis.connection.Subscription; import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.connection.convert.TransactionResultConverter; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.KeyBoundCursor; -import org.springframework.data.redis.core.RedisCommand; -import org.springframework.data.redis.core.ScanCursor; -import org.springframework.data.redis.core.ScanIteration; -import org.springframework.data.redis.core.ScanOptions; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; @@ -3099,6 +3094,153 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) } } + @Override + public Long geoadd(byte[] key, Map memberCoordinateMap){ + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().geoadd(key, memberCoordinateMap))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().geoadd(key, memberCoordinateMap))); + return null; + } + return getConnection().geoadd(key, memberCoordinateMap); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + + @Override + public Double geodist(byte[] key, byte[] member1, byte[] member2) { + throw new UnsupportedOperationException("Lettuce does not support this method without unit parameter passed"); + } + + @Override + public Double geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().geodist(key, member1, member2, unit))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().geodist(key, longitude, latitude, member))); + return null; + } + return getConnection().geodist(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List geohash(byte[] key, byte[]... members) { + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().geohash(key, longitude, latitude, member))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().geohash(key, longitude, latitude, member))); + return null; + } + return getConnection().geohash(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List geopos(byte[] key, byte[]... members) { + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().geopos(key, longitude, latitude, member))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().geopos(key, longitude, latitude, member))); + return null; + } + return getConnection().geopos(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, + double radius, GeoUnit unit) { + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, member))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, member))); + return null; + } + return getConnection().georadius(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, + double radius, GeoUnit unit, GeoRadiusParam param) { + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, member))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, member))); + return null; + } + return getConnection().georadius(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, + GeoUnit unit) { + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().georadiusByMember(key, longitude, latitude, member))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().georadiusByMember(key, longitude, latitude, member))); + return null; + } + return getConnection().georadiusByMember(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, + GeoUnit unit, GeoRadiusParam param) { + + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().georadiusByMember(key, longitude, latitude, member))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().georadiusByMember(key, longitude, latitude, member))); + return null; + } + return getConnection().georadiusByMember(key, longitude, latitude, member); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisServerCommands#time() diff --git a/src/main/java/org/springframework/data/redis/core/GeoCoordinate.java b/src/main/java/org/springframework/data/redis/core/GeoCoordinate.java new file mode 100644 index 0000000000..5049059512 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/GeoCoordinate.java @@ -0,0 +1,22 @@ +package org.springframework.data.redis.core; + +/** + * Created by ndivadkar on 3/29/16. + */ +public class GeoCoordinate { + private double longitude; + private double latitude; + + public GeoCoordinate(double longitude, double latitude) { + this.longitude = longitude; + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public double getLatitude() { + return latitude; + } +} diff --git a/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java b/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java new file mode 100644 index 0000000000..5ad9fa7d9f --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java @@ -0,0 +1,64 @@ +package org.springframework.data.redis.core; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by ndivadkar on 3/29/16. + */ +public class GeoRadiusParam { + private static final String WITHCOORD = "withcoord"; + private static final String WITHDIST = "withdist"; + private static final String ASC = "asc"; + private static final String DESC = "desc"; + private static final String COUNT = "count"; + + private Map params; + private GeoRadiusParam() { + } + + public static GeoRadiusParam geoRadiusParam() { + return new GeoRadiusParam(); + } + + public GeoRadiusParam withCoord() { + addParam(WITHCOORD); + return this; + } + + public GeoRadiusParam withDist() { + addParam(WITHDIST); + return this; + } + + public GeoRadiusParam sortAscending() { + addParam(ASC); + return this; + } + + public GeoRadiusParam sortDescending() { + addParam(DESC); + return this; + } + + public GeoRadiusParam count(int count) { + if (count > 0) { + addParam(COUNT, count); + } + return this; + } + + protected void addParam(String name, Object value) { + if (params == null) { + params = new HashMap(); + } + params.put(name, value); + } + + protected void addParam(String name) { + if (params == null) { + params = new HashMap(); + } + params.put(name, null); + } +} diff --git a/src/main/java/org/springframework/data/redis/core/GeoUnit.java b/src/main/java/org/springframework/data/redis/core/GeoUnit.java new file mode 100644 index 0000000000..d31918d4a5 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/GeoUnit.java @@ -0,0 +1,11 @@ +package org.springframework.data.redis.core; + +/** + * Created by ndivadkar on 3/29/16. + */ +public enum GeoUnit { + Meters, + KiloMeters, + Miles, + Feet; +} From 40bed11cc8eb9c660aedbc11653e37fe91549a6c Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Wed, 30 Mar 2016 23:58:38 -0700 Subject: [PATCH 06/15] DATAREDIS-438 Add support for geo commands. Adding support for geoAdd, geoDist, geoPos and geoHash --- .../DefaultStringRedisConnection.java | 61 ++++-- .../redis/connection/RedisGeoCommands.java | 10 +- .../jedis/JedisClusterConnection.java | 122 +++++------ .../connection/jedis/JedisConnection.java | 21 +- .../connection/jredis/JredisConnection.java | 10 +- .../connection/lettuce/LettuceConnection.java | 202 ++++++++---------- .../connection/lettuce/LettuceConverters.java | 37 +++- .../redis/connection/srp/SrpConnection.java | 27 +++ .../data/redis/core/BoundGeoOperations.java | 13 ++ .../redis/core/DefaultBoundGeoOperations.java | 27 +++ .../data/redis/core/DefaultGeoOperations.java | 75 +++++++ .../data/redis/core/GeoOperations.java | 13 ++ .../connection/RedisConnectionUnitTests.java | 27 +++ .../redis/core/DefaultGeoOperationsTests.java | 13 ++ 14 files changed, 439 insertions(+), 219 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 18d3dab368..93cb42f66d 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -15,16 +15,8 @@ */ package org.springframework.data.redis.connection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Properties; -import java.util.Queue; -import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -33,9 +25,7 @@ import org.springframework.data.redis.connection.convert.ListConverter; import org.springframework.data.redis.connection.convert.MapConverter; import org.springframework.data.redis.connection.convert.SetConverter; -import org.springframework.data.redis.core.ConvertingCursor; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.ScanOptions; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.data.redis.serializer.RedisSerializer; @@ -288,7 +278,52 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) return result; } - public byte[] get(byte[] key) { + @Override + public Long geoAdd(byte[] key, Map memberCoordinateMap) { + Long result = delegate.geoAdd(key, memberCoordinateMap); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public Double geoDist(byte[] key, byte[] member1, byte[] member2) { + Double result = delegate.geoDist(key, member1, member2); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + Double result = delegate.geoDist(key, member1, member2, unit); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List geoHash(byte[] key, byte[]... members) { + List result = delegate.geoHash(key, members); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List geoPos(byte[] key, byte[]... members) { + List result = delegate.geoPos(key, members); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + public byte[] get(byte[] key) { byte[] result = delegate.get(key); if (isFutureConversion()) { addResultConverter(identityConverter); diff --git a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java index 5d5e790244..d30bd9214c 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java @@ -43,15 +43,15 @@ public interface RedisGeoCommands { */ Long geoAdd(byte[] key, double longitude, double latitude, byte[] member); - Long geoadd(byte[] key, Map memberCoordinateMap); + Long geoAdd(byte[] key, Map memberCoordinateMap); - Double geodist(byte[] key, byte[] member1, byte[] member2); + Double geoDist(byte[] key, byte[] member1, byte[] member2); - Double geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit); + Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit); - List geohash(byte[] key, byte[]... members); + List geoHash(byte[] key, byte[]... members); - List geopos(byte[] key, byte[]... members); + List geoPos(byte[] key, byte[]... members); // List georadius(byte[] key, double longitude, double latitude, // double radius, GeoUnit unit); diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java index 6b31337dfe..8e7a9436ff 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java @@ -15,19 +15,8 @@ */ package org.springframework.data.redis.connection.jedis; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.Properties; -import java.util.Random; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.springframework.beans.DirectFieldAccessor; @@ -59,10 +48,7 @@ import org.springframework.data.redis.connection.Subscription; import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.connection.util.ByteArraySet; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.ScanCursor; -import org.springframework.data.redis.core.ScanIteration; -import org.springframework.data.redis.core.ScanOptions; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.data.redis.util.ByteUtils; @@ -71,7 +57,8 @@ import org.springframework.util.ObjectUtils; import redis.clients.jedis.*; -import redis.clients.jedis.params.geo.GeoRadiusParam; +import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.GeoUnit; /** * {@link RedisClusterConnection} implementation on top of {@link JedisCluster}.
@@ -2517,9 +2504,13 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) } @Override - public Long geoadd(byte[] key, Map memberCoordinateMap){ + public Long geoAdd(byte[] key, Map memberCoordinateMap) { + Map redisGeoCoordinateMap = new HashMap(); + for(byte[] mapKey : memberCoordinateMap.keySet()){ + redisGeoCoordinateMap.put(mapKey, JedisConverters.toGeoCoordinate(memberCoordinateMap.get(mapKey))); + } try { - return cluster.geoadd(key, memberCoordinateMap); + return cluster.geoadd(key, redisGeoCoordinateMap); } catch (Exception ex) { throw convertJedisAccessException(ex); } @@ -2527,7 +2518,7 @@ public Long geoadd(byte[] key, Map memberCoordinateMap){ @Override - public Double geodist(byte[] key, byte[] member1, byte[] member2) { + public Double geoDist(byte[] key, byte[] member1, byte[] member2) { try { return cluster.geodist(key, member1, member2); } catch (Exception ex) { @@ -2536,16 +2527,17 @@ public Double geodist(byte[] key, byte[] member1, byte[] member2) { } @Override - public Double geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + public Double geoDist(byte[] key, byte[] member1, byte[] member2, org.springframework.data.redis.core.GeoUnit unit) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); try { - return cluster.geodist(key, member1, member2, unit); + return cluster.geodist(key, member1, member2, geoUnit); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public List geohash(byte[] key, byte[]... members) { + public List geoHash(byte[] key, byte[]... members) { try { return cluster.geohash(key, members); } catch (Exception ex) { @@ -2554,54 +2546,54 @@ public List geohash(byte[] key, byte[]... members) { } @Override - public List geopos(byte[] key, byte[]... members) { - try { - return cluster.geopos(key, members); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - @Override - public List georadius(byte[] key, double longitude, double latitude, - double radius, GeoUnit unit) { - try { - return cluster.georadius(key, longitude, latitude, radius, unit); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - @Override - public List georadius(byte[] key, double longitude, double latitude, - double radius, GeoUnit unit, GeoRadiusParam param) { + public List geoPos(byte[] key, byte[]... members) { try { - return cluster.georadius(key, longitude, latitude, radius, unit, param); + return JedisConverters.geoCoordinateListToGeoCoordinateList().convert(cluster.geopos(key, members)); } catch (Exception ex) { throw convertJedisAccessException(ex); } } - @Override - public List georadiusByMember(byte[] key, byte[] member, double radius, - GeoUnit unit) { - try { - return cluster.georadiusByMember(key, member, radius, unit); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - - @Override - public List georadiusByMember(byte[] key, byte[] member, double radius, - GeoUnit unit, GeoRadiusParam param) { - - try { - return cluster.georadiusByMember(key, member, radius, unit, param); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } +// @Override +// public List georadius(byte[] key, double longitude, double latitude, +// double radius, GeoUnit unit) { +// try { +// return cluster.georadius(key, longitude, latitude, radius, unit); +// } catch (Exception ex) { +// throw convertJedisAccessException(ex); +// } +// } +// +// @Override +// public List georadius(byte[] key, double longitude, double latitude, +// double radius, GeoUnit unit, GeoRadiusParam param) { +// try { +// return cluster.georadius(key, longitude, latitude, radius, unit, param); +// } catch (Exception ex) { +// throw convertJedisAccessException(ex); +// } +// } +// +// @Override +// public List georadiusByMember(byte[] key, byte[] member, double radius, +// GeoUnit unit) { +// try { +// return cluster.georadiusByMember(key, member, radius, unit); +// } catch (Exception ex) { +// throw convertJedisAccessException(ex); +// } +// } +// +// @Override +// public List georadiusByMember(byte[] key, byte[] member, double radius, +// GeoUnit unit, GeoRadiusParam param) { +// +// try { +// return cluster.georadiusByMember(key, member, radius, unit, param); +// } catch (Exception ex) { +// throw convertJedisAccessException(ex); +// } +// } /* 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 d8a499b5e8..7cc9cdafcb 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 @@ -3078,7 +3078,7 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) } @Override - public Long geoadd(byte[] key, Map memberCoordinateMap){ + public Long geoAdd(byte[] key, Map memberCoordinateMap){ try { Map redisGeoCoordinateMap = new HashMap(); for(byte[] mapKey : memberCoordinateMap.keySet()){ @@ -3102,7 +3102,7 @@ public Long geoadd(byte[] key, Map memberCoordinateMap){ @Override - public Double geodist(byte[] key, byte[] member1, byte[] member2) { + public Double geoDist(byte[] key, byte[] member1, byte[] member2) { try { if (isPipelined()) { pipeline(new JedisResult(pipeline.geodist(key, member1, member2))); @@ -3120,25 +3120,26 @@ public Double geodist(byte[] key, byte[] member1, byte[] member2) { } @Override - public Double geodist(byte[] key, byte[] member1, byte[] member2, org.springframework.data.redis.core.GeoUnit unit) { + public Double geoDist(byte[] key, byte[] member1, byte[] member2, org.springframework.data.redis.core.GeoUnit unit) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.geodist(key, member1, member2))); + pipeline(new JedisResult(pipeline.geodist(key, member1, member2, geoUnit))); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.geodist(key, member1, member2))); + transaction(new JedisResult(transaction.geodist(key, member1, member2, geoUnit))); return null; } - return jedis.geodist(key, member1, member2); + return jedis.geodist(key, member1, member2, geoUnit); } catch (Exception ex) { throw convertJedisAccessException(ex); } } @Override - public List geohash(byte[] key, byte[]... members) { + public List geoHash(byte[] key, byte[]... members) { try { if (isPipelined()) { pipeline(new JedisResult(pipeline.geohash(key, members))); @@ -3156,14 +3157,14 @@ public List geohash(byte[] key, byte[]... members) { } @Override - public List geopos(byte[] key, byte[]... members) { + public List geoPos(byte[] key, byte[]... members) { try { if (isPipelined()) { - pipeline(new JedisResult(pipeline.geopos(key, members))); + pipeline(new JedisResult(pipeline.geopos(key, members), JedisConverters.geoCoordinateListToGeoCoordinateList())); return null; } if (isQueueing()) { - transaction(new JedisResult(transaction.geopos(key, members))); + transaction(new JedisResult(transaction.geopos(key, members), JedisConverters.geoCoordinateListToGeoCoordinateList())); return null; } 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 b414a34581..f7dd92fcb4 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 @@ -1202,28 +1202,28 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) } @Override - public Long geoadd(byte[] key, Map memberCoordinateMap){ + public Long geoAdd(byte[] key, Map memberCoordinateMap){ throw new UnsupportedOperationException(); } @Override - public Double geodist(byte[] key, byte[] member1, byte[] member2) { + public Double geoDist(byte[] key, byte[] member1, byte[] member2) { throw new UnsupportedOperationException(); } @Override - public Double geodist(byte[] key, byte[] member1, byte[] member2, org.springframework.data.redis.core.GeoUnit unit) { + public Double geoDist(byte[] key, byte[] member1, byte[] member2, org.springframework.data.redis.core.GeoUnit unit) { throw new UnsupportedOperationException(); } @Override - public List geohash(byte[] key, byte[]... members) { + public List geoHash(byte[] key, byte[]... members) { throw new UnsupportedOperationException(); } @Override - public List geopos(byte[] key, byte[]... members) { + public List geoPos(byte[] key, byte[]... members) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index ecb63f67c9..fe88a0683e 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -35,6 +35,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import com.lambdaworks.redis.*; import org.springframework.beans.BeanUtils; import org.springframework.core.convert.converter.Converter; import org.springframework.dao.DataAccessException; @@ -57,6 +58,7 @@ import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.connection.convert.TransactionResultConverter; import org.springframework.data.redis.core.*; +import org.springframework.data.redis.core.ScanCursor; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; @@ -64,25 +66,6 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; -import com.lambdaworks.redis.AbstractRedisClient; -import com.lambdaworks.redis.KeyScanCursor; -import com.lambdaworks.redis.LettuceFutures; -import com.lambdaworks.redis.MapScanCursor; -import com.lambdaworks.redis.RedisAsyncConnection; -import com.lambdaworks.redis.RedisAsyncConnectionImpl; -import com.lambdaworks.redis.RedisChannelHandler; -import com.lambdaworks.redis.RedisClient; -import com.lambdaworks.redis.RedisClusterConnection; -import com.lambdaworks.redis.RedisConnection; -import com.lambdaworks.redis.RedisException; -import com.lambdaworks.redis.RedisSentinelAsyncConnection; -import com.lambdaworks.redis.RedisURI; -import com.lambdaworks.redis.ScanArgs; -import com.lambdaworks.redis.ScoredValue; -import com.lambdaworks.redis.ScoredValueScanCursor; -import com.lambdaworks.redis.SortArgs; -import com.lambdaworks.redis.ValueScanCursor; -import com.lambdaworks.redis.ZStoreArgs; import com.lambdaworks.redis.codec.RedisCodec; import com.lambdaworks.redis.output.BooleanOutput; import com.lambdaworks.redis.output.ByteArrayOutput; @@ -3095,7 +3078,7 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) } @Override - public Long geoadd(byte[] key, Map memberCoordinateMap){ + public Long geoAdd(byte[] key, Map memberCoordinateMap){ try { if (isPipelined()) { pipeline(new LettuceResult(getAsyncConnection().geoadd(key, memberCoordinateMap))); @@ -3113,133 +3096,122 @@ public Long geoadd(byte[] key, Map memberCoordinateMap){ @Override - public Double geodist(byte[] key, byte[] member1, byte[] member2) { + public Double geoDist(byte[] key, byte[] member1, byte[] member2) { throw new UnsupportedOperationException("Lettuce does not support this method without unit parameter passed"); } @Override - public Double geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + public Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit); try { if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().geodist(key, member1, member2, unit))); + pipeline(new LettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit))); return null; } if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().geodist(key, longitude, latitude, member))); + transaction(new LettuceTxResult(getConnection().geodist(key, member1, member2, geoUnit))); return null; } - return getConnection().geodist(key, longitude, latitude, member); + return getConnection().geodist(key, member1, member2, geoUnit); } catch (Exception ex) { throw convertLettuceAccessException(ex); } } @Override - public List geohash(byte[] key, byte[]... members) { - try { - if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().geohash(key, longitude, latitude, member))); - return null; - } - if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().geohash(key, longitude, latitude, member))); - return null; - } - return getConnection().geohash(key, longitude, latitude, member); - } catch (Exception ex) { - throw convertLettuceAccessException(ex); - } - } - - @Override - public List geopos(byte[] key, byte[]... members) { - try { - if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().geopos(key, longitude, latitude, member))); - return null; - } - if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().geopos(key, longitude, latitude, member))); - return null; - } - return getConnection().geopos(key, longitude, latitude, member); - } catch (Exception ex) { - throw convertLettuceAccessException(ex); - } - } - - @Override - public List georadius(byte[] key, double longitude, double latitude, - double radius, GeoUnit unit) { - try { - if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, member))); - return null; - } - if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, member))); - return null; - } - return getConnection().georadius(key, longitude, latitude, member); - } catch (Exception ex) { - throw convertLettuceAccessException(ex); - } + public List geoHash(byte[] key, byte[]... members) { + throw new UnsupportedOperationException(); } @Override - public List georadius(byte[] key, double longitude, double latitude, - double radius, GeoUnit unit, GeoRadiusParam param) { + public List geoPos(byte[] key, byte[]... members) { try { if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, member))); + pipeline(new LettuceResult(getAsyncConnection().geopos(key, members), LettuceConverters.geoCoordinateListToGeoCoordinateList())); return null; } if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, member))); + transaction(new LettuceTxResult(getConnection().geopos(key, members), LettuceConverters.geoCoordinateListToGeoCoordinateList())); return null; } - return getConnection().georadius(key, longitude, latitude, member); + return LettuceConverters.geoCoordinateListToGeoCoordinateList().convert(getConnection().geopos(key, members)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } } - @Override - public List georadiusByMember(byte[] key, byte[] member, double radius, - GeoUnit unit) { - try { - if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().georadiusByMember(key, longitude, latitude, member))); - return null; - } - if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().georadiusByMember(key, longitude, latitude, member))); - return null; - } - return getConnection().georadiusByMember(key, longitude, latitude, member); - } catch (Exception ex) { - throw convertLettuceAccessException(ex); - } - } - - @Override - public List georadiusByMember(byte[] key, byte[] member, double radius, - GeoUnit unit, GeoRadiusParam param) { - - try { - if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().georadiusByMember(key, longitude, latitude, member))); - return null; - } - if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().georadiusByMember(key, longitude, latitude, member))); - return null; - } - return getConnection().georadiusByMember(key, longitude, latitude, member); - } catch (Exception ex) { - throw convertLettuceAccessException(ex); - } - } +// @Override +// public List georadius(byte[] key, double longitude, double latitude, +// double radius, GeoUnit unit) { +// try { +// if (isPipelined()) { +// pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, member))); +// return null; +// } +// if (isQueueing()) { +// transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, member))); +// return null; +// } +// return getConnection().georadius(key, longitude, latitude, member); +// } catch (Exception ex) { +// throw convertLettuceAccessException(ex); +// } +// } +// +// @Override +// public List georadius(byte[] key, double longitude, double latitude, +// double radius, GeoUnit unit, GeoRadiusParam param) { +// try { +// if (isPipelined()) { +// pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, member))); +// return null; +// } +// if (isQueueing()) { +// transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, member))); +// return null; +// } +// return getConnection().georadius(key, longitude, latitude, member); +// } catch (Exception ex) { +// throw convertLettuceAccessException(ex); +// } +// } +// +// @Override +// public List georadiusByMember(byte[] key, byte[] member, double radius, +// GeoUnit unit) { +// try { +// if (isPipelined()) { +// pipeline(new LettuceResult(getAsyncConnection().georadiusByMember(key, longitude, latitude, member))); +// return null; +// } +// if (isQueueing()) { +// transaction(new LettuceTxResult(getConnection().georadiusByMember(key, longitude, latitude, member))); +// return null; +// } +// return getConnection().georadiusByMember(key, longitude, latitude, member); +// } catch (Exception ex) { +// throw convertLettuceAccessException(ex); +// } +// } +// +// @Override +// public List georadiusByMember(byte[] key, byte[] member, double radius, +// GeoUnit unit, GeoRadiusParam param) { +// +// try { +// if (isPipelined()) { +// pipeline(new LettuceResult(getAsyncConnection().georadiusByMember(key, longitude, latitude, member))); +// return null; +// } +// if (isQueueing()) { +// transaction(new LettuceTxResult(getConnection().georadiusByMember(key, longitude, latitude, member))); +// return null; +// } +// return getConnection().georadiusByMember(key, longitude, latitude, member); +// } catch (Exception ex) { +// throw convertLettuceAccessException(ex); +// } +// } /* * (non-Javadoc) diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java index 9d57b17c2b..3fe36134e3 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; +import com.lambdaworks.redis.*; import org.springframework.core.convert.converter.Converter; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.DefaultTuple; @@ -47,19 +48,17 @@ import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.SortParameters.Order; import org.springframework.data.redis.connection.convert.Converters; +import org.springframework.data.redis.connection.convert.ListConverter; import org.springframework.data.redis.connection.convert.LongToBooleanConverter; import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter; +import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import com.lambdaworks.redis.KeyValue; -import com.lambdaworks.redis.RedisURI; -import com.lambdaworks.redis.ScoredValue; -import com.lambdaworks.redis.ScriptOutputType; -import com.lambdaworks.redis.SortArgs; import com.lambdaworks.redis.cluster.models.partitions.Partitions; import com.lambdaworks.redis.cluster.models.partitions.RedisClusterNode.NodeFlag; import com.lambdaworks.redis.protocol.LettuceCharsets; @@ -91,6 +90,8 @@ abstract public class LettuceConverters extends Converters { private static final Converter> STRING_TO_LIST_OF_CLIENT_INFO = new StringToRedisClientInfoConverter(); private static final Converter> PARTITIONS_TO_CLUSTER_NODES; private static Converter CLUSTER_NODE_TO_CLUSTER_NODE_CONVERTER; + private static final Converter GEO_COORDINATE_CONVERTER; + private static final ListConverter GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; public static final byte[] PLUS_BYTES; public static final byte[] MINUS_BYTES; @@ -284,7 +285,16 @@ private Set parseFlags(Set source) { MINUS_BYTES = toBytes("-"); POSITIVE_INFINITY_BYTES = toBytes("+inf"); NEGATIVE_INFINITY_BYTES = toBytes("-inf"); - } + + GEO_COORDINATE_CONVERTER = new Converter() { + @Override + public GeoCoordinate convert(com.lambdaworks.redis.GeoCoordinates geoCoordinate) { + return geoCoordinate != null ? new GeoCoordinate(geoCoordinate.x.doubleValue(), geoCoordinate.y.doubleValue()) : null; + } + }; + GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST = new ListConverter(GEO_COORDINATE_CONVERTER); + + } public static List toTuple(List list) { return BYTES_LIST_TO_TUPLE_LIST_CONVERTER.convert(list); @@ -344,6 +354,8 @@ public static Converter exceptionConverter() { return EXCEPTION_CONVERTER; } + public static ListConverter geoCoordinateListToGeoCoordinateList() { return GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; } + /** * @return * @sice 1.3 @@ -657,4 +669,17 @@ public static SetArgs toSetArgs(Expiration expiration, SetOption option) { return args; } + public static com.lambdaworks.redis.GeoArgs.Unit toGeoArgsUnit(GeoUnit geoUnit){ + switch (geoUnit){ + case Meters: return GeoArgs.Unit.m; + case KiloMeters: return GeoArgs.Unit.km; + case Miles: return GeoArgs.Unit.mi; + case Feet: return GeoArgs.Unit.ft; + default: throw new IllegalArgumentException("geoUnit not supported"); + } + } + + public static redis.clients.jedis.GeoCoordinate toGeoCoordinate(GeoCoordinate geoCoordinate){ + return new redis.clients.jedis.GeoCoordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()); + } } diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java index 8ff97f3b4e..170367bfa4 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java @@ -45,6 +45,8 @@ import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; import org.springframework.data.redis.core.Cursor; +import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; @@ -2246,6 +2248,31 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) throw new UnsupportedOperationException(); } + @Override + public Long geoAdd(byte[] key, Map memberCoordinateMap) { + throw new UnsupportedOperationException(); + } + + @Override + public Double geoDist(byte[] key, byte[] member1, byte[] member2) { + throw new UnsupportedOperationException(); + } + + @Override + public Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + throw new UnsupportedOperationException(); + } + + @Override + public List geoHash(byte[] key, byte[]... members) { + throw new UnsupportedOperationException(); + } + + @Override + public List geoPos(byte[] key, byte[]... members) { + throw new UnsupportedOperationException(); + } + /** * Specifies if pipelined results should be converted to the expected data type. If false, results of * {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Lettuce driver diff --git a/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java index 162e70e8ac..babea1099d 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java @@ -15,6 +15,9 @@ */ package org.springframework.data.redis.core; +import java.util.List; +import java.util.Map; + /** * Hash operations bound to a certain key. * @@ -22,4 +25,14 @@ */ public interface BoundGeoOperations extends BoundKeyOperations { Long geoAdd(K key, double longitude, double latitude, M member); + + Long geoAdd(K key, Map memberCoordinateMap); + + Double geoDist(K key, M member1, M member2); + + Double geoDist(K key, M member1, M member2, GeoUnit unit); + + List geoHash(K key, M... members); + + List geoPos(K key, M... members); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java index 3611f82724..e6042db79c 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java @@ -17,6 +17,8 @@ import org.springframework.data.redis.connection.DataType; +import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; /** @@ -42,6 +44,31 @@ public Long geoAdd(K key, double longitude, double latitude, M member) { return ops.geoAdd(key, longitude, latitude, member); } + @Override + public Long geoAdd(K key, Map memberCoordinateMap) { + return ops.geoAdd(key, memberCoordinateMap); + } + + @Override + public Double geoDist(K key, M member1, M member2) { + return ops.geoDist(key, member1, member2); + } + + @Override + public Double geoDist(K key, M member1, M member2, GeoUnit unit) { + return ops.geoDist(key, member1, member2, unit); + } + + @Override + public List geoHash(K key, M... members) { + return ops.geoHash(key, members); + } + + @Override + public List geoPos(K key, M... members) { + return ops.geoPos(key, members); + } + @Override public DataType getType() { return DataType.STRING; diff --git a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java index 0790a75af8..30125e56c7 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java @@ -17,6 +17,10 @@ import org.springframework.data.redis.connection.RedisConnection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * Default implementation of {@link GeoOperations}. * @@ -39,4 +43,75 @@ public Long doInRedis(RedisConnection connection) { } }, true); } + + @Override + public Long geoAdd(K key, Map memberCoordinateMap) { + final byte[] rawKey = rawKey(key); + final Map rawMemberCoordinateMap = new HashMap(); + for(M member : memberCoordinateMap.keySet()){ + final byte[] rawMember = rawValue(member); + rawMemberCoordinateMap.put(rawMember, memberCoordinateMap.get(member)); + } + + return execute(new RedisCallback() { + + public Long doInRedis(RedisConnection connection) { + return connection.geoAdd(rawKey, rawMemberCoordinateMap); + } + }, true); + } + + @Override + public Double geoDist(K key, final M member1, final M member2) { + final byte[] rawKey = rawKey(key); + final byte[] rawMember1 = rawValue(member1); + final byte[] rawMember2 = rawValue(member2); + + return execute(new RedisCallback() { + + public Double doInRedis(RedisConnection connection) { + return connection.geoDist(rawKey, rawMember1, rawMember2); + } + }, true); + } + + @Override + public Double geoDist(K key, M member1, M member2, final GeoUnit unit) { + final byte[] rawKey = rawKey(key); + final byte[] rawMember1 = rawValue(member1); + final byte[] rawMember2 = rawValue(member2); + + return execute(new RedisCallback() { + + public Double doInRedis(RedisConnection connection) { + return connection.geoDist(rawKey, rawMember1, rawMember2, unit); + } + }, true); + } + + @Override + public List geoHash(K key, final M... members) { + final byte[] rawKey = rawKey(key); + final byte[][] rawMembers = rawValues(members); + + return execute(new RedisCallback>() { + + public List doInRedis(RedisConnection connection) { + return connection.geoHash(rawKey, rawMembers); + } + }, true); + } + + @Override + public List geoPos(K key, M... members) { + final byte[] rawKey = rawKey(key); + final byte[][] rawMembers = rawValues(members); + + return execute(new RedisCallback>() { + + public List doInRedis(RedisConnection connection) { + return connection.geoPos(rawKey, rawMembers); + } + }, true); + } } diff --git a/src/main/java/org/springframework/data/redis/core/GeoOperations.java b/src/main/java/org/springframework/data/redis/core/GeoOperations.java index a3cfc9bfd9..7c70031699 100644 --- a/src/main/java/org/springframework/data/redis/core/GeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/GeoOperations.java @@ -15,6 +15,9 @@ */ package org.springframework.data.redis.core; +import java.util.List; +import java.util.Map; + /** * Redis operations for geo commands. * @@ -22,4 +25,14 @@ */ public interface GeoOperations { Long geoAdd(K key, double longitude, double latitude, M member); + + Long geoAdd(K key, Map memberCoordinateMap); + + Double geoDist(K key, M member1, M member2); + + Double geoDist(K key, M member1, M member2, GeoUnit unit); + + List geoHash(K key, M... members); + + List geoPos(K key, M... members); } diff --git a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java index 0832f3fdf6..08983c5e85 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java @@ -29,6 +29,8 @@ import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder; import org.springframework.data.redis.core.Cursor; +import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; @@ -264,6 +266,31 @@ public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) return delegate.geoAdd(key, longitude, latitude, member); } + @Override + public Long geoAdd(byte[] key, Map memberCoordinateMap) { + return delegate.geoAdd(key, memberCoordinateMap); + } + + @Override + public Double geoDist(byte[] key, byte[] member1, byte[] member2) { + return delegate.geoDist(key, member1, member2); + } + + @Override + public Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + return delegate.geoDist(key, member1, member2, unit); + } + + @Override + public List geoHash(byte[] key, byte[]... members) { + return delegate.geoHash(key, members); + } + + @Override + public List geoPos(byte[] key, byte[]... members) { + return delegate.geoPos(key, members); + } + public Set keys(byte[] pattern) { return delegate.keys(pattern); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java index c8cc9d8687..643dd7aa30 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java @@ -88,4 +88,17 @@ public void testGeoAdd() throws Exception { // numAdded = geoOperations.geoAdd("Sicily", 15.087269, 37.502669, "Catania"); // assertEquals(numAdded.longValue(), 2L); } + + @Test + public void testGeoAdd2() throws Exception { + K key = keyFactory.instance(); + Map memberCoordinateMap = new HashMap(); + memberCoordinateMap.put(valueFactory.instance(), new GeoCoordinate(2.2323, 43.324)); + memberCoordinateMap.put(valueFactory.instance(), new GeoCoordinate(12.993, 31.3994)); + Long numAdded = geoOperations.geoAdd(key, memberCoordinateMap); + assertEquals(numAdded.longValue(), 2L); + +// numAdded = geoOperations.geoAdd("Sicily", 15.087269, 37.502669, "Catania"); +// assertEquals(numAdded.longValue(), 2L); + } } From fd7b5e5ef7655c41a92f523165e51cbceb413a4c Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Thu, 31 Mar 2016 23:48:38 -0700 Subject: [PATCH 07/15] DATAREDIS-438 Adding tests --- .../DefaultStringRedisConnection.java | 165 ++++++++++++------ .../connection/StringRedisConnection.java | 16 +- .../connection/jedis/JedisConverters.java | 2 +- .../DefaultStringRedisConnectionTests.java | 52 +++++- .../redis/core/DefaultGeoOperationsTests.java | 65 +++++++ 5 files changed, 237 insertions(+), 63 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 93cb42f66d..30ae7008ef 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -270,59 +270,6 @@ public void flushDb() { delegate.flushDb(); } - public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member){ - Long result = delegate.geoAdd(key, longitude, latitude, member); - if (isFutureConversion()){ - addResultConverter(identityConverter); - } - return result; - } - - @Override - public Long geoAdd(byte[] key, Map memberCoordinateMap) { - Long result = delegate.geoAdd(key, memberCoordinateMap); - if (isFutureConversion()){ - addResultConverter(identityConverter); - } - return result; - } - - @Override - public Double geoDist(byte[] key, byte[] member1, byte[] member2) { - Double result = delegate.geoDist(key, member1, member2); - if (isFutureConversion()){ - addResultConverter(identityConverter); - } - return result; - } - - @Override - public Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { - Double result = delegate.geoDist(key, member1, member2, unit); - if (isFutureConversion()){ - addResultConverter(identityConverter); - } - return result; - } - - @Override - public List geoHash(byte[] key, byte[]... members) { - List result = delegate.geoHash(key, members); - if (isFutureConversion()){ - addResultConverter(identityConverter); - } - return result; - } - - @Override - public List geoPos(byte[] key, byte[]... members) { - List result = delegate.geoPos(key, members); - if (isFutureConversion()){ - addResultConverter(identityConverter); - } - return result; - } - public byte[] get(byte[] key) { byte[] result = delegate.get(key); if (isFutureConversion()) { @@ -1550,10 +1497,6 @@ public Boolean expireAt(String key, long unixTime) { return result; } - public Long geoAdd(String key, double longitude, double latitude, String member){ - return delegate.geoAdd(serialize(key), longitude, latitude, serialize(member)); - } - public String get(String key) { byte[] result = delegate.get(serialize(key)); if (isFutureConversion()) { @@ -2327,6 +2270,114 @@ public Long zUnionStore(String destKey, String... sets) { return result; } + @Override + public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member){ + Long result = delegate.geoAdd(key, longitude, latitude, member); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public Long geoAdd(String key, double longitude, double latitude, String member){ + Long result = delegate.geoAdd(serialize(key), longitude, latitude, serialize(member)); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public Long geoAdd(byte[] key, Map memberCoordinateMap) { + Long result = delegate.geoAdd(key, memberCoordinateMap); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public Long geoAdd(String key, Map memberCoordinateMap) { + Map byteMap = new HashMap(); + for (String k : memberCoordinateMap.keySet()){ + byteMap.put(serialize(k), memberCoordinateMap.get(k)); + } + Long result = delegate.geoAdd(serialize(key), byteMap); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public Double geoDist(byte[] key, byte[] member1, byte[] member2) { + Double result = delegate.geoDist(key, member1, member2); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public Double geoDist(String key, String member1, String member2) { + return geoDist(key, member1, member2, GeoUnit.Meters); + } + + @Override + public Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + Double result = delegate.geoDist(key, member1, member2, unit); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public Double geoDist(String key, String member1, String member2, GeoUnit geoUnit) { + Double result = delegate.geoDist(serialize(key), serialize(member1), serialize(member2), geoUnit); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List geoHash(byte[] key, byte[]... members) { + List result = delegate.geoHash(key, members); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List geoHash(String key, String... members) { + List result = delegate.geoHash(serialize(key), serializeMulti(members)); + if (isFutureConversion()){ + addResultConverter(byteListToStringList); + } + return byteListToStringList.convert(result); + } + + @Override + public List geoPos(byte[] key, byte[]... members) { + List result = delegate.geoPos(key, members); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List geoPos(String key, String... members) { + List result = delegate.geoPos(serialize(key), serializeMulti(members)); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + public List closePipeline() { try { return convertResults(delegate.closePipeline(), pipelineConverters); 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 3056c871f0..34eb2c3a8d 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -20,10 +20,7 @@ import java.util.Map; import java.util.Set; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.RedisCallback; -import org.springframework.data.redis.core.ScanOptions; -import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.data.redis.serializer.RedisSerializer; @@ -625,4 +622,15 @@ public interface StringTuple extends Tuple { */ Set zRangeByLex(String key, Range range, Limit limit); + Long geoAdd(String key, double longitude, double latitude, String member); + + Long geoAdd(String key, Map memberCoordinateMap); + + Double geoDist(String key, String member1, String member2); + + Double geoDist(String key, String member1, String member2, GeoUnit unit); + + List geoHash(String key, String... values); + + List geoPos(String key, String... members); } diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java index a881a24bb1..fb6fe364b3 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java @@ -474,7 +474,7 @@ public static redis.clients.jedis.GeoUnit toGeoUnit(GeoUnit geoUnit){ switch (geoUnit){ case Meters: return redis.clients.jedis.GeoUnit.M; case KiloMeters: return redis.clients.jedis.GeoUnit.KM; - case Miles: return redis.clients.jedis.GeoUnit.M; + case Miles: return redis.clients.jedis.GeoUnit.MI; case Feet: return redis.clients.jedis.GeoUnit.FT; default: throw new IllegalArgumentException("geoUnit not supported"); } diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java index 81230bf105..1ca84ece35 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java @@ -40,6 +40,8 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate; import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; import org.springframework.data.redis.connection.StringRedisConnection.StringTuple; +import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.serializer.StringRedisSerializer; /** @@ -62,10 +64,14 @@ public class DefaultStringRedisConnectionTests { protected String bar = "bar"; + protected String bar2 = "bar2"; + protected byte[] fooBytes = serializer.serialize(foo); protected byte[] barBytes = serializer.serialize(bar); + protected byte[] bar2Bytes = serializer.serialize(bar2); + protected List bytesList = Collections.singletonList(barBytes); protected List stringList = Collections.singletonList(bar); @@ -1569,7 +1575,51 @@ public void testZUnionStore() { verifyResults(Arrays.asList(new Object[] { 5l })); } - @Test + @Test + public void testGeoAdd(){ + doReturn(1l).when(nativeConnection).geoAdd(fooBytes, 1.23232, 34.2342434, barBytes); + actual.add(connection.geoAdd(foo, 1.23232, 34.2342434, bar)); + verifyResults(Arrays.asList(new Object[] { 1l })); + } + + @Test + public void testGeoAdd2(){ + Map memberGeoCoordinateMap = new HashMap(); + memberGeoCoordinateMap.put(barBytes, new GeoCoordinate(1.23232, 34.2342434)); + doReturn(1l).when(nativeConnection).geoAdd(fooBytes, memberGeoCoordinateMap); + + Map stringGeoCoordinateMap = new HashMap(); + stringGeoCoordinateMap.put(bar, new GeoCoordinate(1.23232, 34.2342434)); + actual.add(connection.geoAdd(foo, stringGeoCoordinateMap)); + verifyResults(Arrays.asList(new Object[] { 1l })); + } + + @Test + public void testGeoDist(){ + doReturn(102121.12d).when(nativeConnection).geoDist(fooBytes, barBytes, bar2Bytes, GeoUnit.Meters); + actual.add(connection.geoDist(foo, bar, bar2, GeoUnit.Meters)); + verifyResults(Arrays.asList(new Object[] { 102121.12d })); + } + + @Test + public void testGeoHash(){ + doReturn(bytesList).when(nativeConnection).geoHash(fooBytes, barBytes); + actual.add(connection.geoHash(foo, bar)); + List expected = new ArrayList(); + expected.add(bar); + verifyResults(Arrays.asList(new Object[]{expected})); + } + + @Test + public void testGeoPos(){ + List geoCoordinates = new ArrayList(); + geoCoordinates.add(new GeoCoordinate(213.00, 324.343)); + doReturn(geoCoordinates).when(nativeConnection).geoPos(fooBytes, barBytes); + actual.add(connection.geoPos(foo, bar)); + verifyResults(Arrays.asList(new Object[] { geoCoordinates })); + } + + @Test public void testPExpireBytes() { doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l); actual.add(connection.pExpire(fooBytes, 34l)); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java index 643dd7aa30..dd53d77154 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java @@ -25,9 +25,12 @@ import org.springframework.data.redis.RedisTestProfileValueSource; import org.springframework.data.redis.TestCondition; import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; import java.text.DecimalFormat; import java.util.*; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; @@ -101,4 +104,66 @@ public void testGeoAdd2() throws Exception { // numAdded = geoOperations.geoAdd("Sicily", 15.087269, 37.502669, "Catania"); // assertEquals(numAdded.longValue(), 2L); } + + @Test + public void testGeoDist() throws Exception { + K key = keyFactory.instance(); + M v1 = valueFactory.instance(); + M v2 = valueFactory.instance(); + + geoOperations.geoAdd(key, 13.361389, 38.115556, v1); + geoOperations.geoAdd(key, 15.087269, 37.502669, v2); + + Double dist = geoOperations.geoDist(key, v1, v2); + assertEquals(dist.doubleValue(), 166274.15156960033, 0.00001); // gives in meters + + dist = geoOperations.geoDist(key, v1, v2, GeoUnit.KiloMeters); + assertEquals(dist.doubleValue(), 166.27415156960033, 0.00001); + + dist = geoOperations.geoDist(key, v1, v2, GeoUnit.Miles); + assertEquals(dist.doubleValue(), 103.31822459492733, 0.00001); + + dist = geoOperations.geoDist(key, v1, v2, GeoUnit.Feet); + assertEquals(dist.doubleValue(), 545518.8699790037, 0.00001); + } + + @Test + public void testGeoHash() throws Exception { + K key = keyFactory.instance(); + M v1 = valueFactory.instance(); + M v2 = valueFactory.instance(); + + geoOperations.geoAdd(key, 13.361389, 38.115556, v1); + geoOperations.geoAdd(key, 15.087269, 37.502669, v2); + + List result = geoOperations.geoHash(key, v1, v2); + assertEquals(result.size(), 2); + + final RedisSerializer serializer = new StringRedisSerializer(); + + assertEquals(serializer.deserialize(result.get(0)), "sqc8b49rny0"); + assertEquals(serializer.deserialize(result.get(1)), "sqdtr74hyu0"); + } + + @Test + public void testGeoPos() throws Exception { + K key = keyFactory.instance(); + M v1 = valueFactory.instance(); + M v2 = valueFactory.instance(); + M v3 = valueFactory.instance(); + + geoOperations.geoAdd(key, 13.361389, 38.115556, v1); + geoOperations.geoAdd(key, 15.087269, 37.502669, v2); + + List result = geoOperations.geoPos(key, v1, v2, v3);// v3 is nonexisting + assertEquals(result.size(), 3); + + assertEquals(result.get(0).getLongitude(), 13.361389338970184, 0.000001); + assertEquals(result.get(0).getLatitude(), 38.115556395496299, 0.000001); + + assertEquals(result.get(1).getLongitude(), 15.087267458438873, 0.000001); + assertEquals(result.get(1).getLatitude(), 37.50266842333162, 0.000001); + + assertNull(result.get(2)); + } } From f51d9848945eb9c84fcabd885e4c12e18271f363 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Fri, 1 Apr 2016 23:46:56 -0700 Subject: [PATCH 08/15] DATAREDIS-438 Adding remaining geo* methods --- .../redis/connection/RedisGeoCommands.java | 24 +-- .../jedis/JedisClusterConnection.java | 91 +++++----- .../connection/jedis/JedisConnection.java | 165 ++++++++++-------- .../connection/jedis/JedisConverters.java | 66 +++++-- .../connection/jredis/JredisConnection.java | 25 ++- .../connection/lettuce/LettuceConnection.java | 54 +++++- .../connection/lettuce/LettuceConverters.java | 26 ++- .../data/redis/core/GeoRadiusParam.java | 24 +++ .../data/redis/core/GeoRadiusResponse.java | 34 ++++ 9 files changed, 362 insertions(+), 147 deletions(-) create mode 100644 src/main/java/org/springframework/data/redis/core/GeoRadiusResponse.java diff --git a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java index d30bd9214c..9306f20e66 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java @@ -17,6 +17,8 @@ import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoRadiusParam; +import org.springframework.data.redis.core.GeoRadiusResponse; import org.springframework.data.redis.core.GeoUnit; import java.util.List; @@ -53,15 +55,15 @@ public interface RedisGeoCommands { List geoPos(byte[] key, byte[]... members); -// List georadius(byte[] key, double longitude, double latitude, -// double radius, GeoUnit unit); -// -// List georadius(byte[] key, double longitude, double latitude, -// double radius, GeoUnit unit, GeoRadiusParam param); -// -// List georadiusByMember(byte[] key, byte[] member, double radius, -// GeoUnit unit); -// -// List georadiusByMember(byte[] key, byte[] member, double radius, -// GeoUnit unit, GeoRadiusParam param); + List georadius(byte[] key, double longitude, double latitude, + double radius, GeoUnit unit); + + List georadius(byte[] key, double longitude, double latitude, + double radius, GeoUnit unit, GeoRadiusParam param); + + List georadiusByMember(byte[] key, byte[] member, double radius, + GeoUnit unit); + + List georadiusByMember(byte[] key, byte[] member, double radius, + GeoUnit unit, GeoRadiusParam param); } diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java index 8e7a9436ff..b6888e6c74 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java @@ -49,6 +49,7 @@ import org.springframework.data.redis.connection.convert.Converters; import org.springframework.data.redis.connection.util.ByteArraySet; import org.springframework.data.redis.core.*; +import org.springframework.data.redis.core.GeoRadiusResponse; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.data.redis.util.ByteUtils; @@ -2554,46 +2555,56 @@ public List geoPos(byte[] key } } -// @Override -// public List georadius(byte[] key, double longitude, double latitude, -// double radius, GeoUnit unit) { -// try { -// return cluster.georadius(key, longitude, latitude, radius, unit); -// } catch (Exception ex) { -// throw convertJedisAccessException(ex); -// } -// } -// -// @Override -// public List georadius(byte[] key, double longitude, double latitude, -// double radius, GeoUnit unit, GeoRadiusParam param) { -// try { -// return cluster.georadius(key, longitude, latitude, radius, unit, param); -// } catch (Exception ex) { -// throw convertJedisAccessException(ex); -// } -// } -// -// @Override -// public List georadiusByMember(byte[] key, byte[] member, double radius, -// GeoUnit unit) { -// try { -// return cluster.georadiusByMember(key, member, radius, unit); -// } catch (Exception ex) { -// throw convertJedisAccessException(ex); -// } -// } -// -// @Override -// public List georadiusByMember(byte[] key, byte[] member, double radius, -// GeoUnit unit, GeoRadiusParam param) { -// -// try { -// return cluster.georadiusByMember(key, member, radius, unit, param); -// } catch (Exception ex) { -// throw convertJedisAccessException(ex); -// } -// } + @Override + public List georadius(byte[] key, double longitude, double latitude, + double radius, org.springframework.data.redis.core.GeoUnit unit) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + try { + return JedisConverters.geoRadiusResponseGeoRadiusResponseList(). + convert(cluster.georadius(key, longitude, latitude, radius, geoUnit)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, + double radius, org.springframework.data.redis.core.GeoUnit unit, GeoRadiusParam param) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + redis.clients.jedis.params.geo.GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(param); + try { + return JedisConverters.geoRadiusResponseGeoRadiusResponseList(). + convert(cluster.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, + org.springframework.data.redis.core.GeoUnit unit) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + try { + return JedisConverters.geoRadiusResponseGeoRadiusResponseList(). + convert(cluster.georadiusByMember(key, member, radius, geoUnit)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, + org.springframework.data.redis.core.GeoUnit unit, GeoRadiusParam param) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + redis.clients.jedis.params.geo.GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(param); + try { + return JedisConverters.geoRadiusResponseGeoRadiusResponseList(). + convert(cluster.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam)); + + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } /* 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 7cc9cdafcb..bb9099784a 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConnection.java @@ -42,6 +42,7 @@ import org.springframework.data.redis.connection.convert.TransactionResultConverter; import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoRadiusResponse; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; @@ -53,7 +54,6 @@ import redis.clients.jedis.GeoUnit; import redis.clients.jedis.Protocol.Command; import redis.clients.jedis.exceptions.JedisDataException; -import redis.clients.jedis.params.geo.GeoRadiusParam; import redis.clients.util.Pool; /** @@ -3174,81 +3174,94 @@ public List geoPos(byte[] key, byte[]... members) { } } -// @Override -// public List georadius(byte[] key, double longitude, double latitude, -// double radius, GeoUnit unit) { -// try { -// if (isPipelined()) { -// pipeline(new JedisResult(pipeline.georadius(key, longitude, latitude, radius, unit))); -// return null; -// } -// if (isQueueing()) { -// transaction(new JedisResult(transaction.georadius(key, longitude, latitude, radius, unit))); -// return null; -// } -// -// return jedis.georadius(key, longitude, latitude, radius, unit); -// } catch (Exception ex) { -// throw convertJedisAccessException(ex); -// } -// } -// -// @Override -// public List georadius(byte[] key, double longitude, double latitude, -// double radius, GeoUnit unit, GeoRadiusParam param) { -// try { -// if (isPipelined()) { -// pipeline(new JedisResult(pipeline.georadius(key, longitude, latitude, radius, unit, param))); -// return null; -// } -// if (isQueueing()) { -// transaction(new JedisResult(transaction.georadius(key, longitude, latitude, radius, unit, param))); -// return null; -// } -// -// return jedis.georadius(key, longitude, latitude, radius, unit, param); -// } catch (Exception ex) { -// throw convertJedisAccessException(ex); -// } -// } -// -// @Override -// public List georadiusByMember(byte[] key, byte[] member, double radius, -// GeoUnit unit) { -// try { -// if (isPipelined()) { -// pipeline(new JedisResult(pipeline.georadiusByMember(key, member, radius, unit))); -// return null; -// } -// if (isQueueing()) { -// transaction(new JedisResult(transaction.georadiusByMember(key, member, radius, unit))); -// return null; -// } -// -// return jedis.georadiusByMember(key, member, radius, unit); -// } catch (Exception ex) { -// throw convertJedisAccessException(ex); -// } -// } -// -// @Override -// public List georadiusByMember(byte[] key, byte[] member, double radius, -// GeoUnit unit, GeoRadiusParam param) { -// -// try { -// if (isPipelined()) { -// pipeline(new JedisResult(pipeline.georadiusByMember(key, member, radius, unit, param))); -// return null; -// } -// if (isQueueing()) { -// transaction(new JedisResult(transaction.georadiusByMember(key, member, radius, unit, param))); -// return null; -// } -// return jedis.georadiusByMember(key, member, radius, unit, param); -// } catch (Exception ex) { -// throw convertJedisAccessException(ex); -// } -// } + @Override + public List georadius(byte[] key, double longitude, double latitude, + double radius, org.springframework.data.redis.core.GeoUnit unit) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.georadius(key, longitude, latitude, radius, geoUnit), JedisConverters.geoRadiusResponseGeoRadiusResponseList())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.georadius(key, longitude, latitude, radius, geoUnit), JedisConverters.geoRadiusResponseGeoRadiusResponseList())); + return null; + } + + return JedisConverters.geoRadiusResponseGeoRadiusResponseList().convert(jedis.georadius(key, longitude, latitude, radius, geoUnit)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, + double radius, org.springframework.data.redis.core.GeoUnit unit, GeoRadiusParam param) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + redis.clients.jedis.params.geo.GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(param); + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + JedisConverters.geoRadiusResponseGeoRadiusResponseList())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + JedisConverters.geoRadiusResponseGeoRadiusResponseList())); + return null; + } + + return JedisConverters.geoRadiusResponseGeoRadiusResponseList(). + convert(jedis.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, + org.springframework.data.redis.core.GeoUnit unit) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.georadiusByMember(key, member, radius, geoUnit), + JedisConverters.geoRadiusResponseGeoRadiusResponseList())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.georadiusByMember(key, member, radius, geoUnit), + JedisConverters.geoRadiusResponseGeoRadiusResponseList())); + return null; + } + + return JedisConverters.geoRadiusResponseGeoRadiusResponseList().convert(jedis.georadiusByMember(key, member, radius, geoUnit)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, + org.springframework.data.redis.core.GeoUnit unit, GeoRadiusParam param) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + redis.clients.jedis.params.geo.GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(param); + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + JedisConverters.geoRadiusResponseGeoRadiusResponseList())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + JedisConverters.geoRadiusResponseGeoRadiusResponseList())); + return null; + } + return JedisConverters.geoRadiusResponseGeoRadiusResponseList(). + convert(jedis.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } // diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java index fb6fe364b3..8cd082b78a 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java @@ -43,6 +43,8 @@ import org.springframework.data.redis.connection.convert.SetConverter; import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter; import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoRadiusParam; +import org.springframework.data.redis.core.GeoRadiusResponse; import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.Expiration; @@ -81,8 +83,10 @@ abstract public class JedisConverters extends Converters { private static final Converter OBJECT_TO_CLUSTER_NODE_CONVERTER; private static final Converter EXPIRATION_TO_COMMAND_OPTION_CONVERTER; private static final Converter SET_OPTION_TO_COMMAND_OPTION_CONVERTER; - private static final Converter GEO_COORDINATE_CONVERTER; - private static final ListConverter GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; + private static final Converter GEO_COORDINATE_CONVERTER; + private static final ListConverter GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; + private static final Converter GEO_RADIUS_RESPONSE_CONVERTER; + private static final ListConverter GEO_RADIUS_RESPONSE_LIST_TO_GEO_RADIUS_RESPONSE_LIST; public static final byte[] PLUS_BYTES; public static final byte[] MINUS_BYTES; @@ -170,13 +174,26 @@ public byte[] convert(SetOption source) { }; - GEO_COORDINATE_CONVERTER = new Converter() { - @Override - public GeoCoordinate convert(redis.clients.jedis.GeoCoordinate geoCoordinate) { - return geoCoordinate != null ? new GeoCoordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()) : null; - } - }; - GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST = new ListConverter(GEO_COORDINATE_CONVERTER); + GEO_COORDINATE_CONVERTER = new Converter() { + @Override + public GeoCoordinate convert(redis.clients.jedis.GeoCoordinate geoCoordinate) { + return geoCoordinate != null ? new GeoCoordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()) : null; + } + }; + GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST = new ListConverter(GEO_COORDINATE_CONVERTER); + + GEO_RADIUS_RESPONSE_CONVERTER = new Converter() { + @Override + public GeoRadiusResponse convert(redis.clients.jedis.GeoRadiusResponse geoRadiusResponse) { + if (geoRadiusResponse == null) + return null; + GeoRadiusResponse response = new GeoRadiusResponse(geoRadiusResponse.getMember()); + response.setDistance(geoRadiusResponse.getDistance()); + response.setCoordinate(GEO_COORDINATE_CONVERTER.convert(geoRadiusResponse.getCoordinate())); + return response; + } + }; + GEO_RADIUS_RESPONSE_LIST_TO_GEO_RADIUS_RESPONSE_LIST = new ListConverter(GEO_RADIUS_RESPONSE_CONVERTER); } public static Converter stringToBytes() { @@ -213,7 +230,9 @@ public static Converter exceptionConverter() { return EXCEPTION_CONVERTER; } - public static ListConverter geoCoordinateListToGeoCoordinateList() { return GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; } + public static ListConverter geoCoordinateListToGeoCoordinateList() { return GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; } + + public static ListConverter geoRadiusResponseGeoRadiusResponseList() { return GEO_RADIUS_RESPONSE_LIST_TO_GEO_RADIUS_RESPONSE_LIST; } public static String[] toStrings(byte[][] source) { String[] result = new String[source.length]; @@ -484,8 +503,27 @@ public static redis.clients.jedis.GeoCoordinate toGeoCoordinate(GeoCoordinate ge return new redis.clients.jedis.GeoCoordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()); } -// public static redis.clients.jedis.params.geo.GeoRadiusParam toGeoRadiusParam(GeoRadiusParam geoRadiusParam){ -// redis.clients.jedis.params.geo.GeoRadiusParam param = new redis.clients.jedis.params.geo.GeoRadiusParam(); -// -// } + public static redis.clients.jedis.params.geo.GeoRadiusParam toGeoRadiusParam(GeoRadiusParam geoRadiusParam){ + redis.clients.jedis.params.geo.GeoRadiusParam param = redis.clients.jedis.params.geo.GeoRadiusParam.geoRadiusParam(); + for (String k : geoRadiusParam.getParams().keySet()){ + if (k.equals(GeoRadiusParam.getASC())) + param.sortAscending(); + if (k.equals(GeoRadiusParam.getDESC())) + param.sortDescending(); + if (k.equals(GeoRadiusParam.getCOUNT())) + param.count((Integer)geoRadiusParam.getParams().get(k)); + if (k.equals(GeoRadiusParam.getWITHCOORD())) + param.withCoord(); + if (k.equals(GeoRadiusParam.getWITHDIST())) + param.withDist(); + } + return param; + } + + public static redis.clients.jedis.GeoRadiusResponse toGeoRadiusResponse(GeoRadiusResponse geoRadiusResponse){ + redis.clients.jedis.GeoRadiusResponse response = new redis.clients.jedis.GeoRadiusResponse(geoRadiusResponse.getMember()); + response.setCoordinate(toGeoCoordinate(geoRadiusResponse.getCoordinate())); + response.setDistance(geoRadiusResponse.getDistance()); + return response; + } } 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 f7dd92fcb4..d4dd197e75 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 @@ -45,9 +45,7 @@ import org.springframework.data.redis.connection.ReturnType; import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.GeoCoordinate; -import org.springframework.data.redis.core.ScanOptions; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; @@ -1227,8 +1225,27 @@ public List geoPos(byte[] key, byte[]... members) { throw new UnsupportedOperationException(); } + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) { + throw new UnsupportedOperationException(); + } - // + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { + throw new UnsupportedOperationException(); + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) { + throw new UnsupportedOperationException(); + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) { + throw new UnsupportedOperationException(); + } + + // // Scripting commands // diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index fe88a0683e..62f9c0ba92 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -3140,7 +3140,59 @@ public List geoPos(byte[] key, byte[]... members) { } } -// @Override + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) { + GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit); + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, radius, geoUnit), + LettuceConverters.bytesSetToGeoRadiusResponseListConverter())); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, radius, geoUnit), + LettuceConverters.bytesSetToGeoRadiusResponseListConverter())); + return null; + } + return LettuceConverters.bytesSetToGeoRadiusResponseListConverter(). + convert(getConnection().georadius(key, longitude, latitude, radius, geoUnit)); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { + GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit); + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, radius, geoUnit), + LettuceConverters.bytesSetToGeoRadiusResponseListConverter())); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, radius, geoUnit), + LettuceConverters.bytesSetToGeoRadiusResponseListConverter())); + return null; + } + return LettuceConverters.bytesSetToGeoRadiusResponseListConverter(). + convert(getConnection().georadius(key, longitude, latitude, radius, geoUnit)); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) { + return null; + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) { + return null; + } + + // @Override // public List georadius(byte[] key, double longitude, double latitude, // double radius, GeoUnit unit) { // try { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java index 3fe36134e3..5c88ccd215 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java @@ -52,6 +52,7 @@ import org.springframework.data.redis.connection.convert.LongToBooleanConverter; import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter; import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoRadiusResponse; import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; @@ -92,6 +93,7 @@ abstract public class LettuceConverters extends Converters { private static Converter CLUSTER_NODE_TO_CLUSTER_NODE_CONVERTER; private static final Converter GEO_COORDINATE_CONVERTER; private static final ListConverter GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; + private static final Converter, List> BYTES_SET_TO_GEO_RADIUS_RESPONSE_LIST; public static final byte[] PLUS_BYTES; public static final byte[] MINUS_BYTES; @@ -294,7 +296,25 @@ public GeoCoordinate convert(com.lambdaworks.redis.GeoCoordinates geoCoordinate) }; GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST = new ListConverter(GEO_COORDINATE_CONVERTER); - } + BYTES_SET_TO_GEO_RADIUS_RESPONSE_LIST = new Converter, List>() { + + @Override + public List convert(Set source) { + + if (CollectionUtils.isEmpty(source)) { + return Collections.emptyList(); + } + + List geoRadiusResponses = new ArrayList(); + Iterator it = source.iterator(); + while (it.hasNext()) { + geoRadiusResponses.add(new GeoRadiusResponse(it.next())); + } + return geoRadiusResponses; + } + }; + + } public static List toTuple(List list) { return BYTES_LIST_TO_TUPLE_LIST_CONVERTER.convert(list); @@ -304,6 +324,10 @@ public static Converter, List> bytesListToTupleListConverter return BYTES_LIST_TO_TUPLE_LIST_CONVERTER; } + public static Converter, List> bytesSetToGeoRadiusResponseListConverter() { + return BYTES_SET_TO_GEO_RADIUS_RESPONSE_LIST; + } + public static Converter> stringToRedisClientListConverter() { return new Converter>() { diff --git a/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java b/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java index 5ad9fa7d9f..4ecd887c0d 100644 --- a/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java +++ b/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java @@ -61,4 +61,28 @@ protected void addParam(String name) { } params.put(name, null); } + + public Map getParams() { + return params; + } + + public static String getWITHCOORD() { + return WITHCOORD; + } + + public static String getWITHDIST() { + return WITHDIST; + } + + public static String getASC() { + return ASC; + } + + public static String getDESC() { + return DESC; + } + + public static String getCOUNT() { + return COUNT; + } } diff --git a/src/main/java/org/springframework/data/redis/core/GeoRadiusResponse.java b/src/main/java/org/springframework/data/redis/core/GeoRadiusResponse.java new file mode 100644 index 0000000000..8da66467db --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/GeoRadiusResponse.java @@ -0,0 +1,34 @@ +package org.springframework.data.redis.core; + +/** + * Created by ndivadkar on 4/1/16. + */ +public class GeoRadiusResponse { + private byte[] member; + private double distance; + private GeoCoordinate coordinate; + + public GeoRadiusResponse(byte[] member) { + this.member = member; + } + + public void setDistance(double distance) { + this.distance = distance; + } + + public void setCoordinate(GeoCoordinate coordinate) { + this.coordinate = coordinate; + } + + public byte[] getMember() { + return member; + } + + public double getDistance() { + return distance; + } + + public GeoCoordinate getCoordinate() { + return coordinate; + } +} From 42650e03c906100ca29018b1f61a28442a84b269 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Sat, 2 Apr 2016 14:11:30 -0700 Subject: [PATCH 09/15] DATAREDIS-438 Adding remaining geo* methods and unit tests --- .../DefaultStringRedisConnection.java | 72 ++++++++ .../connection/StringRedisConnection.java | 12 ++ .../connection/lettuce/LettuceConnection.java | 123 +++++-------- .../connection/lettuce/LettuceConverters.java | 47 ++++- .../redis/connection/srp/SrpConnection.java | 27 ++- .../DefaultStringRedisConnectionTests.java | 162 +++++++++++++++++- .../DefaultStringRedisConnectionTxTests.java | 145 +++++++++++++++- .../connection/RedisConnectionUnitTests.java | 27 ++- 8 files changed, 511 insertions(+), 104 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 30ae7008ef..e29f5747c8 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -2378,6 +2378,78 @@ public List geoPos(String key, String... members) { return result; } + @Override + public List georadius(String key, double longitude, double latitude, double radius, GeoUnit unit) { + List result = delegate.georadius(serialize(key), longitude, latitude, radius, unit); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List georadius(String key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { + List result = delegate.georadius(serialize(key), longitude, latitude, radius, unit, param); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List georadiusByMember(String key, String member, double radius, GeoUnit unit) { + List result = delegate.georadiusByMember(serialize(key), serialize(member), radius, unit); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List georadiusByMember(String key, String member, double radius, GeoUnit unit, GeoRadiusParam param) { + List result = delegate.georadiusByMember(serialize(key), serialize(member), radius, unit, param); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) { + List result = delegate.georadius(key, longitude, latitude, radius, unit); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { + List result = delegate.georadius(key, longitude, latitude, radius, unit, param); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) { + List result = delegate.georadiusByMember(key, member, radius, unit); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) { + List result = delegate.georadiusByMember(key, member, radius, unit, param); + if (isFutureConversion()){ + addResultConverter(identityConverter); + } + return result; + } + public List closePipeline() { try { return convertResults(delegate.closePipeline(), pipelineConverters); 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 34eb2c3a8d..91ff7d2faa 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -633,4 +633,16 @@ public interface StringTuple extends Tuple { List geoHash(String key, String... values); List geoPos(String key, String... members); + + List georadius(String key, double longitude, double latitude, + double radius, GeoUnit unit); + + List georadius(String key, double longitude, double latitude, + double radius, GeoUnit unit, GeoRadiusParam param); + + List georadiusByMember(String key, String member, double radius, + GeoUnit unit); + + List georadiusByMember(String key, String member, double radius, + GeoUnit unit, GeoRadiusParam param); } diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index 62f9c0ba92..2fcc4f35e1 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -3164,19 +3164,20 @@ public List georadius(byte[] key, double longitude, double la @Override public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit); + GeoArgs geoArgs = LettuceConverters.toGeoArgs(param); try { if (isPipelined()) { - pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, radius, geoUnit), - LettuceConverters.bytesSetToGeoRadiusResponseListConverter())); + pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, radius, geoUnit, geoArgs), + LettuceConverters.getGeowithinListToGeoRadiusResponseList())); return null; } if (isQueueing()) { - transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, radius, geoUnit), - LettuceConverters.bytesSetToGeoRadiusResponseListConverter())); + transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, radius, geoUnit, geoArgs), + LettuceConverters.getGeowithinListToGeoRadiusResponseList())); return null; } - return LettuceConverters.bytesSetToGeoRadiusResponseListConverter(). - convert(getConnection().georadius(key, longitude, latitude, radius, geoUnit)); + return LettuceConverters.getGeowithinListToGeoRadiusResponseList(). + convert(getConnection().georadius(key, longitude, latitude, radius, geoUnit, geoArgs)); } catch (Exception ex) { throw convertLettuceAccessException(ex); } @@ -3184,87 +3185,47 @@ public List georadius(byte[] key, double longitude, double la @Override public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) { - return null; + GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit); + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().georadiusbymember(key, member, radius, geoUnit), + LettuceConverters.bytesSetToGeoRadiusResponseListConverter())); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().georadiusbymember(key, member, radius, geoUnit), + LettuceConverters.bytesSetToGeoRadiusResponseListConverter())); + return null; + } + return LettuceConverters.bytesSetToGeoRadiusResponseListConverter(). + convert(getConnection().georadiusbymember(key, member, radius, geoUnit)); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } } @Override public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) { - return null; + GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit); + GeoArgs geoArgs = LettuceConverters.toGeoArgs(param); + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().georadiusbymember(key, member, radius, geoUnit, geoArgs), + LettuceConverters.getGeowithinListToGeoRadiusResponseList())); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().georadiusbymember(key, member, radius, geoUnit, geoArgs), + LettuceConverters.getGeowithinListToGeoRadiusResponseList())); + return null; + } + return LettuceConverters.getGeowithinListToGeoRadiusResponseList(). + convert(getConnection().georadiusbymember(key, member, radius, geoUnit, geoArgs)); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } } - // @Override -// public List georadius(byte[] key, double longitude, double latitude, -// double radius, GeoUnit unit) { -// try { -// if (isPipelined()) { -// pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, member))); -// return null; -// } -// if (isQueueing()) { -// transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, member))); -// return null; -// } -// return getConnection().georadius(key, longitude, latitude, member); -// } catch (Exception ex) { -// throw convertLettuceAccessException(ex); -// } -// } -// -// @Override -// public List georadius(byte[] key, double longitude, double latitude, -// double radius, GeoUnit unit, GeoRadiusParam param) { -// try { -// if (isPipelined()) { -// pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, member))); -// return null; -// } -// if (isQueueing()) { -// transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, member))); -// return null; -// } -// return getConnection().georadius(key, longitude, latitude, member); -// } catch (Exception ex) { -// throw convertLettuceAccessException(ex); -// } -// } -// -// @Override -// public List georadiusByMember(byte[] key, byte[] member, double radius, -// GeoUnit unit) { -// try { -// if (isPipelined()) { -// pipeline(new LettuceResult(getAsyncConnection().georadiusByMember(key, longitude, latitude, member))); -// return null; -// } -// if (isQueueing()) { -// transaction(new LettuceTxResult(getConnection().georadiusByMember(key, longitude, latitude, member))); -// return null; -// } -// return getConnection().georadiusByMember(key, longitude, latitude, member); -// } catch (Exception ex) { -// throw convertLettuceAccessException(ex); -// } -// } -// -// @Override -// public List georadiusByMember(byte[] key, byte[] member, double radius, -// GeoUnit unit, GeoRadiusParam param) { -// -// try { -// if (isPipelined()) { -// pipeline(new LettuceResult(getAsyncConnection().georadiusByMember(key, longitude, latitude, member))); -// return null; -// } -// if (isQueueing()) { -// transaction(new LettuceTxResult(getConnection().georadiusByMember(key, longitude, latitude, member))); -// return null; -// } -// return getConnection().georadiusByMember(key, longitude, latitude, member); -// } catch (Exception ex) { -// throw convertLettuceAccessException(ex); -// } -// } - /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisServerCommands#time() diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java index 5c88ccd215..30a747111d 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java @@ -52,6 +52,7 @@ import org.springframework.data.redis.connection.convert.LongToBooleanConverter; import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter; import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoRadiusParam; import org.springframework.data.redis.core.GeoRadiusResponse; import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.core.types.Expiration; @@ -94,6 +95,7 @@ abstract public class LettuceConverters extends Converters { private static final Converter GEO_COORDINATE_CONVERTER; private static final ListConverter GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; private static final Converter, List> BYTES_SET_TO_GEO_RADIUS_RESPONSE_LIST; + private static final Converter>, List> GEOWITHIN_LIST_TO_GEO_RADIUS_RESPONSE_LIST; public static final byte[] PLUS_BYTES; public static final byte[] MINUS_BYTES; @@ -314,6 +316,28 @@ public List convert(Set source) { } }; + GEOWITHIN_LIST_TO_GEO_RADIUS_RESPONSE_LIST = new Converter>, List>() { + + @Override + public List convert(List> source) { + + if (CollectionUtils.isEmpty(source)) { + return Collections.emptyList(); + } + + List geoRadiusResponses = new ArrayList(); + Iterator> it = source.iterator(); + while (it.hasNext()) { + GeoWithin geoWithin = it.next(); + GeoRadiusResponse geoRadiusResponse = new GeoRadiusResponse(geoWithin.member); + geoRadiusResponse.setCoordinate(new GeoCoordinate(geoWithin.coordinates.x.doubleValue(), + geoWithin.coordinates.y.doubleValue())); + geoRadiusResponse.setDistance(geoWithin.distance); + } + return geoRadiusResponses; + } + }; + } public static List toTuple(List list) { @@ -328,6 +352,10 @@ public static Converter, List> bytesSetToGeoRadiu return BYTES_SET_TO_GEO_RADIUS_RESPONSE_LIST; } + public static Converter>, List> getGeowithinListToGeoRadiusResponseList() { + return GEOWITHIN_LIST_TO_GEO_RADIUS_RESPONSE_LIST; + } + public static Converter> stringToRedisClientListConverter() { return new Converter>() { @@ -703,7 +731,22 @@ public static com.lambdaworks.redis.GeoArgs.Unit toGeoArgsUnit(GeoUnit geoUnit){ } } - public static redis.clients.jedis.GeoCoordinate toGeoCoordinate(GeoCoordinate geoCoordinate){ - return new redis.clients.jedis.GeoCoordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()); + public static com.lambdaworks.redis.GeoArgs toGeoArgs(GeoRadiusParam geoRadiusParam){ + com.lambdaworks.redis.GeoArgs geoArgs = new GeoArgs(); + for (String k : geoRadiusParam.getParams().keySet()){ + if (k.equals(GeoRadiusParam.getASC())) + geoArgs.asc(); + else if (k.equals(GeoRadiusParam.getDESC())) + geoArgs.desc(); + else if (k.equals(GeoRadiusParam.getCOUNT())) + geoArgs.withCount((Integer)geoRadiusParam.getParams().get(k)); + else if (k.equals(GeoRadiusParam.getWITHCOORD())) + geoArgs.withCoordinates(); + else if (k.equals(GeoRadiusParam.getWITHDIST())) + geoArgs.withDistance(); + else + throw new IllegalArgumentException("unknown key value"); + } + return geoArgs; } } diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java index 170367bfa4..535b56c6b0 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java @@ -44,10 +44,7 @@ import org.springframework.data.redis.connection.ReturnType; import org.springframework.data.redis.connection.SortParameters; import org.springframework.data.redis.connection.Subscription; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.GeoCoordinate; -import org.springframework.data.redis.core.GeoUnit; -import org.springframework.data.redis.core.ScanOptions; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; @@ -2273,7 +2270,27 @@ public List geoPos(byte[] key, byte[]... members) { throw new UnsupportedOperationException(); } - /** + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) { + throw new UnsupportedOperationException(); + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { + throw new UnsupportedOperationException(); + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) { + throw new UnsupportedOperationException(); + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) { + throw new UnsupportedOperationException(); + } + + /** * Specifies if pipelined results should be converted to the expected data type. If false, results of * {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Lettuce driver * diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java index 1ca84ece35..7a3e0ba28a 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java @@ -41,6 +41,8 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple; import org.springframework.data.redis.connection.StringRedisConnection.StringTuple; import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoRadiusParam; +import org.springframework.data.redis.core.GeoRadiusResponse; import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.serializer.StringRedisSerializer; @@ -89,12 +91,20 @@ public class DefaultStringRedisConnectionTests { protected Set stringTupleSet = new HashSet( Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar))); + protected GeoCoordinate geoCoordinate = new GeoCoordinate(213.00, 324.343); + protected List geoCoordinates = new ArrayList(); + + protected GeoRadiusResponse geoRadiusResponse = new GeoRadiusResponse(barBytes); + protected List geoRadiusResponses = new ArrayList(); + @Before public void setUp() { MockitoAnnotations.initMocks(this); this.connection = new DefaultStringRedisConnection(nativeConnection); bytesMap.put(fooBytes, barBytes); stringMap.put(foo, bar); + geoCoordinates.add(geoCoordinate); + geoRadiusResponses.add(geoRadiusResponse); } @Test @@ -1575,6 +1585,13 @@ public void testZUnionStore() { verifyResults(Arrays.asList(new Object[] { 5l })); } + @Test + public void testGeoAddBytes(){ + doReturn(1l).when(nativeConnection).geoAdd(fooBytes, 1.23232, 34.2342434, barBytes); + actual.add(connection.geoAdd(fooBytes, 1.23232, 34.2342434, barBytes)); + verifyResults(Arrays.asList(new Object[] { 1l })); + } + @Test public void testGeoAdd(){ doReturn(1l).when(nativeConnection).geoAdd(fooBytes, 1.23232, 34.2342434, barBytes); @@ -1582,18 +1599,34 @@ public void testGeoAdd(){ verifyResults(Arrays.asList(new Object[] { 1l })); } + @Test + public void testGeoAddCoordinateMapBytes(){ + Map memberGeoCoordinateMap = new HashMap(); + memberGeoCoordinateMap.put(barBytes, new GeoCoordinate(1.23232, 34.2342434)); + doReturn(1l).when(nativeConnection).geoAdd(fooBytes, memberGeoCoordinateMap); + + actual.add(connection.geoAdd(fooBytes, memberGeoCoordinateMap)); + verifyResults(Arrays.asList(new Object[] { 1l })); + } + @Test - public void testGeoAdd2(){ - Map memberGeoCoordinateMap = new HashMap(); - memberGeoCoordinateMap.put(barBytes, new GeoCoordinate(1.23232, 34.2342434)); - doReturn(1l).when(nativeConnection).geoAdd(fooBytes, memberGeoCoordinateMap); + public void testGeoAddCoordinateMap(){ + GeoCoordinate geoCoordinate = new GeoCoordinate(1.23232, 34.2342434); + doReturn(1l).when(nativeConnection).geoAdd(any(byte[].class), anyMapOf(byte[].class, GeoCoordinate.class)); Map stringGeoCoordinateMap = new HashMap(); - stringGeoCoordinateMap.put(bar, new GeoCoordinate(1.23232, 34.2342434)); + stringGeoCoordinateMap.put(bar, geoCoordinate); actual.add(connection.geoAdd(foo, stringGeoCoordinateMap)); verifyResults(Arrays.asList(new Object[] { 1l })); } + @Test + public void testGeoDistBytes(){ + doReturn(102121.12d).when(nativeConnection).geoDist(fooBytes, barBytes, bar2Bytes, GeoUnit.Meters); + actual.add(connection.geoDist(fooBytes, barBytes, bar2Bytes, GeoUnit.Meters)); + verifyResults(Arrays.asList(new Object[] { 102121.12d })); + } + @Test public void testGeoDist(){ doReturn(102121.12d).when(nativeConnection).geoDist(fooBytes, barBytes, bar2Bytes, GeoUnit.Meters); @@ -1601,6 +1634,15 @@ public void testGeoDist(){ verifyResults(Arrays.asList(new Object[] { 102121.12d })); } + @Test + public void testGeoHashBytes(){ + doReturn(bytesList).when(nativeConnection).geoHash(fooBytes, barBytes); + actual.add(connection.geoHash(fooBytes, barBytes)); + List expected = new ArrayList(); + expected.add(barBytes); + verifyResults(Arrays.asList(new Object[]{expected})); + } + @Test public void testGeoHash(){ doReturn(bytesList).when(nativeConnection).geoHash(fooBytes, barBytes); @@ -1610,15 +1652,121 @@ public void testGeoHash(){ verifyResults(Arrays.asList(new Object[]{expected})); } + @Test + public void testGeoPosBytes(){ + doReturn(geoCoordinates).when(nativeConnection).geoPos(fooBytes, barBytes); + actual.add(connection.geoPos(fooBytes, barBytes)); + verifyResults(Arrays.asList(new Object[] { geoCoordinates })); + } + @Test public void testGeoPos(){ - List geoCoordinates = new ArrayList(); - geoCoordinates.add(new GeoCoordinate(213.00, 324.343)); doReturn(geoCoordinates).when(nativeConnection).geoPos(fooBytes, barBytes); actual.add(connection.geoPos(foo, bar)); verifyResults(Arrays.asList(new Object[] { geoCoordinates })); } + @Test + public void testGeoRadiusWithoutParamBytes(){ + + doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet); + actual.add(connection.georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusWithoutParam(){ + doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet); + actual.add(connection.georadius(foo, 13.361389, 38.115556, 10, GeoUnit.Feet)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusWithDistBytes(){ + GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam(); + geoRadiusParam.withDist(); + doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam); + actual.add(connection.georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusWithDist(){ + GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam(); + geoRadiusParam.withDist(); + doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam); + actual.add(connection.georadius(foo, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusWithCoordAndDescBytes(){ + GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam(); + geoRadiusParam.withCoord().sortDescending(); + doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam); + actual.add(connection.georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusWithCoordAndDesc(){ + GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam(); + geoRadiusParam.withCoord().sortDescending(); + doReturn(geoRadiusResponses).when(nativeConnection).georadius(fooBytes, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam); + actual.add(connection.georadius(foo, 13.361389, 38.115556, 10, GeoUnit.Feet, geoRadiusParam)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusByMemberWithoutParamBytes(){ + doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet); + actual.add(connection.georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusByMemberWithoutParam(){ + doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet); + actual.add(connection.georadiusByMember(foo, bar, 38.115556, GeoUnit.Feet)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusByMemberWithDistAndAscBytes(){ + GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam(); + geoRadiusParam.withDist().sortAscending(); + doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam); + actual.add(connection.georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusByMemberWithDistAndAsc(){ + GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam(); + geoRadiusParam.withDist().sortAscending(); + doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam); + actual.add(connection.georadiusByMember(foo, bar, 38.115556, GeoUnit.Feet, geoRadiusParam)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusByMemberWithCoordAndCountBytes(){ + GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam(); + geoRadiusParam.withDist().count(23); + doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam); + actual.add(connection.georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + + @Test + public void testGeoRadiusByMemberWithCoordAndCount(){ + GeoRadiusParam geoRadiusParam = GeoRadiusParam.geoRadiusParam(); + geoRadiusParam.withDist().count(23); + doReturn(geoRadiusResponses).when(nativeConnection).georadiusByMember(fooBytes, barBytes, 38.115556, GeoUnit.Feet, geoRadiusParam); + actual.add(connection.georadiusByMember(foo, bar, 38.115556, GeoUnit.Feet, geoRadiusParam)); + verifyResults(Arrays.asList(new Object[] { geoRadiusResponses })); + } + @Test public void testPExpireBytes() { doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l); diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java index 88051a298d..0b1341109a 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java @@ -17,13 +17,14 @@ import static org.mockito.Mockito.*; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Properties; +import java.util.*; import org.junit.Before; import org.junit.Test; +import org.springframework.data.redis.core.GeoCoordinate; +import org.springframework.data.redis.core.GeoRadiusParam; +import org.springframework.data.redis.core.GeoRadiusResponse; +import org.springframework.data.redis.core.GeoUnit; /** * @author Jennifer Hickey @@ -1292,6 +1293,142 @@ public void testZUnionStore() { super.testZUnionStore(); } + @Test + public void testGeoAddBytes(){ + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + super.testGeoAddBytes(); + } + + @Test + public void testGeoAdd(){ + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + super.testGeoAddBytes(); + } + + @Test + public void testGeoAddCoordinateMapBytes(){ + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + super.testGeoAddCoordinateMapBytes(); + } + + @Test + public void testGeoAddCoordinateMap(){ + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + super.testGeoAddCoordinateMap(); + } + + @Test + public void testGeoDistBytes(){ + doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).exec(); + super.testGeoDistBytes(); + } + + @Test + public void testGeoDist(){ + doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).exec(); + super.testGeoDist(); + } + + @Test + public void testGeoHashBytes(){ + List expected = new ArrayList(); + expected.add(barBytes); + doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).exec(); + super.testGeoHashBytes(); + } + + @Test + public void testGeoHash(){ + List expected = new ArrayList(); + expected.add(barBytes); + doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).exec(); + super.testGeoHash(); + } + + @Test + public void testGeoPosBytes(){ + doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).exec(); + super.testGeoPosBytes(); + } + + @Test + public void testGeoPos(){ + doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).exec(); + super.testGeoPos(); + } + + @Test + public void testGeoRadiusWithoutParamBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusWithoutParamBytes(); + } + + @Test + public void testGeoRadiusWithoutParam(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusWithoutParam(); + } + + @Test + public void testGeoRadiusWithDistBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusWithDistBytes(); + } + + @Test + public void testGeoRadiusWithDist(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusWithDist(); + } + + @Test + public void testGeoRadiusWithCoordAndDescBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusWithCoordAndDescBytes(); + } + + @Test + public void testGeoRadiusWithCoordAndDesc(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusWithCoordAndDesc(); + } + + @Test + public void testGeoRadiusByMemberWithoutParamBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusByMemberWithoutParamBytes(); + } + + @Test + public void testGeoRadiusByMemberWithoutParam(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusByMemberWithoutParam(); + } + + @Test + public void testGeoRadiusByMemberWithDistAndAscBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusByMemberWithDistAndAscBytes(); + } + + @Test + public void testGeoRadiusByMemberWithDistAndAsc(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusByMemberWithDistAndAsc(); + } + + @Test + public void testGeoRadiusByMemberWithCoordAndCountBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusByMemberWithCoordAndCountBytes(); + } + + @Test + public void testGeoRadiusByMemberWithCoordAndCount(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).exec(); + super.testGeoRadiusByMemberWithCoordAndCount(); + } + @Test public void testPExpireBytes() { doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); diff --git a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java index 08983c5e85..6c28d812cb 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java @@ -28,10 +28,7 @@ import org.junit.Test; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder; -import org.springframework.data.redis.core.Cursor; -import org.springframework.data.redis.core.GeoCoordinate; -import org.springframework.data.redis.core.GeoUnit; -import org.springframework.data.redis.core.ScanOptions; +import org.springframework.data.redis.core.*; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.ObjectUtils; @@ -291,7 +288,27 @@ public List geoPos(byte[] key, byte[]... members) { return delegate.geoPos(key, members); } - public Set keys(byte[] pattern) { + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) { + return delegate.georadius(key, longitude, latitude, radius, unit); + } + + @Override + public List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { + return delegate.georadius(key, longitude, latitude, radius, unit, param); + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) { + return delegate.georadiusByMember(key, member, radius, unit); + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) { + return delegate.georadiusByMember(key, member, radius, unit, param); + } + + public Set keys(byte[] pattern) { return delegate.keys(pattern); } From 58cc21d2ee55384d89deaab76e9a0f1359a2b5c4 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Sat, 2 Apr 2016 16:35:37 -0700 Subject: [PATCH 10/15] DATAREDIS-438 pipeline tests --- ...ultStringRedisConnectionPipelineTests.java | 141 +++++++++++++++++- ...tStringRedisConnectionPipelineTxTests.java | 141 +++++++++++++++++- 2 files changed, 274 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java index b79477437e..bfce657dfe 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java @@ -17,10 +17,7 @@ import static org.mockito.Mockito.*; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Properties; +import java.util.*; import org.junit.Before; import org.junit.Test; @@ -1306,6 +1303,142 @@ public void testZUnionStore() { super.testZUnionStore(); } + @Test + public void testGeoAddBytes(){ + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + super.testGeoAddBytes(); + } + + @Test + public void testGeoAdd(){ + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + super.testGeoAddBytes(); + } + + @Test + public void testGeoAddCoordinateMapBytes(){ + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + super.testGeoAddCoordinateMapBytes(); + } + + @Test + public void testGeoAddCoordinateMap(){ + doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + super.testGeoAddCoordinateMap(); + } + + @Test + public void testGeoDistBytes(){ + doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).closePipeline(); + super.testGeoDistBytes(); + } + + @Test + public void testGeoDist(){ + doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).closePipeline(); + super.testGeoDist(); + } + + @Test + public void testGeoHashBytes(){ + List expected = new ArrayList(); + expected.add(barBytes); + doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).closePipeline(); + super.testGeoHashBytes(); + } + + @Test + public void testGeoHash(){ + List expected = new ArrayList(); + expected.add(barBytes); + doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).closePipeline(); + super.testGeoHash(); + } + + @Test + public void testGeoPosBytes(){ + doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).closePipeline(); + super.testGeoPosBytes(); + } + + @Test + public void testGeoPos(){ + doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).closePipeline(); + super.testGeoPos(); + } + + @Test + public void testGeoRadiusWithoutParamBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithoutParamBytes(); + } + + @Test + public void testGeoRadiusWithoutParam(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithoutParam(); + } + + @Test + public void testGeoRadiusWithDistBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithDistBytes(); + } + + @Test + public void testGeoRadiusWithDist(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithDist(); + } + + @Test + public void testGeoRadiusWithCoordAndDescBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithCoordAndDescBytes(); + } + + @Test + public void testGeoRadiusWithCoordAndDesc(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithCoordAndDesc(); + } + + @Test + public void testGeoRadiusByMemberWithoutParamBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithoutParamBytes(); + } + + @Test + public void testGeoRadiusByMemberWithoutParam(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithoutParam(); + } + + @Test + public void testGeoRadiusByMemberWithDistAndAscBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithDistAndAscBytes(); + } + + @Test + public void testGeoRadiusByMemberWithDistAndAsc(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithDistAndAsc(); + } + + @Test + public void testGeoRadiusByMemberWithCoordAndCountBytes(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithCoordAndCountBytes(); + } + + @Test + public void testGeoRadiusByMemberWithCoordAndCount(){ + doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithCoordAndCount(); + } + @Test public void testPExpireBytes() { doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java index 29354d0695..264bbd6e34 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java @@ -4,10 +4,7 @@ import static org.mockito.Mockito.when; import static org.junit.Assert.assertEquals; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Properties; +import java.util.*; import org.junit.Before; import org.junit.Test; @@ -1390,6 +1387,142 @@ public void testZUnionStore() { super.testZUnionStore(); } + @Test + public void testGeoAddBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + super.testGeoAddBytes(); + } + + @Test + public void testGeoAdd(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + super.testGeoAddBytes(); + } + + @Test + public void testGeoAddCoordinateMapBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + super.testGeoAddCoordinateMapBytes(); + } + + @Test + public void testGeoAddCoordinateMap(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline(); + super.testGeoAddCoordinateMap(); + } + + @Test + public void testGeoDistBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 102121.12d }) })).when(nativeConnection).closePipeline(); + super.testGeoDistBytes(); + } + + @Test + public void testGeoDist(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 102121.12d }) })).when(nativeConnection).closePipeline(); + super.testGeoDist(); + } + + @Test + public void testGeoHashBytes(){ + List expected = new ArrayList(); + expected.add(barBytes); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { expected }) })).when(nativeConnection).closePipeline(); + super.testGeoHashBytes(); + } + + @Test + public void testGeoHash(){ + List expected = new ArrayList(); + expected.add(barBytes); + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { expected }) })).when(nativeConnection).closePipeline(); + super.testGeoHash(); + } + + @Test + public void testGeoPosBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoCoordinates }) })).when(nativeConnection).closePipeline(); + super.testGeoPosBytes(); + } + + @Test + public void testGeoPos(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoCoordinates }) })).when(nativeConnection).closePipeline(); + super.testGeoPos(); + } + + @Test + public void testGeoRadiusWithoutParamBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithoutParamBytes(); + } + + @Test + public void testGeoRadiusWithoutParam(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithoutParam(); + } + + @Test + public void testGeoRadiusWithDistBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithDistBytes(); + } + + @Test + public void testGeoRadiusWithDist(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithDist(); + } + + @Test + public void testGeoRadiusWithCoordAndDescBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithCoordAndDescBytes(); + } + + @Test + public void testGeoRadiusWithCoordAndDesc(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusWithCoordAndDesc(); + } + + @Test + public void testGeoRadiusByMemberWithoutParamBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithoutParamBytes(); + } + + @Test + public void testGeoRadiusByMemberWithoutParam(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithoutParam(); + } + + @Test + public void testGeoRadiusByMemberWithDistAndAscBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithDistAndAscBytes(); + } + + @Test + public void testGeoRadiusByMemberWithDistAndAsc(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithDistAndAsc(); + } + + @Test + public void testGeoRadiusByMemberWithCoordAndCountBytes(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithCoordAndCountBytes(); + } + + @Test + public void testGeoRadiusByMemberWithCoordAndCount(){ + doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { geoRadiusResponses }) })).when(nativeConnection).closePipeline(); + super.testGeoRadiusByMemberWithCoordAndCount(); + } + @Test public void testPExpireBytes() { doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) From 8357529043c036c1e8f0787d9b3f8005a8c2bb81 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Sat, 2 Apr 2016 17:19:11 -0700 Subject: [PATCH 11/15] DATAREDIS-438 adding to defaultGeoOperations and adding integration tests --- .../redis/connection/RedisGeoCommands.java | 107 ++++++++++++++++++ .../data/redis/core/DefaultGeoOperations.java | 50 ++++++++ .../data/redis/core/GeoOperations.java | 12 ++ .../redis/core/DefaultGeoOperationsTests.java | 45 +++++++- 4 files changed, 208 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java index 9306f20e66..ba485f8934 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java @@ -45,25 +45,132 @@ public interface RedisGeoCommands { */ Long geoAdd(byte[] key, double longitude, double latitude, byte[] member); + /** + * Add latitude and longitude for a given key with a name. + * Returns the number of elements added to the sorted set, not including elements already existing for which the + * score was updated. + *

+ * @see http://redis.io/commands/geoadd + * + * @param key + * @param memberCoordinateMap + * @return + */ Long geoAdd(byte[] key, Map memberCoordinateMap); + /** + * Return the distance between two members in the geospatial index represented by the sorted set. + *

+ * @see http://redis.io/commands/geodist + * + * @param key + * @param member1 + * @param member2 + * @return + */ Double geoDist(byte[] key, byte[] member1, byte[] member2); + /** + * Return the distance between two members in the geospatial index represented by the sorted set. + *

+ * @see http://redis.io/commands/geodist + * + * @param key + * @param member1 + * @param member2 + * @param unit + * @return + */ Double geoDist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit); + /** + * Return valid Geohash strings representing the position of one or more elements in a sorted set value + * representing a geospatial index (where elements were added using GEOADD). + *

+ * @see http://redis.io/commands/geohash + * + * @param key + * @param members + * @return + */ List geoHash(byte[] key, byte[]... members); + /** + * Return the positions (longitude,latitude) of all the specified members of the geospatial index represented by + * the sorted set at key. + *

+ * @see http://redis.io/commands/geopos + * + * @param key + * @param members + * @return + */ List geoPos(byte[] key, byte[]... members); + /** + * Return the members of a sorted set populated with geospatial information using GEOADD, which are within + * the borders of the area specified with the center location and the maximum distance from the radius. + *

+ * @see http://redis.io/commands/georadius + * + * @param key + * @param longitude + * @param latitude + * @param radius + * @param unit + * @return + */ List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit); + /** + * Return the members of a sorted set populated with geospatial information using GEOADD, which are within + * the borders of the area specified with the center location and the maximum distance from the radius. + *

+ * @see http://redis.io/commands/georadius + * + * @param key + * @param longitude + * @param latitude + * @param radius + * @param unit + * @param param + * @return + */ List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param); + /** + * Add latitude and longitude for a given key with a name. + * Returns the number of elements added to the sorted set, not including elements already existing for which the + * score was updated. + *

+ * @see http://redis.io/commands/georadiusbymember + * + * @param key + * @param member + * @param radius + * @param unit + * @return + */ List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit); + /** + * This command is exactly like GEORADIUS with the sole difference that instead of taking, as the center of + * the area to query, a longitude and latitude value, it takes the name of a member already existing inside + * the geospatial index represented by the sorted set. + *

+ * @see http://redis.io/commands/georadiusbymember + * + * @param key + * @param member + * @param radius + * @param unit + * @param param + * + * @return + */ List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java index 30125e56c7..8c90279bd7 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java @@ -114,4 +114,54 @@ public List doInRedis(RedisConnection connection) { } }, true); } + + @Override + public List georadius(K key, final double longitude, final double latitude, final double radius, final GeoUnit unit) { + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback>() { + + public List doInRedis(RedisConnection connection) { + return connection.georadius(rawKey, longitude, latitude, radius, unit); + } + }, true); + } + + @Override + public List georadius(K key, final double longitude, final double latitude, final double radius, final GeoUnit unit, final GeoRadiusParam param) { + final byte[] rawKey = rawKey(key); + + return execute(new RedisCallback>() { + + public List doInRedis(RedisConnection connection) { + return connection.georadius(rawKey, longitude, latitude, radius, unit, param); + } + }, true); + } + + @Override + public List georadiusByMember(K key, M member, final double radius, final GeoUnit unit) { + final byte[] rawKey = rawKey(key); + final byte[] rawMember = rawValue(member); + + return execute(new RedisCallback>() { + + public List doInRedis(RedisConnection connection) { + return connection.georadiusByMember(rawKey, rawMember, radius, unit); + } + }, true); + } + + @Override + public List georadiusByMember(K key, M member, final double radius, final GeoUnit unit, final GeoRadiusParam param) { + final byte[] rawKey = rawKey(key); + final byte[] rawMember = rawValue(member); + + return execute(new RedisCallback>() { + + public List doInRedis(RedisConnection connection) { + return connection.georadiusByMember(rawKey, rawMember, radius, unit, param); + } + }, true); + } } diff --git a/src/main/java/org/springframework/data/redis/core/GeoOperations.java b/src/main/java/org/springframework/data/redis/core/GeoOperations.java index 7c70031699..7c50b24131 100644 --- a/src/main/java/org/springframework/data/redis/core/GeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/GeoOperations.java @@ -35,4 +35,16 @@ public interface GeoOperations { List geoHash(K key, M... members); List geoPos(K key, M... members); + + List georadius(K key, double longitude, double latitude, + double radius, GeoUnit unit); + + List georadius(K key, double longitude, double latitude, + double radius, GeoUnit unit, GeoRadiusParam param); + + List georadiusByMember(K key, M member, double radius, + GeoUnit unit); + + List georadiusByMember(K key, M member, double radius, + GeoUnit unit, GeoRadiusParam param); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java index dd53d77154..f5bfdae009 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java @@ -16,6 +16,7 @@ package org.springframework.data.redis.core; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -87,9 +88,6 @@ public void testGeoAdd() throws Exception { M v1 = valueFactory.instance(); Long numAdded = geoOperations.geoAdd(key, 13.361389, 38.115556, v1); assertEquals(numAdded.longValue(), 1L); - -// numAdded = geoOperations.geoAdd("Sicily", 15.087269, 37.502669, "Catania"); -// assertEquals(numAdded.longValue(), 2L); } @Test @@ -100,9 +98,6 @@ public void testGeoAdd2() throws Exception { memberCoordinateMap.put(valueFactory.instance(), new GeoCoordinate(12.993, 31.3994)); Long numAdded = geoOperations.geoAdd(key, memberCoordinateMap); assertEquals(numAdded.longValue(), 2L); - -// numAdded = geoOperations.geoAdd("Sicily", 15.087269, 37.502669, "Catania"); -// assertEquals(numAdded.longValue(), 2L); } @Test @@ -166,4 +161,42 @@ public void testGeoPos() throws Exception { assertNull(result.get(2)); } + + @Test + public void testGeoRadius() throws Exception{ + K key = keyFactory.instance(); + M v1 = valueFactory.instance(); + M v2 = valueFactory.instance(); + + geoOperations.geoAdd(key, 13.361389, 38.115556, v1); + geoOperations.geoAdd(key, 15.087269, 37.502669, v2); + + List result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters); + Assert.assertEquals(2, result.size()); + + // with dist, descending + result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withDist().sortDescending()); + Assert.assertEquals(2, result.size()); + Assert.assertEquals(result.get(0).getDistance(), 190.4424d, 0.0001); + Assert.assertEquals(result.get(1).getDistance(), 56.4413d, 0.0001); + + // with coord, ascending + result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().sortAscending()); + Assert.assertEquals(2, result.size()); + Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001); + Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 38.115556395496299d, 0.0001); + Assert.assertEquals(result.get(0).getCoordinate().getLongitude(), 15.087267458438873d, 0.0001); + Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 37.50266842333162d, 0.0001); + + // with coord and dist, ascending + result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().withDist().sortAscending()); + Assert.assertEquals(2, result.size()); + + Assert.assertEquals(result.get(0).getDistance(), 56.4413d, 0.0001); + Assert.assertEquals(result.get(0).getCoordinate().getLongitude(), 15.087267458438873d, 0.0001); + Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 37.50266842333162d, 0.0001); + Assert.assertEquals(result.get(1).getDistance(), 190.4424d, 0.0001); + Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001); + Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 38.115556395496299d, 0.0001); + } } From 4069e7503ee024b1be0579915546ceb426fccc6b Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Sat, 2 Apr 2016 18:06:06 -0700 Subject: [PATCH 12/15] DATAREDIS-438 adding geoRemove --- .../DefaultStringRedisConnection.java | 10 ++ .../redis/connection/RedisGeoCommands.java | 38 ++++-- .../connection/StringRedisConnection.java | 125 ++++++++++++++++++ .../jedis/JedisClusterConnection.java | 12 +- .../connection/jedis/JedisConnection.java | 6 +- .../connection/jredis/JredisConnection.java | 5 + .../connection/lettuce/LettuceConnection.java | 11 +- .../redis/connection/srp/SrpConnection.java | 5 + .../data/redis/core/BoundGeoOperations.java | 14 ++ .../redis/core/DefaultBoundGeoOperations.java | 25 ++++ .../data/redis/core/DefaultGeoOperations.java | 13 ++ .../data/redis/core/GeoOperations.java | 2 + .../connection/RedisConnectionUnitTests.java | 5 + .../redis/core/DefaultGeoOperationsTests.java | 53 ++++++++ 14 files changed, 303 insertions(+), 21 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 e29f5747c8..341423eb8e 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -2450,6 +2450,16 @@ public List georadiusByMember(byte[] key, byte[] member, doub return result; } + @Override + public Long geoRemove(byte[] key, byte[]... values) { + return zRem(key, values); + } + + @Override + public Long geoRemove(String key, String... members) { + return zRem(key, members); + } + public List closePipeline() { try { return convertResults(delegate.closePipeline(), pipelineConverters); diff --git a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java index ba485f8934..6109f16a3f 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java @@ -35,7 +35,7 @@ public interface RedisGeoCommands { * Returns the number of elements added to the sorted set, not including elements already existing for which the * score was updated. *

- * @see http://redis.io/commands/geoadd + * @link http://redis.io/commands/geoadd * * @param key * @param member @@ -50,7 +50,7 @@ public interface RedisGeoCommands { * Returns the number of elements added to the sorted set, not including elements already existing for which the * score was updated. *

- * @see http://redis.io/commands/geoadd + * @link http://redis.io/commands/geoadd * * @param key * @param memberCoordinateMap @@ -61,7 +61,7 @@ public interface RedisGeoCommands { /** * Return the distance between two members in the geospatial index represented by the sorted set. *

- * @see http://redis.io/commands/geodist + * @link http://redis.io/commands/geodist * * @param key * @param member1 @@ -73,7 +73,7 @@ public interface RedisGeoCommands { /** * Return the distance between two members in the geospatial index represented by the sorted set. *

- * @see http://redis.io/commands/geodist + * @link http://redis.io/commands/geodist * * @param key * @param member1 @@ -87,7 +87,7 @@ public interface RedisGeoCommands { * Return valid Geohash strings representing the position of one or more elements in a sorted set value * representing a geospatial index (where elements were added using GEOADD). *

- * @see http://redis.io/commands/geohash + * @link http://redis.io/commands/geohash * * @param key * @param members @@ -99,7 +99,7 @@ public interface RedisGeoCommands { * Return the positions (longitude,latitude) of all the specified members of the geospatial index represented by * the sorted set at key. *

- * @see http://redis.io/commands/geopos + * @link http://redis.io/commands/geopos * * @param key * @param members @@ -111,7 +111,7 @@ public interface RedisGeoCommands { * Return the members of a sorted set populated with geospatial information using GEOADD, which are within * the borders of the area specified with the center location and the maximum distance from the radius. *

- * @see http://redis.io/commands/georadius + * @link http://redis.io/commands/georadius * * @param key * @param longitude @@ -127,7 +127,7 @@ List georadius(byte[] key, double longitude, double latitude, * Return the members of a sorted set populated with geospatial information using GEOADD, which are within * the borders of the area specified with the center location and the maximum distance from the radius. *

- * @see http://redis.io/commands/georadius + * @link http://redis.io/commands/georadius * * @param key * @param longitude @@ -141,16 +141,17 @@ List georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param); /** - * Add latitude and longitude for a given key with a name. - * Returns the number of elements added to the sorted set, not including elements already existing for which the - * score was updated. + * This command is exactly like GEORADIUS with the sole difference that instead of taking, as the center of + * the area to query, a longitude and latitude value, it takes the name of a member already existing inside + * the geospatial index represented by the sorted set. *

- * @see http://redis.io/commands/georadiusbymember + * @link http://redis.io/commands/georadiusbymember * * @param key * @param member * @param radius * @param unit + * * @return */ List georadiusByMember(byte[] key, byte[] member, double radius, @@ -161,7 +162,7 @@ List georadiusByMember(byte[] key, byte[] member, double radi * the area to query, a longitude and latitude value, it takes the name of a member already existing inside * the geospatial index represented by the sorted set. *

- * @see http://redis.io/commands/georadiusbymember + * @link http://redis.io/commands/georadiusbymember * * @param key * @param member @@ -173,4 +174,15 @@ List georadiusByMember(byte[] key, byte[] member, double radi */ List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param); + + /** + * Redis does not have a georem command, so this command just maps to zrem + *

+ * @link http://redis.io/commands/geoadd + * + * @param key + * @param values + * @return + */ + Long geoRemove(byte[] key, byte[]... values); } 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 91ff7d2faa..9f20632054 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -622,27 +622,152 @@ public interface StringTuple extends Tuple { */ Set zRangeByLex(String key, Range range, Limit limit); + /** + * Add latitude and longitude for a {@member} with a given {@key}. + * Returns the number of elements added to the sorted set, not including elements already existing for which the + * score was updated. + *

+ * @link http://redis.io/commands/geoadd + * + * @param key + * @param member + * @param longitude + * @param latitude + * @return + */ Long geoAdd(String key, double longitude, double latitude, String member); + /** + * Add memberCoordinateMap with a given {@key}. + * Returns the number of elements added to the sorted set, not including elements already existing for which the + * score was updated. + *

+ * @link http://redis.io/commands/geoadd + * + * @param key + * @param memberCoordinateMap + * @return + */ Long geoAdd(String key, Map memberCoordinateMap); + /** + * Return the distance between {@member1} and {@member2} in the geospatial index represented by the sorted set. + * The unit in which the distance is returned is meters. + *

+ * @link http://redis.io/commands/geodist + * + * @param key + * @param member1 + * @param member2 + * @return + */ Double geoDist(String key, String member1, String member2); + /** + * Return the distance in {@unit} between {@member1} and {@member2} in the geospatial index represented by the sorted set. + *

+ * @link http://redis.io/commands/geodist + * + * @param key + * @param member1 + * @param member2 + * @return + */ Double geoDist(String key, String member1, String member2, GeoUnit unit); + /** + * Return valid Geohash strings representing the position of one or more {@values} + * representing a geospatial index (where elements were added using GEOADD). + *

+ * @link http://redis.io/commands/geohash + * + * @param key + * @param values + * @return + */ List geoHash(String key, String... values); + /** + * Return the positions (longitude,latitude) in GeoCoordinate of all the specified {@members} of the geospatial index represented by + * the sorted set at key. + *

+ * @link http://redis.io/commands/geopos + * + * @param key + * @param members + * @return + */ List geoPos(String key, String... members); + /** + * Return the members of a sorted set populated with geospatial information using GEOADD, which are within + * the borders of the area specified with the center location given by {@longitude} and {@latitude} and + * the maximum distance from the {@radius}. + *

+ * @link http://redis.io/commands/georadius + * + * @param key + * @param longitude + * @param latitude + * @param radius + * @param unit + * @return + */ List georadius(String key, double longitude, double latitude, double radius, GeoUnit unit); + /** + * Return the members of a sorted set populated with geospatial information using GEOADD, which are within + * the borders of the area specified with the center location given by {@longitude} and {@latitude} and + * the maximum distance from the {@radius}. {@param} can be passed to get coordinates, distance and sort the values + *

+ * @link http://redis.io/commands/georadius + * + * @param key + * @param longitude + * @param latitude + * @param radius + * @param unit + * @param param + * @return + */ List georadius(String key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param); + /** + * This command is exactly like GEORADIUS with the sole difference that instead of taking, as the center of + * the area to query, a longitude and latitude value, it takes the name of a member already existing inside + * the geospatial index represented by the sorted set. + *

+ * @link http://redis.io/commands/georadiusbymember + * + * @param key + * @param member + * @param radius + * @param unit + * + * @return + */ List georadiusByMember(String key, String member, double radius, GeoUnit unit); + /** + * This command is exactly like GEORADIUS with the sole difference that instead of taking, as the center of + * the area to query, a longitude and latitude value, it takes the name of a member already existing inside + * the geospatial index represented by the sorted set. + *

+ * @link http://redis.io/commands/georadiusbymember + * + * @param key + * @param member + * @param radius + * @param unit + * @param param + * + * @return + */ List georadiusByMember(String key, String member, double radius, GeoUnit unit, GeoRadiusParam param); + + Long geoRemove(String key, String... members); } diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java index b6888e6c74..d38a8678c9 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java @@ -2606,11 +2606,15 @@ public List georadiusByMember(byte[] key, byte[] member, doub } } + @Override + public Long geoRemove(byte[] key, byte[]... values) { + return zRem(key, values); + } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisConnectionCommands#select(int) - */ + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisConnectionCommands#select(int) + */ @Override public void select(final int dbIndex) { 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 bb9099784a..41910f815e 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 @@ -3263,8 +3263,12 @@ public List georadiusByMember(byte[] key, byte[] member, doub } } + @Override + public Long geoRemove(byte[] key, byte[]... values) { + return zRem(key, values); + } - // + // // Scripting commands // 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 d4dd197e75..b147b25669 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 @@ -1245,6 +1245,11 @@ public List georadiusByMember(byte[] key, byte[] member, doub throw new UnsupportedOperationException(); } + @Override + public Long geoRemove(byte[] key, byte[]... values) { + throw new UnsupportedOperationException(); + } + // // Scripting commands // diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java index 2fcc4f35e1..ea54364d9a 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java @@ -3226,10 +3226,15 @@ public List georadiusByMember(byte[] key, byte[] member, doub } } + @Override + public Long geoRemove(byte[] key, byte[]... values) { + return zRem(key, values); + } + /* - * (non-Javadoc) - * @see org.springframework.data.redis.connection.RedisServerCommands#time() - */ + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisServerCommands#time() + */ @Override public Long time() { try { diff --git a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java index 535b56c6b0..8512d02d56 100644 --- a/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/srp/SrpConnection.java @@ -2290,6 +2290,11 @@ public List georadiusByMember(byte[] key, byte[] member, doub throw new UnsupportedOperationException(); } + @Override + public Long geoRemove(byte[] key, byte[]... values) { + throw new UnsupportedOperationException(); + } + /** * Specifies if pipelined results should be converted to the expected data type. If false, results of * {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Lettuce driver diff --git a/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java index babea1099d..6e0f4cc3ed 100644 --- a/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java @@ -35,4 +35,18 @@ public interface BoundGeoOperations extends BoundKeyOperations { List geoHash(K key, M... members); List geoPos(K key, M... members); + + List georadius(K key, double longitude, double latitude, + double radius, GeoUnit unit); + + List georadius(K key, double longitude, double latitude, + double radius, GeoUnit unit, GeoRadiusParam param); + + List georadiusByMember(K key, M member, double radius, + GeoUnit unit); + + List georadiusByMember(K key, M member, double radius, + GeoUnit unit, GeoRadiusParam param); + + Long geoRemove(K key, M... members); } diff --git a/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java index e6042db79c..22ff893b83 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java @@ -69,6 +69,31 @@ public List geoPos(K key, M... members) { return ops.geoPos(key, members); } + @Override + public List georadius(K key, double longitude, double latitude, double radius, GeoUnit unit) { + return ops.georadius(key, longitude, latitude, radius, unit); + } + + @Override + public List georadius(K key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { + return ops.georadius(key, longitude, latitude, radius, unit, param); + } + + @Override + public List georadiusByMember(K key, M member, double radius, GeoUnit unit) { + return ops.georadiusByMember(key, member, radius, unit); + } + + @Override + public List georadiusByMember(K key, M member, double radius, GeoUnit unit, GeoRadiusParam param) { + return ops.georadiusByMember(key, member, radius, unit, param); + } + + @Override + public Long geoRemove(K key, M... members) { + return ops.geoRemove(key, members); + } + @Override public DataType getType() { return DataType.STRING; diff --git a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java index 8c90279bd7..53f9071883 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java @@ -164,4 +164,17 @@ public List doInRedis(RedisConnection connection) { } }, true); } + + @Override + public Long geoRemove(K key, M... members) { + final byte[] rawKey = rawKey(key); + final byte[][] rawMembers = rawValues(members); + + return execute(new RedisCallback() { + + public Long doInRedis(RedisConnection connection) { + return connection.zRem(rawKey, rawMembers); + } + }, true); + } } diff --git a/src/main/java/org/springframework/data/redis/core/GeoOperations.java b/src/main/java/org/springframework/data/redis/core/GeoOperations.java index 7c50b24131..8a2a322064 100644 --- a/src/main/java/org/springframework/data/redis/core/GeoOperations.java +++ b/src/main/java/org/springframework/data/redis/core/GeoOperations.java @@ -47,4 +47,6 @@ List georadiusByMember(K key, M member, double radius, List georadiusByMember(K key, M member, double radius, GeoUnit unit, GeoRadiusParam param); + + Long geoRemove(K key, M... members); } diff --git a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java index 6c28d812cb..1d1b484069 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java @@ -308,6 +308,11 @@ public List georadiusByMember(byte[] key, byte[] member, doub return delegate.georadiusByMember(key, member, radius, unit, param); } + @Override + public Long geoRemove(byte[] key, byte[]... values) { + return zRem(key, values); + } + public Set keys(byte[] pattern) { return delegate.keys(pattern); } diff --git a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java index f5bfdae009..5007bd1774 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java @@ -199,4 +199,57 @@ public void testGeoRadius() throws Exception{ Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001); Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 38.115556395496299d, 0.0001); } + + @Test + public void testGeoRadiusByMember() throws Exception{ + K key = keyFactory.instance(); + M v1 = valueFactory.instance(); + M v2 = valueFactory.instance(); + M v3 = valueFactory.instance(); + + geoOperations.geoAdd(key, 13.361389, 38.115556, v1);//palermo + geoOperations.geoAdd(key, 15.087269, 37.502669, v2);//catania + + geoOperations.geoAdd(key, 13.583333, 37.316667, v3);//Agrigento + + List result = geoOperations.georadiusByMember(key, v3, 200, GeoUnit.KiloMeters); + Assert.assertEquals(3, result.size()); + + // with dist, descending + result = geoOperations.georadiusByMember(key, v3, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withDist().sortDescending()); + Assert.assertEquals(2, result.size()); + Assert.assertEquals(result.get(0).getDistance(), 90.9778d, 0.0001); + Assert.assertEquals(result.get(1).getDistance(), 0.0d, 0.0001); //itself + + // with coord, ascending + result = geoOperations.georadiusByMember(key, v3, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().sortAscending()); + Assert.assertEquals(2, result.size()); + Assert.assertEquals(result.get(0).getCoordinate().getLongitude(), 13.583331406116486d, 0.0001); + Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 37.316668049938166d, 0.0001); + Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001); + Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 38.115556395496299d, 0.0001); + + + // with coord and dist, ascending + result = geoOperations.georadiusByMember(key, v1, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().withDist().sortAscending()); + Assert.assertEquals(2, result.size()); + + Assert.assertEquals(result.get(0).getDistance(), 0.0d, 0.0001); + Assert.assertEquals(result.get(0).getCoordinate().getLongitude(), 13.361389338970184d, 0.0001); + Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 38.1155563954963d, 0.0001); + Assert.assertEquals(result.get(1).getDistance(), 90.9778d, 0.0001); + Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.583331406116486d, 0.0001); + Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 37.316668049938166d, 0.0001); + } + + @Test + public void testGeoRemove(){ + K key = keyFactory.instance(); + M v1 = valueFactory.instance(); + Long numAdded = geoOperations.geoAdd(key, 13.361389, 38.115556, v1); + assertEquals(numAdded.longValue(), 1L); + + Long numRemoved = geoOperations.geoRemove(key, v1); + assertEquals(1L, numRemoved.longValue()); + } } From bea29c92ff4c6d2bfc89fcf585a8f52a6e7abe0c Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Mon, 4 Apr 2016 11:04:58 -0700 Subject: [PATCH 13/15] bumping up spring redis version to 3.2.0 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7c843b7890..7f3160abd1 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -REDIS_VERSION:=3.0.7 +REDIS_VERSION:=3.2.0 SPRING_PROFILE?=ci ####### From 4ebd24c242b3502932684702c56bdc59af21b0e8 Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Mon, 4 Apr 2016 11:08:25 -0700 Subject: [PATCH 14/15] adding rc3 to the REDIS_VERSION --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7f3160abd1..900fafad67 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -REDIS_VERSION:=3.2.0 +REDIS_VERSION:=3.2.0-rc3 SPRING_PROFILE?=ci ####### From 199899144b7239cad71f9236c05b9861a21a11dd Mon Sep 17 00:00:00 2001 From: Ninad Divadkar Date: Fri, 8 Apr 2016 09:56:10 -0700 Subject: [PATCH 15/15] config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6. applying mp911de's suggestion to get a mod of 6 --- .../redis/connection/jedis/JedisClusterConnectionTests.java | 4 +++- .../connection/lettuce/LettuceClusterConnectionTests.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java index 7120084696..2b8803b03c 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java @@ -2291,7 +2291,9 @@ public void getConfigShouldLoadCumulatedConfiguration() { List result = clusterConnection.getConfig("*max-*-entries*"); - assertThat(result.size(), is(24)); + // config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6. + // @link https://github.com/spring-projects/spring-data-redis/pull/187 + assertThat(result.size() % 6, is(0)); for (int i = 0; i < result.size(); i++) { if (i % 2 == 0) { diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java index 00d8741393..0416846e90 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java @@ -2276,7 +2276,9 @@ public void getConfigShouldLoadCumulatedConfiguration() { List result = clusterConnection.getConfig("*max-*-entries*"); - assertThat(result.size(), is(24)); + // config get *max-*-entries on redis 3.0.7 returns 8 entries per node while on 3.2.0-rc3 returns 6. + // @link https://github.com/spring-projects/spring-data-redis/pull/187 + assertThat(result.size() % 6, is(0)); for (int i = 0; i < result.size(); i++) { if (i % 2 == 0) {