diff --git a/Makefile b/Makefile index 7c843b789..900fafad6 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-rc3 SPRING_PROFILE?=ci ####### 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 91b6e92f8..341423eb8 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.RedisSystemException; 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; @@ -280,7 +270,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco delegate.flushDb(); } - public byte[] get(byte[] key) { + public byte[] get(byte[] key) { byte[] result = delegate.get(key); if (isFutureConversion()) { addResultConverter(identityConverter); @@ -2280,6 +2270,196 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco 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; + } + + @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; + } + + @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/RedisCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisCommands.java index 1da8cda6f..47a9579fe 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 @@ package org.springframework.data.redis.connection; */ 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 000000000..6109f16a3 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/connection/RedisGeoCommands.java @@ -0,0 +1,188 @@ +/* + * 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; + + +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; +import java.util.Map; + +/** + * 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. + *

+ * @link http://redis.io/commands/geoadd + * + * @param key + * @param member + * @param longitude + * @param latitude + * @return + */ + 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. + *

+ * @link 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. + *

+ * @link 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. + *

+ * @link 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). + *

+ * @link 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. + *

+ * @link 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. + *

+ * @link 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. + *

+ * @link 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); + + /** + * 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(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. + *

+ * @link 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); + + /** + * 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 3056c871f..9f2063205 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.List; 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,152 @@ public interface StringRedisConnection extends RedisConnection { */ 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 f7a87624b..d38a8678c 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,8 @@ import org.springframework.data.redis.connection.SortParameters; 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.GeoRadiusResponse; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.data.redis.util.ByteUtils; @@ -70,12 +57,9 @@ import org.springframework.util.Assert; 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.GeoCoordinate; +import redis.clients.jedis.GeoUnit; /** * {@link RedisClusterConnection} implementation on top of {@link JedisCluster}.
@@ -2511,10 +2495,126 @@ public class JedisClusterConnection implements RedisClusterConnection { } } + @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); + } + } + + @Override + 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, redisGeoCoordinateMap); + } 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, org.springframework.data.redis.core.GeoUnit unit) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + try { + return cluster.geodist(key, member1, member2, geoUnit); + } 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 JedisConverters.geoCoordinateListToGeoCoordinateList().convert(cluster.geopos(key, members)); + } 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); + } + } + + @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 94ffd486a..41910f815 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 @@ package org.springframework.data.redis.connection.jedis; 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,9 @@ import org.springframework.data.redis.connection.SortParameters; 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.GeoRadiusResponse; import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; @@ -61,22 +50,9 @@ import org.springframework.util.ClassUtils; 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.util.Pool; @@ -95,696 +71,698 @@ import redis.clients.util.Pool; */ 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 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 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); + /** + * 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.pool = pool; - this.dbIndex = dbIndex; + 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; - } - } - } + // 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; - } + 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 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,2293 +770,2505 @@ public class JedisConnection extends AbstractRedisConnection { * 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) { + if (seconds > Integer.MAX_VALUE) { - return pExpireAt(key, time() + TimeUnit.SECONDS.toMillis(seconds)); - } + return pExpireAt(key, time() + TimeUnit.SECONDS.toMillis(seconds)); + } - 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); - } - } + 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 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 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 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 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 void multi() { - if (isQueueing()) { - return; - } - try { - if (isPipelined()) { - pipeline.multi(); - return; - } - this.transaction = jedis.multi(); - } 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 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 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 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 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 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 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 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 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 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 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 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 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 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) { + 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); - } - } + 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 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 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 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 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 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 void restore(byte[] key, long ttlInMillis, byte[] serializedValue) { + public void restore(byte[] key, long ttlInMillis, byte[] serializedValue) { - 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); - } - } + 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); + } + } - 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 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 unwatch() { - try { - jedis.unwatch(); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + public void unwatch() { + try { + jedis.unwatch(); + } 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 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); + } + } - // - // String commands - // + // + // String commands + // - 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; - } + 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; + } - return jedis.get(key); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + return jedis.get(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 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); + } + } - /* + /* * (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) { + @Override + public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) { - if (expiration == null || expiration.isPersistent()) { + if (expiration == null || expiration.isPersistent()) { - if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) { - set(key, value); - } else { + if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) { + set(key, value); + } else { - try { + try { - byte[] nxxx = JedisConverters.toSetCommandNxXxArgument(option); + byte[] nxxx = JedisConverters.toSetCommandNxXxArgument(option); - if (isPipelined()) { + if (isPipelined()) { - pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx))); - return; - } - if (isQueueing()) { + pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx))); + return; + } + if (isQueueing()) { - transaction(new JedisStatusResult(transaction.set(key, value, nxxx))); - return; - } + transaction(new JedisStatusResult(transaction.set(key, value, nxxx))); + return; + } - jedis.set(key, value, nxxx); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } + jedis.set(key, value, nxxx); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } - } else { + } else { - if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) { + if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) { - if (ObjectUtils.nullSafeEquals(TimeUnit.MILLISECONDS, expiration.getTimeUnit())) { - pSetEx(key, expiration.getExpirationTime(), value); - } else { - setEx(key, expiration.getExpirationTime(), value); - } - } else { + if (ObjectUtils.nullSafeEquals(TimeUnit.MILLISECONDS, expiration.getTimeUnit())) { + pSetEx(key, expiration.getExpirationTime(), value); + } else { + setEx(key, expiration.getExpirationTime(), value); + } + } else { - byte[] nxxx = JedisConverters.toSetCommandNxXxArgument(option); - byte[] expx = JedisConverters.toSetCommandExPxArgument(expiration); + byte[] nxxx = JedisConverters.toSetCommandNxXxArgument(option); + byte[] expx = JedisConverters.toSetCommandExPxArgument(expiration); - try { - if (isPipelined()) { + try { + if (isPipelined()) { - if (expiration.getExpirationTime() > Integer.MAX_VALUE) { + if (expiration.getExpirationTime() > Integer.MAX_VALUE) { - throw new IllegalArgumentException( - "Expiration.expirationTime must be less than Integer.MAX_VALUE for pipeline in Jedis."); - } + throw new IllegalArgumentException( + "Expiration.expirationTime must be less than Integer.MAX_VALUE for pipeline in Jedis."); + } - pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx, expx, (int) expiration.getExpirationTime()))); - return; - } - if (isQueueing()) { + pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx, expx, (int) expiration.getExpirationTime()))); + return; + } + if (isQueueing()) { - if (expiration.getExpirationTime() > Integer.MAX_VALUE) { - throw new IllegalArgumentException( - "Expiration.expirationTime must be less than Integer.MAX_VALUE for transactions in Jedis."); - } + if (expiration.getExpirationTime() > Integer.MAX_VALUE) { + throw new IllegalArgumentException( + "Expiration.expirationTime must be less than Integer.MAX_VALUE for transactions in Jedis."); + } - transaction(new JedisStatusResult(transaction.set(key, value, nxxx, expx, - (int) expiration.getExpirationTime()))); - return; - } + transaction(new JedisStatusResult(transaction.set(key, value, nxxx, expx, + (int) expiration.getExpirationTime()))); + return; + } - jedis.set(key, value, nxxx, expx, expiration.getExpirationTime()); + jedis.set(key, value, nxxx, expx, expiration.getExpirationTime()); - } catch (Exception ex) { - throw convertJedisAccessException(ex); - } - } - } - } + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + } + } - 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); - } - } + 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); + } + } - 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); - } - } + 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); + } + } - 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 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 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 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) { + 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."); - } + 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); - } - } + 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 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 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 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 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 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 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 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 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 Boolean setBit(byte[] key, long offset, boolean value) { - try { - if (isPipelined()) { + public Boolean setBit(byte[] key, long offset, boolean value) { + try { + if (isPipelined()) { - 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); - } - } + 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 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 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 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 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) { - 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 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 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, 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 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 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); + } + } - // - // List commands - // + // + // List commands + // - 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 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 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 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 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 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 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 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[] 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 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 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 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 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[] 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 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 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 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 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 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 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 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 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 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[] 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 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 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 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 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[] 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 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 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 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 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); + } + } - // - // Set commands - // + // + // Set commands + // - 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 List sRandMember(byte[] key, long count) { + public List sRandMember(byte[] key, long count) { - if (count > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Count must be less than Integer.MAX_VALUE for sRandMember in Jedis."); - } + if (count > Integer.MAX_VALUE) { + throw new IllegalArgumentException("Count must be less than Integer.MAX_VALUE for sRandMember in Jedis."); + } - 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); - } - } + 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 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); - } - } + 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); + } + } - 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 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 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 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); + } + } - // - // ZSet commands - // + // + // 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 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 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 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 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 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); - } - } + 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) { + @Override + public Set zRangeByScoreWithScores(byte[] key, Range range, Limit limit) { - Assert.notNull(range, "Range cannot be null for ZRANGEBYSCOREWITHSCORES."); + 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); + 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; - } + 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 (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); - } - } + 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); - } + 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); + 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); - } - } + 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 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 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 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 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 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 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 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, 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.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); - } - } + 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, 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 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); + } + } - // - // Hash commands - // + // + // Hash commands + // - 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 + // + @Override + 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); + } + } + + @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) { + GeoUnit geoUnit = JedisConverters.toGeoUnit(unit); + try { + if (isPipelined()) { + pipeline(new JedisResult(pipeline.geodist(key, member1, member2, geoUnit))); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.geodist(key, member1, member2, geoUnit))); + return null; + } + + return jedis.geodist(key, member1, member2, geoUnit); + } 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), JedisConverters.geoCoordinateListToGeoCoordinateList())); + return null; + } + if (isQueueing()) { + transaction(new JedisResult(transaction.geopos(key, members), JedisConverters.geoCoordinateListToGeoCoordinateList())); + 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, 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); + } + } + + @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/jedis/JedisConverters.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java index c241c60a6..8cd082b78 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,10 @@ import org.springframework.data.redis.connection.convert.ListConverter; import org.springframework.data.redis.connection.convert.MapConverter; import org.springframework.data.redis.connection.convert.SetConverter; import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter; +import org.springframework.data.redis.core.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; import org.springframework.data.redis.core.types.RedisClientInfo; @@ -79,6 +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_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; @@ -165,6 +173,27 @@ abstract public class JedisConverters extends Converters { } }; + + 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() { @@ -201,6 +230,10 @@ abstract public class JedisConverters extends Converters { return EXCEPTION_CONVERTER; } + 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]; for (int i = 0; i < source.length; i++) { @@ -456,4 +489,41 @@ abstract public class JedisConverters extends Converters { 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.MI; + 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 = 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 9f44e22fb..b147b2566 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,8 +45,7 @@ import org.springframework.data.redis.connection.RedisNode; 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.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; @@ -1187,14 +1186,74 @@ public class JredisConnection extends AbstractRedisConnection { 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(); + } + + @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(); + } + + @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(); + } + + @Override + public Long geoRemove(byte[] key, byte[]... values) { + 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 d7b312ca2..ea54364d9 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.ExecutionException; 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; @@ -56,12 +57,8 @@ import org.springframework.data.redis.connection.SortParameters; 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.*; 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.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.util.Assert; @@ -69,25 +66,6 @@ import org.springframework.util.ClassUtils; 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; @@ -3079,10 +3057,184 @@ public class LettuceConnection extends AbstractRedisConnection { } } + // + // 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); + } + } + + @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) { + GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit); + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit))); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().geodist(key, member1, member2, geoUnit))); + return null; + } + return getConnection().geodist(key, member1, member2, geoUnit); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List geoHash(byte[] key, byte[]... members) { + throw new UnsupportedOperationException(); + } + + @Override + public List geoPos(byte[] key, byte[]... members) { + try { + if (isPipelined()) { + pipeline(new LettuceResult(getAsyncConnection().geopos(key, members), LettuceConverters.geoCoordinateListToGeoCoordinateList())); + return null; + } + if (isQueueing()) { + transaction(new LettuceTxResult(getConnection().geopos(key, members), LettuceConverters.geoCoordinateListToGeoCoordinateList())); + return null; + } + return LettuceConverters.geoCoordinateListToGeoCoordinateList().convert(getConnection().geopos(key, members)); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @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); + GeoArgs geoArgs = LettuceConverters.toGeoArgs(param); + try { + if (isPipelined()) { + 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, geoArgs), + LettuceConverters.getGeowithinListToGeoRadiusResponseList())); + return null; + } + return LettuceConverters.getGeowithinListToGeoRadiusResponseList(). + convert(getConnection().georadius(key, longitude, latitude, radius, geoUnit, geoArgs)); + } catch (Exception ex) { + throw convertLettuceAccessException(ex); + } + } + + @Override + public List georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) { + 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) { + 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 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/lettuce/LettuceConverters.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java index 9d57b17c2..30a747111 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.Map; 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,19 @@ import org.springframework.data.redis.connection.ReturnType; 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.GeoRadiusParam; +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; 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 +92,10 @@ 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; + 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; @@ -284,6 +289,55 @@ abstract public class LettuceConverters extends Converters { 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); + + 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; + } + }; + + 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) { @@ -294,6 +348,14 @@ abstract public class LettuceConverters extends Converters { return BYTES_LIST_TO_TUPLE_LIST_CONVERTER; } + public static Converter, List> bytesSetToGeoRadiusResponseListConverter() { + 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>() { @@ -344,6 +406,8 @@ abstract public class LettuceConverters extends Converters { return EXCEPTION_CONVERTER; } + public static ListConverter geoCoordinateListToGeoCoordinateList() { return GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; } + /** * @return * @sice 1.3 @@ -657,4 +721,32 @@ abstract public class LettuceConverters extends Converters { 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 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 acbc966ec..8512d02d5 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,8 +44,7 @@ import org.springframework.data.redis.connection.RedisSubscribedConnectionExcept 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.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; @@ -2241,6 +2240,61 @@ public class SrpConnection extends AbstractRedisConnection { } } + @Override + 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(); + } + + @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(); + } + + @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 new file mode 100644 index 000000000..6e0f4cc3e --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/BoundGeoOperations.java @@ -0,0 +1,52 @@ +/* + * 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 java.util.List; +import java.util.Map; + +/** + * 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); + + 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); + + 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 new file mode 100644 index 000000000..22ff893b8 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/DefaultBoundGeoOperations.java @@ -0,0 +1,101 @@ +/* + * 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.List; +import java.util.Map; +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 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 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 new file mode 100644 index 000000000..53f907188 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/DefaultGeoOperations.java @@ -0,0 +1,180 @@ +/* + * 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; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 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); + } + + @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); + } + + @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); + } + + @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/GeoCoordinate.java b/src/main/java/org/springframework/data/redis/core/GeoCoordinate.java new file mode 100644 index 000000000..504905951 --- /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/GeoOperations.java b/src/main/java/org/springframework/data/redis/core/GeoOperations.java new file mode 100644 index 000000000..8a2a32206 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/GeoOperations.java @@ -0,0 +1,52 @@ +/* + * 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 java.util.List; +import java.util.Map; + +/** + * Redis operations for geo commands. + * + * @author Ninad Divadkar + */ +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); + + 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/GeoOperationsEditor.java b/src/main/java/org/springframework/data/redis/core/GeoOperationsEditor.java new file mode 100644 index 000000000..e36a02364 --- /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/GeoRadiusParam.java b/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java new file mode 100644 index 000000000..4ecd887c0 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/core/GeoRadiusParam.java @@ -0,0 +1,88 @@ +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); + } + + 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 000000000..8da66467d --- /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; + } +} 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 000000000..d31918d4a --- /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; +} 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 061b47e56..8f006c817 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 446df60da..0a827c347 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 @@ public interface RedisOperations { */ BoundHashOperations boundHashOps(K key); + /** + * Returns the operations performed on geo values. + * + * @return geo operations + */ + GeoOperations opsForGeo(); + + /** + * Returns the operations performed on values bound to the given key. + * + * @param key Redis key + * @return geo 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 f2b9677ce..af16e0e18 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -98,6 +98,7 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation private ListOperations listOps; private SetOperations setOps; private ZSetOperations zSetOps; + private GeoOperations geoOps; private HyperLogLogOperations hllOps; /** @@ -1006,10 +1007,23 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation 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/DefaultStringRedisConnectionPipelineTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java index b79477437..bfce657df 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 @@ package org.springframework.data.redis.connection; 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 class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi 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 29354d069..264bbd6e3 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.doReturn; 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 class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe 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) 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 81230bf10..7a3e0ba28 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,10 @@ import org.springframework.data.redis.connection.RedisStringCommands.BitOperatio 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.GeoRadiusParam; +import org.springframework.data.redis.core.GeoRadiusResponse; +import org.springframework.data.redis.core.GeoUnit; import org.springframework.data.redis.serializer.StringRedisSerializer; /** @@ -62,10 +66,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); @@ -83,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 @@ -1570,6 +1586,188 @@ public class DefaultStringRedisConnectionTests { } @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); + actual.add(connection.geoAdd(foo, 1.23232, 34.2342434, bar)); + 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 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, 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); + actual.add(connection.geoDist(foo, bar, bar2, GeoUnit.Meters)); + 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); + actual.add(connection.geoHash(foo, bar)); + List expected = new ArrayList(); + expected.add(bar); + 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(){ + 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); actual.add(connection.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 88051a298..0b1341109 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 @@ package org.springframework.data.redis.connection; 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 class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne 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 cb2d660c6..1d1b48406 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java @@ -28,8 +28,7 @@ import org.junit.Before; 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.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; @@ -260,6 +259,60 @@ public class RedisConnectionUnitTests { delegate.subscribe(listener, channels); } + 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); + } + + @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); + } + + @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/connection/jedis/JedisClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java index 712008469..2b8803b03 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 class JedisClusterConnectionTests implements ClusterConnectionTests { 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 00d874139..0416846e9 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 class LettuceClusterConnectionTests implements ClusterConnectionTests { 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/core/DefaultGeoOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java new file mode 100644 index 000000000..5007bd177 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java @@ -0,0 +1,255 @@ +/* + * 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.Assert; +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 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.*; +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.DefaultGeoOperations} + * + * @author Ninad Divadkar + */ +@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(); + M v1 = valueFactory.instance(); + Long numAdded = geoOperations.geoAdd(key, 13.361389, 38.115556, v1); + assertEquals(numAdded.longValue(), 1L); + } + + @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); + } + + @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)); + } + + @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); + } + + @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()); + } +}