DATAREDIS-438 - Polishing.
RedisGeoCommands now take and return Spring Data domain types like Distance and GeoResults. Updated JavaDoc and Reference documentation. Added and updated author and license headers. Fixed minor formatting and code style issues. Original Pulll Request: #187
This commit is contained in:
2
Makefile
2
Makefile
@@ -12,7 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
REDIS_VERSION:=3.2.0-rc3
|
REDIS_VERSION:=3.2.0
|
||||||
SPRING_PROFILE?=ci
|
SPRING_PROFILE?=ci
|
||||||
|
|
||||||
#######
|
#######
|
||||||
|
|||||||
@@ -3,6 +3,17 @@
|
|||||||
|
|
||||||
New and noteworthy in the latest releases.
|
New and noteworthy in the latest releases.
|
||||||
|
|
||||||
|
[[new-in-1.8.0]]
|
||||||
|
== New in Spring Data Redis 1.8
|
||||||
|
|
||||||
|
* Support for Redis http://redis.io/commands#geo[GEO] commands.
|
||||||
|
|
||||||
|
[[new-in-1.7.0]]
|
||||||
|
== New in Spring Data Redis 1.7
|
||||||
|
|
||||||
|
* Support for http://redis.io/topics/cluster-tutorial[RedisCluster].
|
||||||
|
* Support for Spring Data Repository abstractions (see <<redis.repositories>>).
|
||||||
|
|
||||||
[[new-in-1-6-0]]
|
[[new-in-1-6-0]]
|
||||||
== New in Spring Data Redis 1.6
|
== New in Spring Data Redis 1.6
|
||||||
|
|
||||||
|
|||||||
@@ -235,6 +235,9 @@ Moreover, the template provides operations views (following the grouping from Re
|
|||||||
|HyperLogLogOperations
|
|HyperLogLogOperations
|
||||||
|Redis HyperLogLog operations like (pfadd, pfcount,...)
|
|Redis HyperLogLog operations like (pfadd, pfcount,...)
|
||||||
|
|
||||||
|
|GeoOperations
|
||||||
|
|Redis geospatial operations like `GEOADD`, `GEORADIUS`,...)
|
||||||
|
|
||||||
2+^|_Key Bound Operations_
|
2+^|_Key Bound Operations_
|
||||||
|
|
||||||
|BoundValueOperations
|
|BoundValueOperations
|
||||||
@@ -251,6 +254,9 @@ Moreover, the template provides operations views (following the grouping from Re
|
|||||||
|
|
||||||
|BoundHashOperations
|
|BoundHashOperations
|
||||||
|Redis hash key bound operations
|
|Redis hash key bound operations
|
||||||
|
|
||||||
|
|BoundGeoOperations
|
||||||
|
|Redis key bound geospatial operations.
|
||||||
|====
|
|====
|
||||||
|
|
||||||
Once configured, the template is thread-safe and can be reused across multiple instances.
|
Once configured, the template is thread-safe and can be reused across multiple instances.
|
||||||
|
|||||||
@@ -15,17 +15,34 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.connection;
|
package org.springframework.data.redis.connection;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.RedisSystemException;
|
import org.springframework.data.redis.RedisSystemException;
|
||||||
|
import org.springframework.data.redis.connection.convert.Converters;
|
||||||
import org.springframework.data.redis.connection.convert.ListConverter;
|
import org.springframework.data.redis.connection.convert.ListConverter;
|
||||||
import org.springframework.data.redis.connection.convert.MapConverter;
|
import org.springframework.data.redis.connection.convert.MapConverter;
|
||||||
import org.springframework.data.redis.connection.convert.SetConverter;
|
import org.springframework.data.redis.connection.convert.SetConverter;
|
||||||
import org.springframework.data.redis.core.*;
|
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.types.Expiration;
|
import org.springframework.data.redis.core.types.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
@@ -40,6 +57,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
public class DefaultStringRedisConnection implements StringRedisConnection, DecoratedRedisConnection {
|
public class DefaultStringRedisConnection implements StringRedisConnection, DecoratedRedisConnection {
|
||||||
|
|
||||||
@@ -56,6 +74,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
|||||||
private ListConverter<byte[], String> byteListToStringList = new ListConverter<byte[], String>(bytesToString);
|
private ListConverter<byte[], String> byteListToStringList = new ListConverter<byte[], String>(bytesToString);
|
||||||
private MapConverter<byte[], String> byteMapToStringMap = new MapConverter<byte[], String>(bytesToString);
|
private MapConverter<byte[], String> byteMapToStringMap = new MapConverter<byte[], String>(bytesToString);
|
||||||
private SetConverter<byte[], String> byteSetToStringSet = new SetConverter<byte[], String>(bytesToString);
|
private SetConverter<byte[], String> byteSetToStringSet = new SetConverter<byte[], String>(bytesToString);
|
||||||
|
private Converter<GeoResults<GeoLocation<byte[]>>, GeoResults<GeoLocation<String>>> byteGeoResultsToStringGeoResults;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes") private Queue<Converter> pipelineConverters = new LinkedList<Converter>();
|
@SuppressWarnings("rawtypes") private Queue<Converter> pipelineConverters = new LinkedList<Converter>();
|
||||||
@SuppressWarnings("rawtypes") private Queue<Converter> txConverters = new LinkedList<Converter>();
|
@SuppressWarnings("rawtypes") private Queue<Converter> txConverters = new LinkedList<Converter>();
|
||||||
private boolean deserializePipelineAndTxResults = false;
|
private boolean deserializePipelineAndTxResults = false;
|
||||||
@@ -105,9 +125,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
|||||||
* @param connection Redis connection
|
* @param connection Redis connection
|
||||||
*/
|
*/
|
||||||
public DefaultStringRedisConnection(RedisConnection connection) {
|
public DefaultStringRedisConnection(RedisConnection connection) {
|
||||||
Assert.notNull(connection, "connection is required");
|
this(connection, new StringRedisSerializer());
|
||||||
this.delegate = connection;
|
|
||||||
this.serializer = new StringRedisSerializer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,10 +135,13 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
|||||||
* @param serializer String serializer
|
* @param serializer String serializer
|
||||||
*/
|
*/
|
||||||
public DefaultStringRedisConnection(RedisConnection connection, RedisSerializer<String> serializer) {
|
public DefaultStringRedisConnection(RedisConnection connection, RedisSerializer<String> serializer) {
|
||||||
|
|
||||||
Assert.notNull(connection, "connection is required");
|
Assert.notNull(connection, "connection is required");
|
||||||
Assert.notNull(connection, "serializer is required");
|
Assert.notNull(serializer, "serializer is required");
|
||||||
|
|
||||||
this.delegate = connection;
|
this.delegate = connection;
|
||||||
this.serializer = serializer;
|
this.serializer = serializer;
|
||||||
|
this.byteGeoResultsToStringGeoResults = Converters.deserializingGeoResultsConverter(serializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long append(byte[] key, byte[] value) {
|
public Long append(byte[] key, byte[] value) {
|
||||||
@@ -270,7 +291,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
|||||||
delegate.flushDb();
|
delegate.flushDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] get(byte[] key) {
|
public byte[] get(byte[] key) {
|
||||||
byte[] result = delegate.get(key);
|
byte[] result = delegate.get(key);
|
||||||
if (isFutureConversion()) {
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
@@ -2270,194 +2291,362 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member){
|
* (non-Javadoc)
|
||||||
Long result = delegate.geoAdd(key, longitude, latitude, member);
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.geo.Point, byte[])
|
||||||
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<byte[], GeoCoordinate> memberCoordinateMap) {
|
|
||||||
Long result = delegate.geoAdd(key, memberCoordinateMap);
|
|
||||||
if (isFutureConversion()){
|
|
||||||
addResultConverter(identityConverter);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long geoAdd(String key, Map<String, GeoCoordinate> memberCoordinateMap) {
|
|
||||||
Map<byte[], GeoCoordinate> byteMap = new HashMap<byte[], GeoCoordinate>();
|
|
||||||
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<byte[]> geoHash(byte[] key, byte[]... members) {
|
|
||||||
List<byte[]> result = delegate.geoHash(key, members);
|
|
||||||
if (isFutureConversion()){
|
|
||||||
addResultConverter(identityConverter);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> geoHash(String key, String... members) {
|
|
||||||
List<byte[]> result = delegate.geoHash(serialize(key), serializeMulti(members));
|
|
||||||
if (isFutureConversion()){
|
|
||||||
addResultConverter(byteListToStringList);
|
|
||||||
}
|
|
||||||
return byteListToStringList.convert(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoCoordinate> geoPos(byte[] key, byte[]... members) {
|
|
||||||
List<GeoCoordinate> result = delegate.geoPos(key, members);
|
|
||||||
if (isFutureConversion()){
|
|
||||||
addResultConverter(identityConverter);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoCoordinate> geoPos(String key, String... members) {
|
|
||||||
List<GeoCoordinate> result = delegate.geoPos(serialize(key), serializeMulti(members));
|
|
||||||
if (isFutureConversion()){
|
|
||||||
addResultConverter(identityConverter);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(String key, double longitude, double latitude, double radius, GeoUnit unit) {
|
public Long geoAdd(byte[] key, Point point, byte[] member) {
|
||||||
List<GeoRadiusResponse> result = delegate.georadius(serialize(key), longitude, latitude, radius, unit);
|
|
||||||
if (isFutureConversion()){
|
Long result = delegate.geoAdd(key, point, member);
|
||||||
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<GeoRadiusResponse> georadius(String key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
|
* (non-Javadoc)
|
||||||
List<GeoRadiusResponse> result = delegate.georadius(serialize(key), longitude, latitude, radius, unit, param);
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
|
||||||
if (isFutureConversion()){
|
*/
|
||||||
|
public Long geoAdd(byte[] key, GeoLocation<byte[]> location) {
|
||||||
|
|
||||||
|
Long result = delegate.geoAdd(key, location);
|
||||||
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoAdd(java.lang.String, org.springframework.data.geo.Point, java.lang.String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius, GeoUnit unit) {
|
public Long geoAdd(String key, Point point, String member) {
|
||||||
List<GeoRadiusResponse> result = delegate.georadiusByMember(serialize(key), serialize(member), radius, unit);
|
return geoAdd(serialize(key), point, serialize(member));
|
||||||
if (isFutureConversion()){
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoAdd(java.lang.String, org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(String key, GeoLocation<String> location) {
|
||||||
|
|
||||||
|
Assert.notNull(location, "Location must not be null!");
|
||||||
|
return geoAdd(key, location.getPoint(), location.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.util.Map)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) {
|
||||||
|
|
||||||
|
Long result = delegate.geoAdd(key, memberCoordinateMap);
|
||||||
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.lang.Iterable)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) {
|
||||||
List<GeoRadiusResponse> result = delegate.georadiusByMember(serialize(key), serialize(member), radius, unit, param);
|
|
||||||
if (isFutureConversion()){
|
Long result = delegate.geoAdd(key, locations);
|
||||||
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoAdd(java.lang.String, java.util.Map)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) {
|
public Long geoAdd(String key, Map<String, Point> memberCoordinateMap) {
|
||||||
List<GeoRadiusResponse> result = delegate.georadius(key, longitude, latitude, radius, unit);
|
|
||||||
if (isFutureConversion()){
|
Assert.notNull(memberCoordinateMap, "MemberCoordinateMap must not be null!");
|
||||||
|
|
||||||
|
Map<byte[], Point> byteMap = new HashMap<byte[], Point>();
|
||||||
|
for (Entry<String, Point> entry : memberCoordinateMap.entrySet()) {
|
||||||
|
byteMap.put(serialize(entry.getKey()), memberCoordinateMap.get(entry.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return geoAdd(serialize(key), byteMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoAdd(java.lang.String, java.lang.Iterable)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(String key, Iterable<GeoLocation<String>> locations) {
|
||||||
|
|
||||||
|
Assert.notNull(locations, "Locations must not be null!");
|
||||||
|
|
||||||
|
Map<byte[], Point> byteMap = new HashMap<byte[], Point>();
|
||||||
|
for (GeoLocation<String> location : locations) {
|
||||||
|
byteMap.put(serialize(location.getName()), location.getPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
return geoAdd(serialize(key), byteMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
|
||||||
|
|
||||||
|
Distance result = delegate.geoDist(key, member1, member2);
|
||||||
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoDist(java.lang.String, java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Distance geoDist(String key, String member1, String member2) {
|
||||||
List<GeoRadiusResponse> result = delegate.georadius(key, longitude, latitude, radius, unit, param);
|
return geoDist(serialize(key), serialize(member1), serialize(member2));
|
||||||
if (isFutureConversion()){
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[], org.springframework.data.geo.Metric)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) {
|
||||||
|
|
||||||
|
Distance result = delegate.geoDist(key, member1, member2, metric);
|
||||||
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoDist(java.lang.String, java.lang.String, java.lang.String, org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) {
|
public Distance geoDist(String key, String member1, String member2, Metric metric) {
|
||||||
List<GeoRadiusResponse> result = delegate.georadiusByMember(key, member, radius, unit);
|
return geoDist(serialize(key), serialize(member1), serialize(member2), metric);
|
||||||
if (isFutureConversion()){
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoHash(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> geoHash(byte[] key, byte[]... members) {
|
||||||
|
|
||||||
|
List<String> result = delegate.geoHash(key, members);
|
||||||
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoHash(java.lang.String, java.lang.String[])
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public List<String> geoHash(String key, String... members) {
|
||||||
List<GeoRadiusResponse> result = delegate.georadiusByMember(key, member, radius, unit, param);
|
|
||||||
if (isFutureConversion()){
|
List<String> result = delegate.geoHash(serialize(key), serializeMulti(members));
|
||||||
|
if (isFutureConversion()) {
|
||||||
addResultConverter(identityConverter);
|
addResultConverter(identityConverter);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoPos(byte[], byte[][])
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long geoRemove(byte[] key, byte[]... values) {
|
public List<Point> geoPos(byte[] key, byte[]... members) {
|
||||||
return zRem(key, values);
|
|
||||||
|
List<Point> result = delegate.geoPos(key, members);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(identityConverter);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoPos(java.lang.String, java.lang.String[])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Point> geoPos(String key, String... members) {
|
||||||
|
return geoPos(serialize(key), serializeMulti(members));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#georadius(java.lang.String, org.springframework.data.geo.Circle)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<String>> georadius(String key, Circle within) {
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = delegate.geoRadius(serialize(key), within);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(byteGeoResultsToStringGeoResults);
|
||||||
|
}
|
||||||
|
|
||||||
|
return byteGeoResultsToStringGeoResults.convert(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#georadius(java.lang.String, org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<String>> georadius(String key, Circle within, GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = delegate.geoRadius(serialize(key), within, args);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(byteGeoResultsToStringGeoResults);
|
||||||
|
}
|
||||||
|
return byteGeoResultsToStringGeoResults.convert(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#georadiusByMember(java.lang.String, java.lang.String, double)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<String>> georadiusByMember(String key, String member, double radius) {
|
||||||
|
return georadiusByMember(key, member, new Distance(radius, DistanceUnit.METERS));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#georadiusByMember(java.lang.String, java.lang.String, org.springframework.data.geo.Distance)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<String>> georadiusByMember(String key, String member, Distance radius) {
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = delegate.geoRadiusByMember(serialize(key), serialize(member), radius);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(byteGeoResultsToStringGeoResults);
|
||||||
|
}
|
||||||
|
return byteGeoResultsToStringGeoResults.convert(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#georadiusByMember(java.lang.String, java.lang.String, org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<String>> georadiusByMember(String key, String member, Distance radius,
|
||||||
|
GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = delegate.geoRadiusByMember(serialize(key), serialize(member), radius,
|
||||||
|
args);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(byteGeoResultsToStringGeoResults);
|
||||||
|
}
|
||||||
|
return byteGeoResultsToStringGeoResults.convert(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = delegate.geoRadius(key, within);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(identityConverter);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = delegate.geoRadius(key, within, args);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(identityConverter);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], double)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, double radius) {
|
||||||
|
return geoRadiusByMember(key, member, new Distance(radius, DistanceUnit.METERS));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = delegate.geoRadiusByMember(key, member, radius);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(identityConverter);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
|
||||||
|
GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = delegate.geoRadiusByMember(key, member, radius, args);
|
||||||
|
if (isFutureConversion()) {
|
||||||
|
addResultConverter(identityConverter);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoRemove(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoRemove(byte[] key, byte[]... members) {
|
||||||
|
return zRem(key, members);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.StringRedisConnection#geoRemove(java.lang.String, java.lang.String[])
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long geoRemove(String key, String... members) {
|
public Long geoRemove(String key, String... members) {
|
||||||
return zRem(key, members);
|
return geoRemove(serialize(key), serializeMulti(members));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Object> closePipeline() {
|
public List<Object> closePipeline() {
|
||||||
@@ -2684,30 +2873,31 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
|||||||
@Override
|
@Override
|
||||||
public Cursor<Entry<String, String>> hScan(String key, ScanOptions options) {
|
public Cursor<Entry<String, String>> hScan(String key, ScanOptions options) {
|
||||||
|
|
||||||
return new ConvertingCursor<Map.Entry<byte[], byte[]>, Map.Entry<String, String>>(this.delegate.hScan(
|
return new ConvertingCursor<Map.Entry<byte[], byte[]>, Map.Entry<String, String>>(
|
||||||
this.serialize(key), options), new Converter<Map.Entry<byte[], byte[]>, Map.Entry<String, String>>() {
|
this.delegate.hScan(this.serialize(key), options),
|
||||||
|
new Converter<Map.Entry<byte[], byte[]>, Map.Entry<String, String>>() {
|
||||||
@Override
|
|
||||||
public Entry<String, String> convert(final Entry<byte[], byte[]> source) {
|
|
||||||
return new Map.Entry<String, String>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public Entry<String, String> convert(final Entry<byte[], byte[]> source) {
|
||||||
return bytesToString.convert(source.getKey());
|
return new Map.Entry<String, String>() {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue() {
|
public String getKey() {
|
||||||
return bytesToString.convert(source.getValue());
|
return bytesToString.convert(source.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String setValue(String value) {
|
public String getValue() {
|
||||||
throw new UnsupportedOperationException("Cannot set value for entry in cursor");
|
return bytesToString.convert(source.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String setValue(String value) {
|
||||||
|
throw new UnsupportedOperationException("Cannot set value for entry in cursor");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2014 the original author or authors.
|
* Copyright 2011-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 the original author or authors.
|
* Copyright 2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,174 +15,356 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.connection;
|
package org.springframework.data.redis.connection;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
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.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Sort.Direction;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Geo-specific Redis commands.
|
* Geo-specific Redis commands.
|
||||||
*
|
*
|
||||||
* @author Ninad Divadkar
|
* @author Ninad Divadkar
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public interface RedisGeoCommands {
|
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.
|
|
||||||
* <p>
|
|
||||||
* @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.
|
* Add {@link Point} with given member {@literal name} to {@literal key}.
|
||||||
* Returns the number of elements added to the sorted set, not including elements already existing for which the
|
*
|
||||||
* score was updated.
|
* @param key must not be {@literal null}.
|
||||||
* <p>
|
* @param point must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/geoadd
|
* @param member must not be {@literal null}.
|
||||||
*
|
* @return Number of elements added.
|
||||||
* @param key
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
* @param memberCoordinateMap
|
*/
|
||||||
* @return
|
Long geoAdd(byte[] key, Point point, byte[] member);
|
||||||
*/
|
|
||||||
Long geoAdd(byte[] key, Map<byte[], GeoCoordinate> memberCoordinateMap);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the distance between two members in the geospatial index represented by the sorted set.
|
* Add {@link GeoLocation} to {@literal key}.
|
||||||
* <p>
|
*
|
||||||
* @link http://redis.io/commands/geodist
|
* @param key must not be {@literal null}.
|
||||||
*
|
* @param location must not be {@literal null}.
|
||||||
* @param key
|
* @return Number of elements added.
|
||||||
* @param member1
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
* @param member2
|
*/
|
||||||
* @return
|
Long geoAdd(byte[] key, GeoLocation<byte[]> location);
|
||||||
*/
|
|
||||||
Double geoDist(byte[] key, byte[] member1, byte[] member2);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the distance between two members in the geospatial index represented by the sorted set.
|
* Add {@link Map} of member / {@link Point} pairs to {@literal key}.
|
||||||
* <p>
|
*
|
||||||
* @link http://redis.io/commands/geodist
|
* @param key must not be {@literal null}.
|
||||||
*
|
* @param memberCoordinateMap must not be {@literal null}.
|
||||||
* @param key
|
* @return Number of elements added.
|
||||||
* @param member1
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
* @param member2
|
*/
|
||||||
* @param unit
|
Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap);
|
||||||
* @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
|
* Add {@link GeoLocation}s to {@literal key}
|
||||||
* representing a geospatial index (where elements were added using GEOADD).
|
*
|
||||||
* <p>
|
* @param key must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/geohash
|
* @param locations must not be {@literal null}.
|
||||||
*
|
* @return Number of elements added.
|
||||||
* @param key
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
* @param members
|
*/
|
||||||
* @return
|
Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations);
|
||||||
*/
|
|
||||||
List<byte[]> geoHash(byte[] key, byte[]... members);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the positions (longitude,latitude) of all the specified members of the geospatial index represented by
|
* Get the {@link Distance} between {@literal member1} and {@literal member2}.
|
||||||
* the sorted set at key.
|
*
|
||||||
* <p>
|
* @param key must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/geopos
|
* @param member1 must not be {@literal null}.
|
||||||
*
|
* @param member2 must not be {@literal null}.
|
||||||
* @param key
|
* @return can be {@literal null}.
|
||||||
* @param members
|
* @see <a href="http://redis.io/commands/geodist">http://redis.io/commands/geodist</a>
|
||||||
* @return
|
*/
|
||||||
*/
|
Distance geoDist(byte[] key, byte[] member1, byte[] member2);
|
||||||
List<GeoCoordinate> geoPos(byte[] key, byte[]... members);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the members of a sorted set populated with geospatial information using GEOADD, which are within
|
* Get the {@link Distance} between {@literal member1} and {@literal member2} in the given {@link Metric}.
|
||||||
* the borders of the area specified with the center location and the maximum distance from the radius.
|
*
|
||||||
* <p>
|
* @param key must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/georadius
|
* @param member1 must not be {@literal null}.
|
||||||
*
|
* @param member2 must not be {@literal null}.
|
||||||
* @param key
|
* @param metric must not be {@literal null}.
|
||||||
* @param longitude
|
* @return can be {@literal null}.
|
||||||
* @param latitude
|
* @see <a href="http://redis.io/commands/geodist">http://redis.io/commands/geodist</a>
|
||||||
* @param radius
|
*/
|
||||||
* @param unit
|
Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric);
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<GeoRadiusResponse> 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
|
* Get Geohash representation of the position for one or more {@literal member}s.
|
||||||
* the borders of the area specified with the center location and the maximum distance from the radius.
|
*
|
||||||
* <p>
|
* @param key must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/georadius
|
* @param members must not be {@literal null}.
|
||||||
*
|
* @return never {@literal null}.
|
||||||
* @param key
|
* @see <a href="http://redis.io/commands/geohash">http://redis.io/commands/geohash</a>
|
||||||
* @param longitude
|
*/
|
||||||
* @param latitude
|
List<String> geoHash(byte[] key, byte[]... members);
|
||||||
* @param radius
|
|
||||||
* @param unit
|
|
||||||
* @param param
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<GeoRadiusResponse> 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
|
* Get the {@link Point} representation of positions for one or more {@literal member}s.
|
||||||
* 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.
|
* @param key must not be {@literal null}.
|
||||||
* <p>
|
* @param members must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/georadiusbymember
|
* @return never {@literal null}.
|
||||||
*
|
* @see <a href="http://redis.io/commands/geopos">http://redis.io/commands/geopos</a>
|
||||||
* @param key
|
*/
|
||||||
* @param member
|
List<Point> geoPos(byte[] key, byte[]... members);
|
||||||
* @param radius
|
|
||||||
* @param unit
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<GeoRadiusResponse> 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
|
* Get the {@literal member}s within the boundaries of a given {@link Circle}.
|
||||||
* 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.
|
* @param key must not be {@literal null}.
|
||||||
* <p>
|
* @param within must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/georadiusbymember
|
* @return never {@literal null}.
|
||||||
*
|
* @see <a href="http://redis.io/commands/georadius">http://redis.io/commands/georadius</a>
|
||||||
* @param key
|
*/
|
||||||
* @param member
|
GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within);
|
||||||
* @param radius
|
|
||||||
* @param unit
|
|
||||||
* @param param
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<GeoRadiusResponse> 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
|
* Get the {@literal member}s within the boundaries of a given {@link Circle} applying {@link GeoRadiusCommandArgs}.
|
||||||
* <p>
|
*
|
||||||
* @link http://redis.io/commands/geoadd
|
* @param key must not be {@literal null}.
|
||||||
*
|
* @param within must not be {@literal null}.
|
||||||
* @param key
|
* @param args must not be {@literal null}.
|
||||||
* @param values
|
* @return never {@literal null}.
|
||||||
* @return
|
* @see <a href="http://redis.io/commands/georadius">http://redis.io/commands/georadius</a>
|
||||||
*/
|
*/
|
||||||
Long geoRemove(byte[] key, byte[]... values);
|
GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@literal radius}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param radius
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, double radius);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@link Distance}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param radius must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates, given {@link Distance}
|
||||||
|
* and {@link GeoRadiusCommandArgs}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param radius must not be {@literal null}.
|
||||||
|
* @param args must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
|
||||||
|
GeoRadiusCommandArgs args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the {@literal member}s.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param members must not be {@literal null}.
|
||||||
|
* @return Number of elements removed.
|
||||||
|
*/
|
||||||
|
Long geoRemove(byte[] key, byte[]... members);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional arguments (like count/sort/...) to be used with {@link RedisGeoCommands}.
|
||||||
|
*
|
||||||
|
* @author Ninad Divadkar
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public class GeoRadiusCommandArgs {
|
||||||
|
|
||||||
|
Set<Flag> flags = new LinkedHashSet<Flag>(2, 1);
|
||||||
|
Long limit;
|
||||||
|
Direction sortDirection;
|
||||||
|
|
||||||
|
private GeoRadiusCommandArgs() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new {@link GeoRadiusCommandArgs}.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
public static GeoRadiusCommandArgs newGeoRadiusArgs() {
|
||||||
|
return new GeoRadiusCommandArgs();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link Flag#WITHCOORD} flag to also return the longitude, latitude coordinates of the matching items.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public GeoRadiusCommandArgs includeCoordinates() {
|
||||||
|
|
||||||
|
flags.add(Flag.WITHCOORD);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link Flag#WITHDIST} flag to also return the distance of the returned items from the specified center.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
public GeoRadiusCommandArgs includeDistance() {
|
||||||
|
|
||||||
|
flags.add(Flag.WITHDIST);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort returned items from the nearest to the furthest, relative to the center.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
public GeoRadiusCommandArgs sortAscending() {
|
||||||
|
|
||||||
|
sortDirection = Direction.ASC;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort returned items from the furthest to the nearest, relative to the center.
|
||||||
|
*
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
public GeoRadiusCommandArgs sortDescending() {
|
||||||
|
|
||||||
|
sortDirection = Direction.DESC;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limit the results to the first N matching items.
|
||||||
|
*
|
||||||
|
* @param count
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
public GeoRadiusCommandArgs limit(long count) {
|
||||||
|
|
||||||
|
Assert.isTrue(count > 0, "Count has to positive value.");
|
||||||
|
limit = count;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return never {@literal null}.
|
||||||
|
*/
|
||||||
|
public Set<Flag> getFlags() {
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return can be {@literal null}.
|
||||||
|
*/
|
||||||
|
public Long getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return can be {@literal null}.
|
||||||
|
*/
|
||||||
|
public Direction getSortDirection() {
|
||||||
|
return sortDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasFlags() {
|
||||||
|
return !flags.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSortDirection() {
|
||||||
|
return sortDirection != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasLimit() {
|
||||||
|
return limit != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum Flag {
|
||||||
|
WITHCOORD, WITHDIST
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link GeoLocation} representing a {@link Point} associated with a {@literal name}.
|
||||||
|
*
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @param <T>
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public static class GeoLocation<T> {
|
||||||
|
|
||||||
|
private final T name;
|
||||||
|
private final Point point;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Metric}s supported by Redis.
|
||||||
|
*
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static enum DistanceUnit implements Metric {
|
||||||
|
|
||||||
|
METERS(6378137, "m"), KILOMETERS(6378.137, "km"), MILES(3963.191, "mi"), FEET(20925646.325, "ft");
|
||||||
|
|
||||||
|
private final double multiplier;
|
||||||
|
private final String abbreviation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link DistanceUnit} using the given muliplier.
|
||||||
|
*
|
||||||
|
* @param multiplier the earth radius at equator.
|
||||||
|
*/
|
||||||
|
private DistanceUnit(double multiplier, String abbreviation) {
|
||||||
|
|
||||||
|
this.multiplier = multiplier;
|
||||||
|
this.abbreviation = abbreviation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.mongodb.core.geo.Metric#getMultiplier()
|
||||||
|
*/
|
||||||
|
public double getMultiplier() {
|
||||||
|
return multiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.geo.Metric#getAbbreviation()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getAbbreviation() {
|
||||||
|
return abbreviation;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,15 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.data.redis.core.*;
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
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.types.Expiration;
|
import org.springframework.data.redis.core.types.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
@@ -34,6 +42,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
|||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author David Liu
|
* @author David Liu
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ninad Divadkar
|
||||||
* @see RedisCallback
|
* @see RedisCallback
|
||||||
* @see RedisSerializer
|
* @see RedisSerializer
|
||||||
* @see StringRedisTemplate
|
* @see StringRedisTemplate
|
||||||
@@ -623,151 +632,168 @@ public interface StringRedisConnection extends RedisConnection {
|
|||||||
Set<String> zRangeByLex(String key, Range range, Limit limit);
|
Set<String> zRangeByLex(String key, Range range, Limit limit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add latitude and longitude for a {@member} with a given {@key}.
|
* Add {@link Point} with given member {@literal name} to {@literal key}.
|
||||||
* Returns the number of elements added to the sorted set, not including elements already existing for which the
|
*
|
||||||
* score was updated.
|
* @param key must not be {@literal null}.
|
||||||
* <p>
|
* @param point must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/geoadd
|
* @param member must not be {@literal null}.
|
||||||
*
|
* @return Number of elements added.
|
||||||
* @param key
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
* @param member
|
* @since 1.8
|
||||||
* @param longitude
|
|
||||||
* @param latitude
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
Long geoAdd(String key, double longitude, double latitude, String member);
|
Long geoAdd(String key, Point point, String member);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add memberCoordinateMap with a given {@key}.
|
* Add {@link GeoLocation} to {@literal key}.
|
||||||
* Returns the number of elements added to the sorted set, not including elements already existing for which the
|
*
|
||||||
* score was updated.
|
* @param key must not be {@literal null}.
|
||||||
* <p>
|
* @param location must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/geoadd
|
* @return Number of elements added.
|
||||||
*
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
* @param key
|
* @since 1.8
|
||||||
* @param memberCoordinateMap
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
Long geoAdd(String key, Map<String, GeoCoordinate> memberCoordinateMap);
|
Long geoAdd(String key, GeoLocation<String> location);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the distance between {@member1} and {@member2} in the geospatial index represented by the sorted set.
|
* Add {@link Map} of member / {@link Point} pairs to {@literal key}.
|
||||||
* The unit in which the distance is returned is meters.
|
*
|
||||||
* <p>
|
* @param key must not be {@literal null}.
|
||||||
* @link http://redis.io/commands/geodist
|
* @param memberCoordinateMap must not be {@literal null}.
|
||||||
*
|
* @return Number of elements added.
|
||||||
* @param key
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
* @param member1
|
* @since 1.8
|
||||||
* @param member2
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
Double geoDist(String key, String member1, String member2);
|
Long geoAdd(String key, Map<String, Point> memberCoordinateMap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the distance in {@unit} between {@member1} and {@member2} in the geospatial index represented by the sorted set.
|
* Add {@link GeoLocation}s to {@literal key}
|
||||||
* <p>
|
*
|
||||||
* @link http://redis.io/commands/geodist
|
* @param key must not be {@literal null}.
|
||||||
*
|
* @param locations must not be {@literal null}.
|
||||||
* @param key
|
* @return Number of elements added.
|
||||||
* @param member1
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
* @param member2
|
* @since 1.8
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
Double geoDist(String key, String member1, String member2, GeoUnit unit);
|
Long geoAdd(String key, Iterable<GeoLocation<String>> locations);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return valid Geohash strings representing the position of one or more {@values}
|
* Get the {@link Distance} between {@literal member1} and {@literal member2}.
|
||||||
* representing a geospatial index (where elements were added using GEOADD).
|
|
||||||
* <p>
|
|
||||||
* @link http://redis.io/commands/geohash
|
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key must not be {@literal null}.
|
||||||
* @param values
|
* @param member1 must not be {@literal null}.
|
||||||
* @return
|
* @param member2 must not be {@literal null}.
|
||||||
|
* @return can be {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geodist">http://redis.io/commands/geodist</a>
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
List<String> geoHash(String key, String... values);
|
Distance geoDist(String key, String member1, String member2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the positions (longitude,latitude) in GeoCoordinate of all the specified {@members} of the geospatial index represented by
|
* Get the {@link Distance} between {@literal member1} and {@literal member2} in the given {@link Metric}.
|
||||||
* the sorted set at key.
|
|
||||||
* <p>
|
|
||||||
* @link http://redis.io/commands/geopos
|
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key must not be {@literal null}.
|
||||||
* @param members
|
* @param member1 must not be {@literal null}.
|
||||||
* @return
|
* @param member2 must not be {@literal null}.
|
||||||
|
* @param metric must not be {@literal null}.
|
||||||
|
* @return can be {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geodist">http://redis.io/commands/geodist</a>
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
List<GeoCoordinate> geoPos(String key, String... members);
|
Distance geoDist(String key, String member1, String member2, Metric metric);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the members of a sorted set populated with geospatial information using GEOADD, which are within
|
* Get geohash representation of the position for one or more {@literal member}s.
|
||||||
* the borders of the area specified with the center location given by {@longitude} and {@latitude} and
|
|
||||||
* the maximum distance from the {@radius}.
|
|
||||||
* <p>
|
|
||||||
* @link http://redis.io/commands/georadius
|
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key must not be {@literal null}.
|
||||||
* @param longitude
|
* @param members must not be {@literal null}.
|
||||||
* @param latitude
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geohash">http://redis.io/commands/geohash</a>
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
List<String> geoHash(String key, String... members);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link Point} representation of positions for one or more {@literal member}s.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param members must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geopos">http://redis.io/commands/geopos</a>
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
List<Point> geoPos(String key, String... members);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the boundaries of a given {@link Circle}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param within must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadius">http://redis.io/commands/georadius</a>
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<String>> georadius(String key, Circle within);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the boundaries of a given {@link Circle} applying {@link GeoRadiusCommandArgs}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param within must not be {@literal null}.
|
||||||
|
* @param args must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadius">http://redis.io/commands/georadius</a>
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<String>> georadius(String key, Circle within, GeoRadiusCommandArgs args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@literal radius}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
* @param radius
|
* @param radius
|
||||||
* @param unit
|
* @return never {@literal null}.
|
||||||
* @return
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
List<GeoRadiusResponse> georadius(String key, double longitude, double latitude,
|
GeoResults<GeoLocation<String>> georadiusByMember(String key, String member, double radius);
|
||||||
double radius, GeoUnit unit);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the members of a sorted set populated with geospatial information using GEOADD, which are within
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
* the borders of the area specified with the center location given by {@longitude} and {@latitude} and
|
* {@link Distance}.
|
||||||
* the maximum distance from the {@radius}. {@param} can be passed to get coordinates, distance and sort the values
|
|
||||||
* <p>
|
|
||||||
* @link http://redis.io/commands/georadius
|
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key must not be {@literal null}.
|
||||||
* @param longitude
|
* @param member must not be {@literal null}.
|
||||||
* @param latitude
|
* @param radius must not be {@literal null}.
|
||||||
* @param radius
|
* @return never {@literal null}.
|
||||||
* @param unit
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
* @param param
|
* @since 1.8
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
List<GeoRadiusResponse> georadius(String key, double longitude, double latitude,
|
GeoResults<GeoLocation<String>> georadiusByMember(String key, String member, Distance radius);
|
||||||
double radius, GeoUnit unit, GeoRadiusParam param);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This command is exactly like GEORADIUS with the sole difference that instead of taking, as the center of
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
* the area to query, a longitude and latitude value, it takes the name of a member already existing inside
|
* {@link Distance} and {@link GeoRadiusCommandArgs}.
|
||||||
* the geospatial index represented by the sorted set.
|
|
||||||
* <p>
|
|
||||||
* @link http://redis.io/commands/georadiusbymember
|
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key must not be {@literal null}.
|
||||||
* @param member
|
* @param member must not be {@literal null}.
|
||||||
* @param radius
|
* @param radius must not be {@literal null}.
|
||||||
* @param unit
|
* @param args must not be {@literal null}.
|
||||||
*
|
* @return never {@literal null}.
|
||||||
* @return
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius,
|
GeoResults<GeoLocation<String>> georadiusByMember(String key, String member, Distance radius,
|
||||||
GeoUnit unit);
|
GeoRadiusCommandArgs args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This command is exactly like GEORADIUS with the sole difference that instead of taking, as the center of
|
* Remove the {@literal member}s.
|
||||||
* 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.
|
|
||||||
* <p>
|
|
||||||
* @link http://redis.io/commands/georadiusbymember
|
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key must not be {@literal null}.
|
||||||
* @param member
|
* @param members must not be {@literal null}.
|
||||||
* @param radius
|
* @return Number of members elements removed.
|
||||||
* @param unit
|
* @since 1.8
|
||||||
* @param param
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius,
|
|
||||||
GeoUnit unit, GeoRadiusParam param);
|
|
||||||
|
|
||||||
Long geoRemove(String key, String... members);
|
Long geoRemove(String key, String... members);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,24 +27,36 @@ import java.util.Properties;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResult;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Metrics;
|
||||||
import org.springframework.data.redis.connection.DataType;
|
import org.springframework.data.redis.connection.DataType;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
|
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode.LinkState;
|
import org.springframework.data.redis.connection.RedisClusterNode.LinkState;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode.RedisClusterNodeBuilder;
|
import org.springframework.data.redis.connection.RedisClusterNode.RedisClusterNodeBuilder;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
|
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
import org.springframework.data.redis.connection.RedisNode.NodeType;
|
import org.springframework.data.redis.connection.RedisNode.NodeType;
|
||||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||||
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.NumberUtils;
|
import org.springframework.util.NumberUtils;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common type converters
|
* Common type converters
|
||||||
*
|
*
|
||||||
* @author Jennifer Hickey
|
* @author Jennifer Hickey
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Christoph Strobl
|
||||||
*/
|
*/
|
||||||
abstract public class Converters {
|
abstract public class Converters {
|
||||||
|
|
||||||
@@ -263,4 +275,86 @@ abstract public class Converters {
|
|||||||
+ NumberUtils.parseNumber(microseconds, Long.class) / 1000L;
|
+ NumberUtils.parseNumber(microseconds, Long.class) / 1000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Converter} capable of deserializing {@link GeoResults}.
|
||||||
|
*
|
||||||
|
* @param serializer
|
||||||
|
* @return
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static <V> Converter<GeoResults<GeoLocation<byte[]>>, GeoResults<GeoLocation<V>>> deserializingGeoResultsConverter(
|
||||||
|
RedisSerializer<V> serializer) {
|
||||||
|
return new DeserializingGeoResultsConverter<V>(serializer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Converter} capable of converting Double into {@link Distance} using given {@link Metric}.
|
||||||
|
*
|
||||||
|
* @param metric
|
||||||
|
* @return
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static Converter<Double, Distance> distanceConverterForMetric(Metric metric) {
|
||||||
|
return DistanceConverterFactory.INSTANCE.forMetric(metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
static enum DistanceConverterFactory {
|
||||||
|
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
DistanceConverter forMetric(Metric metric) {
|
||||||
|
return new DistanceConverter(
|
||||||
|
metric == null || ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, metric) ? DistanceUnit.METERS : metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class DistanceConverter implements Converter<Double, Distance> {
|
||||||
|
|
||||||
|
private Metric metric;
|
||||||
|
|
||||||
|
public DistanceConverter(Metric metric) {
|
||||||
|
this.metric = metric == null || ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, metric) ? DistanceUnit.METERS
|
||||||
|
: metric;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Distance convert(Double source) {
|
||||||
|
return source == null ? null : new Distance(source, metric);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @param <V>
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
static class DeserializingGeoResultsConverter<V>
|
||||||
|
implements Converter<GeoResults<GeoLocation<byte[]>>, GeoResults<GeoLocation<V>>> {
|
||||||
|
|
||||||
|
final RedisSerializer<V> serializer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<V>> convert(GeoResults<GeoLocation<byte[]>> source) {
|
||||||
|
|
||||||
|
if (source == null) {
|
||||||
|
return new GeoResults<GeoLocation<V>>(Collections.<GeoResult<GeoLocation<V>>> emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<GeoResult<GeoLocation<V>>> values = new ArrayList<GeoResult<GeoLocation<V>>>(source.getContent().size());
|
||||||
|
for (GeoResult<GeoLocation<byte[]>> value : source.getContent()) {
|
||||||
|
|
||||||
|
values.add(new GeoResult<GeoLocation<V>>(
|
||||||
|
new GeoLocation<V>(serializer.deserialize(value.getContent().getName()), value.getContent().getPoint()),
|
||||||
|
value.getDistance()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GeoResults<GeoLocation<V>>(values, source.getAverageDistance().getMetric());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,30 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.connection.jedis;
|
package org.springframework.data.redis.connection.jedis;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.ClusterStateFailureException;
|
import org.springframework.data.redis.ClusterStateFailureException;
|
||||||
import org.springframework.data.redis.ExceptionTranslationStrategy;
|
import org.springframework.data.redis.ExceptionTranslationStrategy;
|
||||||
import org.springframework.data.redis.PassThroughExceptionTranslationStrategy;
|
import org.springframework.data.redis.PassThroughExceptionTranslationStrategy;
|
||||||
@@ -48,8 +65,10 @@ import org.springframework.data.redis.connection.SortParameters;
|
|||||||
import org.springframework.data.redis.connection.Subscription;
|
import org.springframework.data.redis.connection.Subscription;
|
||||||
import org.springframework.data.redis.connection.convert.Converters;
|
import org.springframework.data.redis.connection.convert.Converters;
|
||||||
import org.springframework.data.redis.connection.util.ByteArraySet;
|
import org.springframework.data.redis.connection.util.ByteArraySet;
|
||||||
import org.springframework.data.redis.core.*;
|
import org.springframework.data.redis.core.Cursor;
|
||||||
import org.springframework.data.redis.core.GeoRadiusResponse;
|
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.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
import org.springframework.data.redis.util.ByteUtils;
|
import org.springframework.data.redis.util.ByteUtils;
|
||||||
@@ -57,9 +76,15 @@ import org.springframework.util.Assert;
|
|||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
import redis.clients.jedis.*;
|
import redis.clients.jedis.BinaryJedisPubSub;
|
||||||
import redis.clients.jedis.GeoCoordinate;
|
import redis.clients.jedis.GeoCoordinate;
|
||||||
import redis.clients.jedis.GeoUnit;
|
import redis.clients.jedis.GeoUnit;
|
||||||
|
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.params.geo.GeoRadiusParam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link RedisClusterConnection} implementation on top of {@link JedisCluster}.<br/>
|
* {@link RedisClusterConnection} implementation on top of {@link JedisCluster}.<br/>
|
||||||
@@ -68,6 +93,7 @@ import redis.clients.jedis.GeoUnit;
|
|||||||
*
|
*
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ninad Divadkar
|
||||||
* @since 1.7
|
* @since 1.7
|
||||||
*/
|
*/
|
||||||
public class JedisClusterConnection implements RedisClusterConnection {
|
public class JedisClusterConnection implements RedisClusterConnection {
|
||||||
@@ -2149,10 +2175,11 @@ public class JedisClusterConnection implements RedisClusterConnection {
|
|||||||
protected ScanIteration<Tuple> doScan(long cursorId, ScanOptions options) {
|
protected ScanIteration<Tuple> doScan(long cursorId, ScanOptions options) {
|
||||||
|
|
||||||
ScanParams params = JedisConverters.toScanParams(options);
|
ScanParams params = JedisConverters.toScanParams(options);
|
||||||
|
|
||||||
redis.clients.jedis.ScanResult<redis.clients.jedis.Tuple> result = cluster.zscan(key, JedisConverters.toBytes(cursorId), params);
|
redis.clients.jedis.ScanResult<redis.clients.jedis.Tuple> result = cluster.zscan(key,
|
||||||
return new ScanIteration<Tuple>(Long.valueOf(result.getStringCursor()), JedisConverters
|
JedisConverters.toBytes(cursorId), params);
|
||||||
.tuplesToTuples().convert(result.getResult()));
|
return new ScanIteration<Tuple>(Long.valueOf(result.getStringCursor()),
|
||||||
|
JedisConverters.tuplesToTuples().convert(result.getResult()));
|
||||||
}
|
}
|
||||||
}.open();
|
}.open();
|
||||||
}
|
}
|
||||||
@@ -2382,10 +2409,11 @@ public class JedisClusterConnection implements RedisClusterConnection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ScanIteration<Entry<byte[], byte[]>> doScan(long cursorId, ScanOptions options) {
|
protected ScanIteration<Entry<byte[], byte[]>> doScan(long cursorId, ScanOptions options) {
|
||||||
|
|
||||||
ScanParams params = JedisConverters.toScanParams(options);
|
ScanParams params = JedisConverters.toScanParams(options);
|
||||||
|
|
||||||
redis.clients.jedis.ScanResult<Map.Entry<byte[], byte[]>> result = cluster.hscan(key, JedisConverters.toBytes(cursorId), params);
|
redis.clients.jedis.ScanResult<Map.Entry<byte[], byte[]>> result = cluster.hscan(key,
|
||||||
|
JedisConverters.toBytes(cursorId), params);
|
||||||
return new ScanIteration<Map.Entry<byte[], byte[]>>(Long.valueOf(result.getStringCursor()), result.getResult());
|
return new ScanIteration<Map.Entry<byte[], byte[]>>(Long.valueOf(result.getStringCursor()), result.getResult());
|
||||||
}
|
}
|
||||||
}.open();
|
}.open();
|
||||||
@@ -2495,126 +2523,265 @@ public class JedisClusterConnection implements RedisClusterConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member){
|
* (non-Javadoc)
|
||||||
try {
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.geo.Point, byte[])
|
||||||
return cluster.geoadd(key, longitude, latitude, member);
|
*/
|
||||||
} catch (Exception ex) {
|
|
||||||
throw convertJedisAccessException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long geoAdd(byte[] key, Map<byte[], org.springframework.data.redis.core.GeoCoordinate> memberCoordinateMap) {
|
|
||||||
Map<byte[], redis.clients.jedis.GeoCoordinate> redisGeoCoordinateMap = new HashMap<byte[], GeoCoordinate>();
|
|
||||||
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<byte[]> geoHash(byte[] key, byte[]... members) {
|
|
||||||
try {
|
|
||||||
return cluster.geohash(key, members);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw convertJedisAccessException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<org.springframework.data.redis.core.GeoCoordinate> geoPos(byte[] key, byte[]... members) {
|
|
||||||
try {
|
|
||||||
return JedisConverters.geoCoordinateListToGeoCoordinateList().convert(cluster.geopos(key, members));
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw convertJedisAccessException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude,
|
public Long geoAdd(byte[] key, Point point, byte[] member) {
|
||||||
double radius, org.springframework.data.redis.core.GeoUnit unit) {
|
|
||||||
GeoUnit geoUnit = JedisConverters.toGeoUnit(unit);
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(point, "Point must not be null!");
|
||||||
|
Assert.notNull(member, "Member must not be null!");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return JedisConverters.geoRadiusResponseGeoRadiusResponseList().
|
return cluster.geoadd(key, point.getX(), point.getY(), member);
|
||||||
convert(cluster.georadius(key, longitude, latitude, radius, geoUnit));
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertJedisAccessException(ex);
|
throw convertJedisAccessException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoRadiusResponse> 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<GeoRadiusResponse> 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<GeoRadiusResponse> 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)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.redis.connection.RedisConnectionCommands#select(int)
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
|
||||||
*/
|
*/
|
||||||
|
public Long geoAdd(byte[] key, GeoLocation<byte[]> location) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(location, "Location must not be null!");
|
||||||
|
|
||||||
|
return geoAdd(key, location.getPoint(), location.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.util.Map)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(memberCoordinateMap, "MemberCoordinateMap must not be null!");
|
||||||
|
|
||||||
|
Map<byte[], GeoCoordinate> redisGeoCoordinateMap = new HashMap<byte[], GeoCoordinate>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.lang.Iterable)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(locations, "Locations must not be null!");
|
||||||
|
|
||||||
|
Map<byte[], redis.clients.jedis.GeoCoordinate> redisGeoCoordinateMap = new HashMap<byte[], GeoCoordinate>();
|
||||||
|
for (GeoLocation<byte[]> location : locations) {
|
||||||
|
redisGeoCoordinateMap.put(location.getName(), JedisConverters.toGeoCoordinate(location.getPoint()));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return cluster.geoadd(key, redisGeoCoordinateMap);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(member1, "Member1 must not be null!");
|
||||||
|
Assert.notNull(member2, "Member2 must not be null!");
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JedisConverters.distanceConverterForMetric(DistanceUnit.METERS)
|
||||||
|
.convert(cluster.geodist(key, member1, member2));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[], org.springframework.data.geo.Metric)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(member1, "Member1 must not be null!");
|
||||||
|
Assert.notNull(member2, "Member2 must not be null!");
|
||||||
|
Assert.notNull(metric, "Metric must not be null!");
|
||||||
|
|
||||||
|
GeoUnit geoUnit = JedisConverters.toGeoUnit(metric);
|
||||||
|
try {
|
||||||
|
return JedisConverters.distanceConverterForMetric(metric)
|
||||||
|
.convert(cluster.geodist(key, member1, member2, geoUnit));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoHash(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> geoHash(byte[] key, byte[]... members) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(members, "Members must not be null!");
|
||||||
|
Assert.noNullElements(members, "Members must not contain null!");
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JedisConverters.toStrings(cluster.geohash(key, members));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoPos(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Point> geoPos(byte[] key, byte[]... members) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(members, "Members must not be null!");
|
||||||
|
Assert.noNullElements(members, "Members must not contain null!");
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JedisConverters.geoCoordinateToPointConverter().convert(cluster.geopos(key, members));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(within, "Within must not be null!");
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JedisConverters.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric())
|
||||||
|
.convert(cluster.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
|
||||||
|
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric())));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(within, "Within must not be null!");
|
||||||
|
Assert.notNull(args, "Args must not be null!");
|
||||||
|
|
||||||
|
GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(args);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JedisConverters.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric())
|
||||||
|
.convert(cluster.georadius(key, within.getCenter().getX(), within.getCenter().getY(),
|
||||||
|
within.getRadius().getValue(), JedisConverters.toGeoUnit(within.getRadius().getMetric()),
|
||||||
|
geoRadiusParam));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], double)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, double radius) {
|
||||||
|
return geoRadiusByMember(key, member, new Distance(radius, DistanceUnit.METERS));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(member, "Member must not be null!");
|
||||||
|
Assert.notNull(radius, "Radius must not be null!");
|
||||||
|
|
||||||
|
GeoUnit geoUnit = JedisConverters.toGeoUnit(radius.getMetric());
|
||||||
|
try {
|
||||||
|
return JedisConverters.geoRadiusResponseToGeoResultsConverter(radius.getMetric())
|
||||||
|
.convert(cluster.georadiusByMember(key, member, radius.getValue(), geoUnit));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
|
||||||
|
GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(member, "Member must not be null!");
|
||||||
|
Assert.notNull(radius, "Radius must not be null!");
|
||||||
|
Assert.notNull(args, "Args must not be null!");
|
||||||
|
|
||||||
|
GeoUnit geoUnit = JedisConverters.toGeoUnit(radius.getMetric());
|
||||||
|
redis.clients.jedis.params.geo.GeoRadiusParam geoRadiusParam = JedisConverters.toGeoRadiusParam(args);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JedisConverters.geoRadiusResponseToGeoResultsConverter(radius.getMetric())
|
||||||
|
.convert(cluster.georadiusByMember(key, member, radius.getValue(), geoUnit, geoRadiusParam));
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertJedisAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoRemove(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoRemove(byte[] key, byte[]... members) {
|
||||||
|
return zRem(key, members);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisConnectionCommands#select(int)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void select(final int dbIndex) {
|
public void select(final int dbIndex) {
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -25,8 +25,18 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResult;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Metrics;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.connection.DefaultTuple;
|
import org.springframework.data.redis.connection.DefaultTuple;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.Flag;
|
||||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||||
import org.springframework.data.redis.connection.RedisServer;
|
import org.springframework.data.redis.connection.RedisServer;
|
||||||
import org.springframework.data.redis.connection.RedisStringCommands;
|
import org.springframework.data.redis.connection.RedisStringCommands;
|
||||||
@@ -42,10 +52,6 @@ import org.springframework.data.redis.connection.convert.ListConverter;
|
|||||||
import org.springframework.data.redis.connection.convert.MapConverter;
|
import org.springframework.data.redis.connection.convert.MapConverter;
|
||||||
import org.springframework.data.redis.connection.convert.SetConverter;
|
import org.springframework.data.redis.connection.convert.SetConverter;
|
||||||
import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
|
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.ScanOptions;
|
||||||
import org.springframework.data.redis.core.types.Expiration;
|
import org.springframework.data.redis.core.types.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
@@ -56,8 +62,12 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
import redis.clients.jedis.BitOP;
|
import redis.clients.jedis.BitOP;
|
||||||
|
import redis.clients.jedis.GeoCoordinate;
|
||||||
|
import redis.clients.jedis.GeoRadiusResponse;
|
||||||
|
import redis.clients.jedis.GeoUnit;
|
||||||
import redis.clients.jedis.ScanParams;
|
import redis.clients.jedis.ScanParams;
|
||||||
import redis.clients.jedis.SortingParams;
|
import redis.clients.jedis.SortingParams;
|
||||||
|
import redis.clients.jedis.params.geo.GeoRadiusParam;
|
||||||
import redis.clients.util.SafeEncoder;
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,6 +78,7 @@ import redis.clients.util.SafeEncoder;
|
|||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author Jungtaek Lim
|
* @author Jungtaek Lim
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
abstract public class JedisConverters extends Converters {
|
abstract public class JedisConverters extends Converters {
|
||||||
|
|
||||||
@@ -83,10 +94,10 @@ abstract public class JedisConverters extends Converters {
|
|||||||
private static final Converter<Object, RedisClusterNode> OBJECT_TO_CLUSTER_NODE_CONVERTER;
|
private static final Converter<Object, RedisClusterNode> OBJECT_TO_CLUSTER_NODE_CONVERTER;
|
||||||
private static final Converter<Expiration, byte[]> EXPIRATION_TO_COMMAND_OPTION_CONVERTER;
|
private static final Converter<Expiration, byte[]> EXPIRATION_TO_COMMAND_OPTION_CONVERTER;
|
||||||
private static final Converter<SetOption, byte[]> SET_OPTION_TO_COMMAND_OPTION_CONVERTER;
|
private static final Converter<SetOption, byte[]> SET_OPTION_TO_COMMAND_OPTION_CONVERTER;
|
||||||
private static final Converter<redis.clients.jedis.GeoCoordinate, GeoCoordinate> GEO_COORDINATE_CONVERTER;
|
private static final Converter<redis.clients.jedis.GeoCoordinate, Point> GEO_COORDINATE_TO_POINT_CONVERTER;
|
||||||
private static final ListConverter<redis.clients.jedis.GeoCoordinate, GeoCoordinate> GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST;
|
private static final ListConverter<redis.clients.jedis.GeoCoordinate, Point> LIST_GEO_COORDINATE_TO_POINT_CONVERTER;
|
||||||
private static final Converter<redis.clients.jedis.GeoRadiusResponse, GeoRadiusResponse> GEO_RADIUS_RESPONSE_CONVERTER;
|
private static final Converter<byte[], String> BYTES_TO_STRING_CONVERTER;
|
||||||
private static final ListConverter<redis.clients.jedis.GeoRadiusResponse, GeoRadiusResponse> GEO_RADIUS_RESPONSE_LIST_TO_GEO_RADIUS_RESPONSE_LIST;
|
private static final ListConverter<byte[], String> BYTES_LIST_TO_STRING_LIST_CONVERTER;
|
||||||
|
|
||||||
public static final byte[] PLUS_BYTES;
|
public static final byte[] PLUS_BYTES;
|
||||||
public static final byte[] MINUS_BYTES;
|
public static final byte[] MINUS_BYTES;
|
||||||
@@ -99,6 +110,15 @@ abstract public class JedisConverters extends Converters {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
|
BYTES_TO_STRING_CONVERTER = new Converter<byte[], String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convert(byte[] source) {
|
||||||
|
return source == null ? null : SafeEncoder.encode(source);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
BYTES_LIST_TO_STRING_LIST_CONVERTER = new ListConverter<byte[], String>(BYTES_TO_STRING_CONVERTER);
|
||||||
|
|
||||||
STRING_TO_BYTES = new Converter<String, byte[]>() {
|
STRING_TO_BYTES = new Converter<String, byte[]>() {
|
||||||
public byte[] convert(String source) {
|
public byte[] convert(String source) {
|
||||||
return source == null ? null : SafeEncoder.encode(source);
|
return source == null ? null : SafeEncoder.encode(source);
|
||||||
@@ -174,26 +194,14 @@ abstract public class JedisConverters extends Converters {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GEO_COORDINATE_CONVERTER = new Converter<redis.clients.jedis.GeoCoordinate, GeoCoordinate>() {
|
GEO_COORDINATE_TO_POINT_CONVERTER = new Converter<redis.clients.jedis.GeoCoordinate, Point>() {
|
||||||
@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<redis.clients.jedis.GeoCoordinate, GeoCoordinate>(GEO_COORDINATE_CONVERTER);
|
|
||||||
|
|
||||||
GEO_RADIUS_RESPONSE_CONVERTER = new Converter<redis.clients.jedis.GeoRadiusResponse, GeoRadiusResponse>() {
|
|
||||||
@Override
|
@Override
|
||||||
public GeoRadiusResponse convert(redis.clients.jedis.GeoRadiusResponse geoRadiusResponse) {
|
public Point convert(redis.clients.jedis.GeoCoordinate geoCoordinate) {
|
||||||
if (geoRadiusResponse == null)
|
return geoCoordinate != null ? new Point(geoCoordinate.getLongitude(), geoCoordinate.getLatitude()) : 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<redis.clients.jedis.GeoRadiusResponse, GeoRadiusResponse>(GEO_RADIUS_RESPONSE_CONVERTER);
|
LIST_GEO_COORDINATE_TO_POINT_CONVERTER = new ListConverter<redis.clients.jedis.GeoCoordinate, Point>(
|
||||||
|
GEO_COORDINATE_TO_POINT_CONVERTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Converter<String, byte[]> stringToBytes() {
|
public static Converter<String, byte[]> stringToBytes() {
|
||||||
@@ -230,10 +238,6 @@ abstract public class JedisConverters extends Converters {
|
|||||||
return EXCEPTION_CONVERTER;
|
return EXCEPTION_CONVERTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ListConverter<redis.clients.jedis.GeoCoordinate, GeoCoordinate> geoCoordinateListToGeoCoordinateList() { return GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; }
|
|
||||||
|
|
||||||
public static ListConverter<redis.clients.jedis.GeoRadiusResponse, GeoRadiusResponse> geoRadiusResponseGeoRadiusResponseList() { return GEO_RADIUS_RESPONSE_LIST_TO_GEO_RADIUS_RESPONSE_LIST; }
|
|
||||||
|
|
||||||
public static String[] toStrings(byte[][] source) {
|
public static String[] toStrings(byte[][] source) {
|
||||||
String[] result = new String[source.length];
|
String[] result = new String[source.length];
|
||||||
for (int i = 0; i < source.length; i++) {
|
for (int i = 0; i < source.length; i++) {
|
||||||
@@ -475,9 +479,9 @@ abstract public class JedisConverters extends Converters {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ScanParams toScanParams(ScanOptions options) {
|
public static ScanParams toScanParams(ScanOptions options) {
|
||||||
|
|
||||||
ScanParams sp = new ScanParams();
|
ScanParams sp = new ScanParams();
|
||||||
|
|
||||||
if (!options.equals(ScanOptions.NONE)) {
|
if (!options.equals(ScanOptions.NONE)) {
|
||||||
if (options.getCount() != null) {
|
if (options.getCount() != null) {
|
||||||
sp.count(options.getCount().intValue());
|
sp.count(options.getCount().intValue());
|
||||||
@@ -489,41 +493,179 @@ abstract public class JedisConverters extends Converters {
|
|||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static redis.clients.jedis.GeoUnit toGeoUnit(GeoUnit geoUnit){
|
/**
|
||||||
switch (geoUnit){
|
* @param source
|
||||||
case Meters: return redis.clients.jedis.GeoUnit.M;
|
* @return
|
||||||
case KiloMeters: return redis.clients.jedis.GeoUnit.KM;
|
* @since 1.8
|
||||||
case Miles: return redis.clients.jedis.GeoUnit.MI;
|
*/
|
||||||
case Feet: return redis.clients.jedis.GeoUnit.FT;
|
public static List<String> toStrings(List<byte[]> source) {
|
||||||
default: throw new IllegalArgumentException("geoUnit not supported");
|
return BYTES_LIST_TO_STRING_LIST_CONVERTER.convert(source);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static redis.clients.jedis.GeoCoordinate toGeoCoordinate(GeoCoordinate geoCoordinate){
|
/**
|
||||||
return new redis.clients.jedis.GeoCoordinate(geoCoordinate.getLongitude(), geoCoordinate.getLatitude());
|
* @return
|
||||||
}
|
*/
|
||||||
|
public static ListConverter<byte[], String> bytesListToStringListConverter() {
|
||||||
|
return BYTES_LIST_TO_STRING_LIST_CONVERTER;
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
* @return
|
||||||
for (String k : geoRadiusParam.getParams().keySet()){
|
* @since 1.8
|
||||||
if (k.equals(GeoRadiusParam.getASC()))
|
*/
|
||||||
param.sortAscending();
|
public static ListConverter<redis.clients.jedis.GeoCoordinate, Point> geoCoordinateToPointConverter() {
|
||||||
if (k.equals(GeoRadiusParam.getDESC()))
|
return LIST_GEO_COORDINATE_TO_POINT_CONVERTER;
|
||||||
param.sortDescending();
|
}
|
||||||
if (k.equals(GeoRadiusParam.getCOUNT()))
|
|
||||||
param.count((Integer)geoRadiusParam.getParams().get(k));
|
/**
|
||||||
if (k.equals(GeoRadiusParam.getWITHCOORD()))
|
* Get a {@link Converter} capable of converting {@link GeoRadiusResponse} into {@link GeoResults}.
|
||||||
param.withCoord();
|
*
|
||||||
if (k.equals(GeoRadiusParam.getWITHDIST()))
|
* @param metric
|
||||||
param.withDist();
|
* @return
|
||||||
}
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static Converter<List<redis.clients.jedis.GeoRadiusResponse>, GeoResults<GeoLocation<byte[]>>> geoRadiusResponseToGeoResultsConverter(
|
||||||
|
Metric metric) {
|
||||||
|
return GeoResultsConverterFactory.INSTANCE.forMetric(metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert {@link Metric} into {@link GeoUnit}.
|
||||||
|
*
|
||||||
|
* @param metric
|
||||||
|
* @return
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static GeoUnit toGeoUnit(Metric metric) {
|
||||||
|
|
||||||
|
Metric metricToUse = metric == null || ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, metric) ? DistanceUnit.METERS
|
||||||
|
: metric;
|
||||||
|
return ObjectUtils.caseInsensitiveValueOf(GeoUnit.values(), metricToUse.getAbbreviation());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert {@link Point} into {@link GeoCoordinate}.
|
||||||
|
*
|
||||||
|
* @param source
|
||||||
|
* @return
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static GeoCoordinate toGeoCoordinate(Point source) {
|
||||||
|
return source == null ? null : new redis.clients.jedis.GeoCoordinate(source.getX(), source.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert {@link GeoRadiusCommandArgs} into {@link GeoRadiusParam}.
|
||||||
|
*
|
||||||
|
* @param source
|
||||||
|
* @return
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static GeoRadiusParam toGeoRadiusParam(GeoRadiusCommandArgs source) {
|
||||||
|
|
||||||
|
GeoRadiusParam param = GeoRadiusParam.geoRadiusParam();
|
||||||
|
if (source == null) {
|
||||||
return param;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (source.hasFlags()) {
|
||||||
|
for (Flag flag : source.getFlags()) {
|
||||||
|
switch (flag) {
|
||||||
|
case WITHCOORD:
|
||||||
|
param.withCoord();
|
||||||
|
break;
|
||||||
|
case WITHDIST:
|
||||||
|
param.withDist();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source.hasSortDirection()) {
|
||||||
|
switch (source.getSortDirection()) {
|
||||||
|
case ASC:
|
||||||
|
param.sortAscending();
|
||||||
|
break;
|
||||||
|
case DESC:
|
||||||
|
param.sortDescending();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source.hasLimit()) {
|
||||||
|
param.count(source.getLimit().intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
static enum GeoResultsConverterFactory {
|
||||||
|
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
Converter<List<redis.clients.jedis.GeoRadiusResponse>, GeoResults<GeoLocation<byte[]>>> forMetric(Metric metric) {
|
||||||
|
return new GeoResultsConverter(
|
||||||
|
metric == null || ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, metric) ? DistanceUnit.METERS : metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GeoResultsConverter
|
||||||
|
implements Converter<List<redis.clients.jedis.GeoRadiusResponse>, GeoResults<GeoLocation<byte[]>>> {
|
||||||
|
|
||||||
|
private Metric metric;
|
||||||
|
|
||||||
|
public GeoResultsConverter(Metric metric) {
|
||||||
|
this.metric = metric;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> convert(List<GeoRadiusResponse> source) {
|
||||||
|
|
||||||
|
List<GeoResult<GeoLocation<byte[]>>> results = new ArrayList<GeoResult<GeoLocation<byte[]>>>(source.size());
|
||||||
|
|
||||||
|
Converter<redis.clients.jedis.GeoRadiusResponse, GeoResult<GeoLocation<byte[]>>> converter = GeoResultConverterFactory.INSTANCE
|
||||||
|
.forMetric(metric);
|
||||||
|
for (GeoRadiusResponse result : source) {
|
||||||
|
results.add(converter.convert(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GeoResults<GeoLocation<byte[]>>(results, metric);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
static enum GeoResultConverterFactory {
|
||||||
|
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
Converter<redis.clients.jedis.GeoRadiusResponse, GeoResult<GeoLocation<byte[]>>> forMetric(Metric metric) {
|
||||||
|
return new GeoResultConverter(metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GeoResultConverter
|
||||||
|
implements Converter<redis.clients.jedis.GeoRadiusResponse, GeoResult<GeoLocation<byte[]>>> {
|
||||||
|
|
||||||
|
private Metric metric;
|
||||||
|
|
||||||
|
public GeoResultConverter(Metric metric) {
|
||||||
|
this.metric = metric;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResult<GeoLocation<byte[]>> convert(redis.clients.jedis.GeoRadiusResponse source) {
|
||||||
|
|
||||||
|
Point point = GEO_COORDINATE_TO_POINT_CONVERTER.convert(source.getCoordinate());
|
||||||
|
|
||||||
|
return new GeoResult<GeoLocation<byte[]>>(new GeoLocation<byte[]>(source.getMember(), point),
|
||||||
|
new Distance(source.getDistance(), metric));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ import org.jredis.connector.NotConnectedException;
|
|||||||
import org.jredis.protocol.Command;
|
import org.jredis.protocol.Command;
|
||||||
import org.jredis.ri.alphazero.JRedisSupport;
|
import org.jredis.ri.alphazero.JRedisSupport;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.RedisSystemException;
|
import org.springframework.data.redis.RedisSystemException;
|
||||||
import org.springframework.data.redis.connection.AbstractRedisConnection;
|
import org.springframework.data.redis.connection.AbstractRedisConnection;
|
||||||
import org.springframework.data.redis.connection.DataType;
|
import org.springframework.data.redis.connection.DataType;
|
||||||
@@ -45,7 +50,8 @@ import org.springframework.data.redis.connection.RedisNode;
|
|||||||
import org.springframework.data.redis.connection.ReturnType;
|
import org.springframework.data.redis.connection.ReturnType;
|
||||||
import org.springframework.data.redis.connection.SortParameters;
|
import org.springframework.data.redis.connection.SortParameters;
|
||||||
import org.springframework.data.redis.connection.Subscription;
|
import org.springframework.data.redis.connection.Subscription;
|
||||||
import org.springframework.data.redis.core.*;
|
import org.springframework.data.redis.core.Cursor;
|
||||||
|
import org.springframework.data.redis.core.ScanOptions;
|
||||||
import org.springframework.data.redis.core.types.Expiration;
|
import org.springframework.data.redis.core.types.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -60,6 +66,7 @@ import org.springframework.util.ReflectionUtils;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author David Liu
|
* @author David Liu
|
||||||
|
* @author Ninad Divadkar
|
||||||
* @deprecated since 1.7. Will be removed in subsequent version.
|
* @deprecated since 1.7. Will be removed in subsequent version.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -1186,67 +1193,138 @@ public class JredisConnection extends AbstractRedisConnection {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void subscribe(MessageListener listener, byte[]... channels) {
|
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<byte[], GeoCoordinate> 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<byte[]> geoHash(byte[] key, byte[]... members) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoCoordinate> geoPos(byte[] key, byte[]... members) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) {
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Geo commands
|
||||||
|
//
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.geo.Point, byte[])
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Long geoAdd(byte[] key, Point point, byte[] member) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) {
|
public Long geoAdd(byte[] key, GeoLocation<byte[]> location) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.util.Map)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.lang.Iterable)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long geoRemove(byte[] key, byte[]... values) {
|
public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[], org.springframework.data.geo.Metric)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoHash(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> geoHash(byte[] key, byte[]... members) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoPos(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Point> geoPos(byte[] key, byte[]... members) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], double)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, double radius) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
|
||||||
|
GeoRadiusCommandArgs args) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoRemove(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoRemove(byte[] key, byte[]... members) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2015 the original author or authors.
|
* Copyright 2011-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,6 +21,7 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -35,12 +36,16 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.lambdaworks.redis.*;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.dao.QueryTimeoutException;
|
import org.springframework.dao.QueryTimeoutException;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.ExceptionTranslationStrategy;
|
import org.springframework.data.redis.ExceptionTranslationStrategy;
|
||||||
import org.springframework.data.redis.FallbackExceptionTranslationStrategy;
|
import org.springframework.data.redis.FallbackExceptionTranslationStrategy;
|
||||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||||
@@ -56,9 +61,14 @@ import org.springframework.data.redis.connection.ReturnType;
|
|||||||
import org.springframework.data.redis.connection.SortParameters;
|
import org.springframework.data.redis.connection.SortParameters;
|
||||||
import org.springframework.data.redis.connection.Subscription;
|
import org.springframework.data.redis.connection.Subscription;
|
||||||
import org.springframework.data.redis.connection.convert.Converters;
|
import org.springframework.data.redis.connection.convert.Converters;
|
||||||
|
import org.springframework.data.redis.connection.convert.ListConverter;
|
||||||
import org.springframework.data.redis.connection.convert.TransactionResultConverter;
|
import org.springframework.data.redis.connection.convert.TransactionResultConverter;
|
||||||
import org.springframework.data.redis.core.*;
|
import org.springframework.data.redis.core.Cursor;
|
||||||
|
import org.springframework.data.redis.core.KeyBoundCursor;
|
||||||
|
import org.springframework.data.redis.core.RedisCommand;
|
||||||
import org.springframework.data.redis.core.ScanCursor;
|
import org.springframework.data.redis.core.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.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -66,6 +76,28 @@ import org.springframework.util.ClassUtils;
|
|||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
import com.lambdaworks.redis.AbstractRedisClient;
|
||||||
|
import com.lambdaworks.redis.GeoArgs;
|
||||||
|
import com.lambdaworks.redis.GeoCoordinates;
|
||||||
|
import com.lambdaworks.redis.GeoWithin;
|
||||||
|
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.codec.RedisCodec;
|
||||||
import com.lambdaworks.redis.output.BooleanOutput;
|
import com.lambdaworks.redis.output.BooleanOutput;
|
||||||
import com.lambdaworks.redis.output.ByteArrayOutput;
|
import com.lambdaworks.redis.output.ByteArrayOutput;
|
||||||
@@ -96,6 +128,7 @@ import com.lambdaworks.redis.pubsub.RedisPubSubConnection;
|
|||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author David Liu
|
* @author David Liu
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
public class LettuceConnection extends AbstractRedisConnection {
|
public class LettuceConnection extends AbstractRedisConnection {
|
||||||
|
|
||||||
@@ -349,8 +382,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
|
|
||||||
RedisAsyncConnectionImpl<byte[], byte[]> connectionImpl = (RedisAsyncConnectionImpl<byte[], byte[]>) getAsyncConnection();
|
RedisAsyncConnectionImpl<byte[], byte[]> connectionImpl = (RedisAsyncConnectionImpl<byte[], byte[]>) getAsyncConnection();
|
||||||
|
|
||||||
CommandOutput expectedOutput = commandOutputTypeHint != null ? commandOutputTypeHint : typeHints
|
CommandOutput expectedOutput = commandOutputTypeHint != null ? commandOutputTypeHint
|
||||||
.getTypeHint(commandType);
|
: typeHints.getTypeHint(commandType);
|
||||||
Command cmd = new Command(commandType, expectedOutput, cmdArg);
|
Command cmd = new Command(commandType, expectedOutput, cmdArg);
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
|
|
||||||
@@ -827,8 +860,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<Object> results = getDedicatedConnection().exec();
|
List<Object> results = getDedicatedConnection().exec();
|
||||||
return convertPipelineAndTxResults ? new LettuceTransactionResultConverter(txResults,
|
return convertPipelineAndTxResults
|
||||||
LettuceConverters.exceptionConverter()).convert(results) : results;
|
? new LettuceTransactionResultConverter(txResults, LettuceConverters.exceptionConverter()).convert(results)
|
||||||
|
: results;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertLettuceAccessException(ex);
|
throw convertLettuceAccessException(ex);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -1206,13 +1240,13 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceStatusResult(getAsyncConnection().set(key, value,
|
pipeline(new LettuceStatusResult(
|
||||||
LettuceConverters.toSetArgs(expiration, option))));
|
getAsyncConnection().set(key, value, LettuceConverters.toSetArgs(expiration, option))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxStatusResult(getConnection().set(key, value,
|
transaction(new LettuceTxStatusResult(
|
||||||
LettuceConverters.toSetArgs(expiration, option))));
|
getConnection().set(key, value, LettuceConverters.toSetArgs(expiration, option))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getConnection().set(key, value, LettuceConverters.toSetArgs(expiration, option));
|
getConnection().set(key, value, LettuceConverters.toSetArgs(expiration, option));
|
||||||
@@ -1479,8 +1513,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
LettuceConverters.longToBooleanConverter()));
|
LettuceConverters.longToBooleanConverter()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.longToBooleanConverter().convert(
|
return LettuceConverters.longToBooleanConverter()
|
||||||
getConnection().setbit(key, offset, LettuceConverters.toInt(value)));
|
.convert(getConnection().setbit(key, offset, LettuceConverters.toInt(value)));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertLettuceAccessException(ex);
|
throw convertLettuceAccessException(ex);
|
||||||
}
|
}
|
||||||
@@ -1659,11 +1693,13 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) {
|
public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) {
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value)));
|
pipeline(
|
||||||
|
new LettuceResult(getAsyncConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value)));
|
transaction(
|
||||||
|
new LettuceTxResult(getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value);
|
return getConnection().linsert(key, LettuceConverters.toBoolean(where), pivot, value);
|
||||||
@@ -2031,13 +2067,13 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
public List<byte[]> sRandMember(byte[] key, long count) {
|
public List<byte[]> sRandMember(byte[] key, long count) {
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().srandmember(key, count),
|
pipeline(
|
||||||
LettuceConverters.bytesSetToBytesList()));
|
new LettuceResult(getAsyncConnection().srandmember(key, count), LettuceConverters.bytesSetToBytesList()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().srandmember(key, count),
|
transaction(
|
||||||
LettuceConverters.bytesSetToBytesList()));
|
new LettuceTxResult(getConnection().srandmember(key, count), LettuceConverters.bytesSetToBytesList()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.toBytesList(getConnection().srandmember(key, count));
|
return LettuceConverters.toBytesList(getConnection().srandmember(key, count));
|
||||||
@@ -2227,13 +2263,13 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
public Set<byte[]> zRange(byte[] key, long start, long end) {
|
public Set<byte[]> zRange(byte[] key, long start, long end) {
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrange(key, start, end),
|
pipeline(
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
new LettuceResult(getAsyncConnection().zrange(key, start, end), LettuceConverters.bytesListToBytesSet()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().zrange(key, start, end),
|
transaction(
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
new LettuceTxResult(getConnection().zrange(key, start, end), LettuceConverters.bytesListToBytesSet()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.toBytesSet(getConnection().zrange(key, start, end));
|
return LettuceConverters.toBytesSet(getConnection().zrange(key, start, end));
|
||||||
@@ -2281,8 +2317,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrangebyscore(key, min, max, limit.getOffset(),
|
pipeline(
|
||||||
limit.getCount()), LettuceConverters.bytesListToBytesSet()));
|
new LettuceResult(getAsyncConnection().zrangebyscore(key, min, max, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
} else {
|
} else {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrangebyscore(key, min, max),
|
pipeline(new LettuceResult(getAsyncConnection().zrangebyscore(key, min, max),
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
@@ -2291,8 +2328,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
transaction(new LettuceTxResult(getConnection().zrangebyscore(key, min, max, limit.getOffset(),
|
transaction(
|
||||||
limit.getCount()), LettuceConverters.bytesListToBytesSet()));
|
new LettuceTxResult(getConnection().zrangebyscore(key, min, max, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
} else {
|
} else {
|
||||||
transaction(new LettuceTxResult(getConnection().zrangebyscore(key, min, max),
|
transaction(new LettuceTxResult(getConnection().zrangebyscore(key, min, max),
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
@@ -2300,8 +2338,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, min, max, limit.getOffset(),
|
return LettuceConverters
|
||||||
limit.getCount()));
|
.toBytesSet(getConnection().zrangebyscore(key, min, max, limit.getOffset(), limit.getCount()));
|
||||||
}
|
}
|
||||||
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, min, max));
|
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, min, max));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -2330,8 +2368,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrangebyscoreWithScores(key, min, max, limit.getOffset(),
|
pipeline(new LettuceResult(
|
||||||
limit.getCount()), LettuceConverters.scoredValuesToTupleSet()));
|
getAsyncConnection().zrangebyscoreWithScores(key, min, max, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.scoredValuesToTupleSet()));
|
||||||
} else {
|
} else {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrangebyscoreWithScores(key, min, max),
|
pipeline(new LettuceResult(getAsyncConnection().zrangebyscoreWithScores(key, min, max),
|
||||||
LettuceConverters.scoredValuesToTupleSet()));
|
LettuceConverters.scoredValuesToTupleSet()));
|
||||||
@@ -2340,8 +2379,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
transaction(new LettuceTxResult(getConnection().zrangebyscoreWithScores(key, min, max, limit.getOffset(),
|
transaction(new LettuceTxResult(
|
||||||
limit.getCount()), LettuceConverters.scoredValuesToTupleSet()));
|
getConnection().zrangebyscoreWithScores(key, min, max, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.scoredValuesToTupleSet()));
|
||||||
} else {
|
} else {
|
||||||
transaction(new LettuceTxResult(getConnection().zrangebyscoreWithScores(key, min, max),
|
transaction(new LettuceTxResult(getConnection().zrangebyscoreWithScores(key, min, max),
|
||||||
LettuceConverters.scoredValuesToTupleSet()));
|
LettuceConverters.scoredValuesToTupleSet()));
|
||||||
@@ -2349,8 +2389,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
return LettuceConverters.toTupleSet(getConnection().zrangebyscoreWithScores(key, min, max, limit.getOffset(),
|
return LettuceConverters
|
||||||
limit.getCount()));
|
.toTupleSet(getConnection().zrangebyscoreWithScores(key, min, max, limit.getOffset(), limit.getCount()));
|
||||||
}
|
}
|
||||||
return LettuceConverters.toTupleSet(getConnection().zrangebyscoreWithScores(key, min, max));
|
return LettuceConverters.toTupleSet(getConnection().zrangebyscoreWithScores(key, min, max));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -2393,8 +2433,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
@Override
|
@Override
|
||||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count) {
|
public Set<byte[]> 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())
|
return zRevRangeByScore(key, new Range().gte(min).lte(max),
|
||||||
.count(Long.valueOf(count).intValue()));
|
new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -2413,8 +2453,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrevrangebyscore(key, max, min, limit.getOffset(),
|
pipeline(new LettuceResult(
|
||||||
limit.getCount()), LettuceConverters.bytesListToBytesSet()));
|
getAsyncConnection().zrevrangebyscore(key, max, min, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
} else {
|
} else {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrevrangebyscore(key, max, min),
|
pipeline(new LettuceResult(getAsyncConnection().zrevrangebyscore(key, max, min),
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
@@ -2423,8 +2464,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
transaction(new LettuceTxResult(getConnection().zrevrangebyscore(key, max, min, limit.getOffset(),
|
transaction(
|
||||||
limit.getCount()), LettuceConverters.bytesListToBytesSet()));
|
new LettuceTxResult(getConnection().zrevrangebyscore(key, max, min, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
} else {
|
} else {
|
||||||
transaction(new LettuceTxResult(getConnection().zrevrangebyscore(key, max, min),
|
transaction(new LettuceTxResult(getConnection().zrevrangebyscore(key, max, min),
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
@@ -2432,8 +2474,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
return LettuceConverters.toBytesSet(getConnection().zrevrangebyscore(key, max, min, limit.getOffset(),
|
return LettuceConverters
|
||||||
limit.getCount()));
|
.toBytesSet(getConnection().zrevrangebyscore(key, max, min, limit.getOffset(), limit.getCount()));
|
||||||
}
|
}
|
||||||
return LettuceConverters.toBytesSet(getConnection().zrevrangebyscore(key, max, min));
|
return LettuceConverters.toBytesSet(getConnection().zrevrangebyscore(key, max, min));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -2469,8 +2511,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrevrangebyscoreWithScores(key, max, min, limit.getOffset(),
|
pipeline(new LettuceResult(
|
||||||
limit.getCount()), LettuceConverters.scoredValuesToTupleSet()));
|
getAsyncConnection().zrevrangebyscoreWithScores(key, max, min, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.scoredValuesToTupleSet()));
|
||||||
} else {
|
} else {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrevrangebyscoreWithScores(key, max, min),
|
pipeline(new LettuceResult(getAsyncConnection().zrevrangebyscoreWithScores(key, max, min),
|
||||||
LettuceConverters.scoredValuesToTupleSet()));
|
LettuceConverters.scoredValuesToTupleSet()));
|
||||||
@@ -2479,8 +2522,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
transaction(new LettuceTxResult(getConnection().zrevrangebyscoreWithScores(key, max, min, limit.getOffset(),
|
transaction(new LettuceTxResult(
|
||||||
limit.getCount()), LettuceConverters.scoredValuesToTupleSet()));
|
getConnection().zrevrangebyscoreWithScores(key, max, min, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.scoredValuesToTupleSet()));
|
||||||
} else {
|
} else {
|
||||||
transaction(new LettuceTxResult(getConnection().zrevrangebyscoreWithScores(key, max, min),
|
transaction(new LettuceTxResult(getConnection().zrevrangebyscoreWithScores(key, max, min),
|
||||||
LettuceConverters.scoredValuesToTupleSet()));
|
LettuceConverters.scoredValuesToTupleSet()));
|
||||||
@@ -2488,8 +2532,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
return LettuceConverters.toTupleSet(getConnection().zrevrangebyscoreWithScores(key, max, min,
|
return LettuceConverters
|
||||||
limit.getOffset(), limit.getCount()));
|
.toTupleSet(getConnection().zrevrangebyscoreWithScores(key, max, min, limit.getOffset(), limit.getCount()));
|
||||||
}
|
}
|
||||||
return LettuceConverters.toTupleSet(getConnection().zrevrangebyscoreWithScores(key, max, min));
|
return LettuceConverters.toTupleSet(getConnection().zrevrangebyscoreWithScores(key, max, min));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -2586,8 +2630,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().zrevrange(key, start, end),
|
transaction(
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
new LettuceTxResult(getConnection().zrevrange(key, start, end), LettuceConverters.bytesListToBytesSet()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.toBytesSet(getConnection().zrevrange(key, start, end));
|
return LettuceConverters.toBytesSet(getConnection().zrevrange(key, start, end));
|
||||||
@@ -2951,19 +2995,19 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);
|
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);
|
||||||
String convertedScript = LettuceConverters.toString(script);
|
String convertedScript = LettuceConverters.toString(script);
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().eval(convertedScript,
|
pipeline(new LettuceResult(
|
||||||
LettuceConverters.toScriptOutputType(returnType), keys, args), new LettuceEvalResultsConverter<T>(
|
getAsyncConnection().eval(convertedScript, LettuceConverters.toScriptOutputType(returnType), keys, args),
|
||||||
returnType)));
|
new LettuceEvalResultsConverter<T>(returnType)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().eval(convertedScript,
|
transaction(new LettuceTxResult(
|
||||||
LettuceConverters.toScriptOutputType(returnType), keys, args), new LettuceEvalResultsConverter<T>(
|
getConnection().eval(convertedScript, LettuceConverters.toScriptOutputType(returnType), keys, args),
|
||||||
returnType)));
|
new LettuceEvalResultsConverter<T>(returnType)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new LettuceEvalResultsConverter<T>(returnType).convert(getConnection().eval(convertedScript,
|
return new LettuceEvalResultsConverter<T>(returnType)
|
||||||
LettuceConverters.toScriptOutputType(returnType), keys, args));
|
.convert(getConnection().eval(convertedScript, LettuceConverters.toScriptOutputType(returnType), keys, args));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertLettuceAccessException(ex);
|
throw convertLettuceAccessException(ex);
|
||||||
}
|
}
|
||||||
@@ -2975,19 +3019,19 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);
|
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);
|
||||||
|
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().evalsha(scriptSha1,
|
pipeline(new LettuceResult(
|
||||||
LettuceConverters.toScriptOutputType(returnType), keys, args), new LettuceEvalResultsConverter<T>(
|
getAsyncConnection().evalsha(scriptSha1, LettuceConverters.toScriptOutputType(returnType), keys, args),
|
||||||
returnType)));
|
new LettuceEvalResultsConverter<T>(returnType)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().evalsha(scriptSha1,
|
transaction(new LettuceTxResult(
|
||||||
LettuceConverters.toScriptOutputType(returnType), keys, args), new LettuceEvalResultsConverter<T>(
|
getConnection().evalsha(scriptSha1, LettuceConverters.toScriptOutputType(returnType), keys, args),
|
||||||
returnType)));
|
new LettuceEvalResultsConverter<T>(returnType)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new LettuceEvalResultsConverter<T>(returnType).convert(getConnection().evalsha(scriptSha1,
|
return new LettuceEvalResultsConverter<T>(returnType)
|
||||||
LettuceConverters.toScriptOutputType(returnType), keys, args));
|
.convert(getConnection().evalsha(scriptSha1, LettuceConverters.toScriptOutputType(returnType), keys, args));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertLettuceAccessException(ex);
|
throw convertLettuceAccessException(ex);
|
||||||
}
|
}
|
||||||
@@ -3057,184 +3101,367 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Geo functionality
|
// 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<byte[], GeoCoordinate> 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<byte[]> geoHash(byte[] key, byte[]... members) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoCoordinate> 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.geo.Point, byte[])
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) {
|
public Long geoAdd(byte[] key, Point point, byte[] member) {
|
||||||
GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit);
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(point, "Point must not be null!");
|
||||||
|
Assert.notNull(member, "Member must not be null!");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, radius, geoUnit),
|
pipeline(new LettuceResult(getAsyncConnection().geoadd(key, point.getX(), point.getY(), member)));
|
||||||
LettuceConverters.bytesSetToGeoRadiusResponseListConverter()));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, radius, geoUnit),
|
transaction(new LettuceTxResult(getConnection().geoadd(key, point.getX(), point.getY(), member)));
|
||||||
LettuceConverters.bytesSetToGeoRadiusResponseListConverter()));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.bytesSetToGeoRadiusResponseListConverter().
|
return getConnection().geoadd(key, point.getX(), point.getY(), member);
|
||||||
convert(getConnection().georadius(key, longitude, latitude, radius, geoUnit));
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertLettuceAccessException(ex);
|
throw convertLettuceAccessException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Long geoAdd(byte[] key, GeoLocation<byte[]> location) {
|
||||||
GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit);
|
|
||||||
GeoArgs geoArgs = LettuceConverters.toGeoArgs(param);
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(location, "Location must not be null!");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().georadius(key, longitude, latitude, radius, geoUnit, geoArgs),
|
pipeline(new LettuceResult(getAsyncConnection().geoadd(key, location.getPoint().getX(),
|
||||||
LettuceConverters.getGeowithinListToGeoRadiusResponseList()));
|
location.getPoint().getY(), location.getName())));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().georadius(key, longitude, latitude, radius, geoUnit, geoArgs),
|
transaction(new LettuceTxResult(
|
||||||
LettuceConverters.getGeowithinListToGeoRadiusResponseList()));
|
getConnection().geoadd(key, location.getPoint().getX(), location.getPoint().getY(), location.getName())));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.getGeowithinListToGeoRadiusResponseList().
|
return getConnection().geoadd(key, location.getPoint().getX(), location.getPoint().getY(), location.getName());
|
||||||
convert(getConnection().georadius(key, longitude, latitude, radius, geoUnit, geoArgs));
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertLettuceAccessException(ex);
|
throw convertLettuceAccessException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.util.Map)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) {
|
public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) {
|
||||||
GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit);
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(memberCoordinateMap, "MemberCoordinateMap must not be null!");
|
||||||
|
|
||||||
|
List<Object> values = new ArrayList<Object>();
|
||||||
|
for (Entry<byte[], Point> entry : memberCoordinateMap.entrySet()) {
|
||||||
|
|
||||||
|
values.add(entry.getValue().getX());
|
||||||
|
values.add(entry.getValue().getY());
|
||||||
|
values.add(entry.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
return geoAdd(key, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.lang.Iterable)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(locations, "Locations must not be null!");
|
||||||
|
|
||||||
|
List<Object> values = new ArrayList<Object>();
|
||||||
|
for (GeoLocation<byte[]> location : locations) {
|
||||||
|
|
||||||
|
values.add(location.getPoint().getX());
|
||||||
|
values.add(location.getPoint().getY());
|
||||||
|
values.add(location.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return geoAdd(key, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long geoAdd(byte[] key, Collection<Object> values) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().georadiusbymember(key, member, radius, geoUnit),
|
pipeline(new LettuceResult(getAsyncConnection().geoadd(key, values.toArray())));
|
||||||
LettuceConverters.bytesSetToGeoRadiusResponseListConverter()));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().georadiusbymember(key, member, radius, geoUnit),
|
transaction(new LettuceTxResult(getConnection().geoadd(key, values.toArray())));
|
||||||
LettuceConverters.bytesSetToGeoRadiusResponseListConverter()));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.bytesSetToGeoRadiusResponseListConverter().
|
return getConnection().geoadd(key, values.toArray());
|
||||||
convert(getConnection().georadiusbymember(key, member, radius, geoUnit));
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertLettuceAccessException(ex);
|
throw convertLettuceAccessException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[])
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
|
||||||
GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(unit);
|
return geoDist(key, member1, member2, DistanceUnit.METERS);
|
||||||
GeoArgs geoArgs = LettuceConverters.toGeoArgs(param);
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[], org.springframework.data.geo.Metric)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(member1, "Member1 must not be null!");
|
||||||
|
Assert.notNull(member2, "Member2 must not be null!");
|
||||||
|
Assert.notNull(metric, "Metric must not be null!");
|
||||||
|
|
||||||
|
GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(metric);
|
||||||
|
Converter<Double, Distance> distanceConverter = LettuceConverters.distanceConverterForMetric(metric);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().georadiusbymember(key, member, radius, geoUnit, geoArgs),
|
pipeline(new LettuceResult(getAsyncConnection().geodist(key, member1, member2, geoUnit), distanceConverter));
|
||||||
LettuceConverters.getGeowithinListToGeoRadiusResponseList()));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().georadiusbymember(key, member, radius, geoUnit, geoArgs),
|
transaction(new LettuceTxResult(getConnection().geodist(key, member1, member2, geoUnit), distanceConverter));
|
||||||
LettuceConverters.getGeowithinListToGeoRadiusResponseList()));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.getGeowithinListToGeoRadiusResponseList().
|
return distanceConverter.convert(getConnection().geodist(key, member1, member2, geoUnit));
|
||||||
convert(getConnection().georadiusbymember(key, member, radius, geoUnit, geoArgs));
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertLettuceAccessException(ex);
|
throw convertLettuceAccessException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoHash(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> geoHash(byte[] key, byte[]... members) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(members, "Members must not be null!");
|
||||||
|
Assert.noNullElements(members, "Members must not contain null!");
|
||||||
|
|
||||||
|
throw new UnsupportedOperationException("Lettuce does currently not supprt GEOHASH.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoPos(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Point> geoPos(byte[] key, byte[]... members) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(members, "Members must not be null!");
|
||||||
|
Assert.noNullElements(members, "Members must not contain null!");
|
||||||
|
|
||||||
|
ListConverter<GeoCoordinates, Point> converter = LettuceConverters.geoCoordinatesToPointConverter();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isPipelined()) {
|
||||||
|
pipeline(new LettuceResult(getAsyncConnection().geopos(key, members), converter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isQueueing()) {
|
||||||
|
transaction(new LettuceTxResult(getConnection().geopos(key, members), converter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return converter.convert(getConnection().geopos(key, members));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertLettuceAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(within, "Within must not be null!");
|
||||||
|
|
||||||
|
Converter<Set<byte[]>, GeoResults<GeoLocation<byte[]>>> geoResultsConverter = LettuceConverters
|
||||||
|
.bytesSetToGeoResultsConverter();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isPipelined()) {
|
||||||
|
pipeline(new LettuceResult(
|
||||||
|
getAsyncConnection().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
|
||||||
|
within.getRadius().getValue(), LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric())),
|
||||||
|
geoResultsConverter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isQueueing()) {
|
||||||
|
transaction(new LettuceTxResult(
|
||||||
|
getConnection().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
|
||||||
|
within.getRadius().getValue(), LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric())),
|
||||||
|
geoResultsConverter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return geoResultsConverter
|
||||||
|
.convert(getConnection().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
|
||||||
|
within.getRadius().getValue(), LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric())));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertLettuceAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(within, "Within must not be null!");
|
||||||
|
Assert.notNull(args, "Args must not be null!");
|
||||||
|
|
||||||
|
GeoArgs geoArgs = LettuceConverters.toGeoArgs(args);
|
||||||
|
Converter<List<GeoWithin<byte[]>>, GeoResults<GeoLocation<byte[]>>> geoResultsConverter = LettuceConverters
|
||||||
|
.geoRadiusResponseToGeoResultsConverter(within.getRadius().getMetric());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isPipelined()) {
|
||||||
|
pipeline(new LettuceResult(getAsyncConnection().georadius(key, within.getCenter().getX(),
|
||||||
|
within.getCenter().getY(), within.getRadius().getValue(),
|
||||||
|
LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric()), geoArgs), geoResultsConverter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isQueueing()) {
|
||||||
|
transaction(new LettuceTxResult(getConnection().georadius(key, within.getCenter().getX(),
|
||||||
|
within.getCenter().getY(), within.getRadius().getValue(),
|
||||||
|
LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric()), geoArgs), geoResultsConverter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return geoResultsConverter
|
||||||
|
.convert(getConnection().georadius(key, within.getCenter().getX(), within.getCenter().getY(),
|
||||||
|
within.getRadius().getValue(), LettuceConverters.toGeoArgsUnit(within.getRadius().getMetric()), geoArgs));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertLettuceAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], double)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, double radius) {
|
||||||
|
return geoRadiusByMember(key, member, new Distance(radius, DistanceUnit.METERS));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], double, org.springframework.data.geo.Metric)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(member, "Member must not be null!");
|
||||||
|
Assert.notNull(radius, "Radius must not be null!");
|
||||||
|
|
||||||
|
GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(radius.getMetric());
|
||||||
|
Converter<Set<byte[]>, GeoResults<GeoLocation<byte[]>>> converter = LettuceConverters
|
||||||
|
.bytesSetToGeoResultsConverter();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isPipelined()) {
|
||||||
|
pipeline(new LettuceResult(getAsyncConnection().georadiusbymember(key, member, radius.getValue(), geoUnit),
|
||||||
|
converter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isQueueing()) {
|
||||||
|
transaction(
|
||||||
|
new LettuceTxResult(getConnection().georadiusbymember(key, member, radius.getValue(), geoUnit), converter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return converter.convert(getConnection().georadiusbymember(key, member, radius.getValue(), geoUnit));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertLettuceAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
|
||||||
|
GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
Assert.notNull(key, "Key must not be null!");
|
||||||
|
Assert.notNull(member, "Member must not be null!");
|
||||||
|
Assert.notNull(radius, "Radius must not be null!");
|
||||||
|
Assert.notNull(args, "Args must not be null!");
|
||||||
|
|
||||||
|
GeoArgs.Unit geoUnit = LettuceConverters.toGeoArgsUnit(radius.getMetric());
|
||||||
|
GeoArgs geoArgs = LettuceConverters.toGeoArgs(args);
|
||||||
|
Converter<List<GeoWithin<byte[]>>, GeoResults<GeoLocation<byte[]>>> geoResultsConverter = LettuceConverters
|
||||||
|
.geoRadiusResponseToGeoResultsConverter(radius.getMetric());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isPipelined()) {
|
||||||
|
pipeline(
|
||||||
|
new LettuceResult(getAsyncConnection().georadiusbymember(key, member, radius.getValue(), geoUnit, geoArgs),
|
||||||
|
geoResultsConverter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (isQueueing()) {
|
||||||
|
transaction(new LettuceTxResult(
|
||||||
|
getConnection().georadiusbymember(key, member, radius.getValue(), geoUnit, geoArgs), geoResultsConverter));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return geoResultsConverter
|
||||||
|
.convert(getConnection().georadiusbymember(key, member, radius.getValue(), geoUnit, geoArgs));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw convertLettuceAccessException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoRemove(byte[], byte[][])
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long geoRemove(byte[] key, byte[]... values) {
|
public Long geoRemove(byte[] key, byte[]... values) {
|
||||||
return zRem(key, values);
|
return zRem(key, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.redis.connection.RedisServerCommands#time()
|
* @see org.springframework.data.redis.connection.RedisServerCommands#time()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long time() {
|
public Long time() {
|
||||||
try {
|
try {
|
||||||
@@ -3242,8 +3469,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
List<byte[]> result = getConnection().time();
|
List<byte[]> result = getConnection().time();
|
||||||
|
|
||||||
Assert.notEmpty(result, "Received invalid result from server. Expected 2 items in collection.");
|
Assert.notEmpty(result, "Received invalid result from server. Expected 2 items in collection.");
|
||||||
Assert.isTrue(result.size() == 2, "Received invalid nr of arguments from redis server. Expected 2 received "
|
Assert.isTrue(result.size() == 2,
|
||||||
+ result.size());
|
"Received invalid nr of arguments from redis server. Expected 2 received " + result.size());
|
||||||
|
|
||||||
return Converters.toTimeMillis(new String(result.get(0)), new String(result.get(1)));
|
return Converters.toTimeMillis(new String(result.get(0)), new String(result.get(1)));
|
||||||
|
|
||||||
@@ -3338,8 +3565,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
throw new UnsupportedOperationException("Cannot be called in pipeline mode.");
|
throw new UnsupportedOperationException("Cannot be called in pipeline mode.");
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getAsyncConnection().clientList(),
|
transaction(
|
||||||
LettuceConverters.stringToRedisClientListConverter()));
|
new LettuceTxResult(getAsyncConnection().clientList(), LettuceConverters.stringToRedisClientListConverter()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3800,10 +4027,10 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
*/
|
*/
|
||||||
static class TypeHints {
|
static class TypeHints {
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")//
|
@SuppressWarnings("rawtypes") //
|
||||||
private static final Map<CommandType, Class<? extends CommandOutput>> COMMAND_OUTPUT_TYPE_MAPPING = new HashMap<CommandType, Class<? extends CommandOutput>>();
|
private static final Map<CommandType, Class<? extends CommandOutput>> COMMAND_OUTPUT_TYPE_MAPPING = new HashMap<CommandType, Class<? extends CommandOutput>>();
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")//
|
@SuppressWarnings("rawtypes") //
|
||||||
private static final Map<Class<?>, Constructor<CommandOutput>> CONSTRUCTORS = new ConcurrentHashMap<Class<?>, Constructor<CommandOutput>>();
|
private static final Map<Class<?>, Constructor<CommandOutput>> CONSTRUCTORS = new ConcurrentHashMap<Class<?>, Constructor<CommandOutput>>();
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -4004,8 +4231,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().zrangebyscore(key, min, max),
|
transaction(
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
new LettuceTxResult(getConnection().zrangebyscore(key, min, max), LettuceConverters.bytesListToBytesSet()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, min, max));
|
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, min, max));
|
||||||
@@ -4049,7 +4276,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
if (values.length == 1) {
|
if (values.length == 1) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().pfadd(key, values[0])));
|
pipeline(new LettuceResult(getAsyncConnection().pfadd(key, values[0])));
|
||||||
} else {
|
} else {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().pfadd(key, values[0], LettuceConverters.subarray(values, 1))));
|
pipeline(
|
||||||
|
new LettuceResult(getAsyncConnection().pfadd(key, values[0], LettuceConverters.subarray(values, 1))));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -4057,7 +4285,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
if (values.length == 1) {
|
if (values.length == 1) {
|
||||||
transaction(new LettuceTxResult(getConnection().pfadd(key, values[0])));
|
transaction(new LettuceTxResult(getConnection().pfadd(key, values[0])));
|
||||||
} else {
|
} else {
|
||||||
transaction(new LettuceTxResult(getConnection().pfadd(key, values[0], LettuceConverters.subarray(values, 1))));
|
transaction(
|
||||||
|
new LettuceTxResult(getConnection().pfadd(key, values[0], LettuceConverters.subarray(values, 1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -4126,16 +4355,16 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
if (sourceKeys.length == 1) {
|
if (sourceKeys.length == 1) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().pfmerge(destinationKey, sourceKeys[0])));
|
pipeline(new LettuceResult(getAsyncConnection().pfmerge(destinationKey, sourceKeys[0])));
|
||||||
} else {
|
} else {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().pfmerge(destinationKey, sourceKeys[0],
|
pipeline(new LettuceResult(
|
||||||
LettuceConverters.subarray(sourceKeys, 1))));
|
getAsyncConnection().pfmerge(destinationKey, sourceKeys[0], LettuceConverters.subarray(sourceKeys, 1))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
if (sourceKeys.length == 1) {
|
if (sourceKeys.length == 1) {
|
||||||
transaction(new LettuceTxResult(getConnection().pfmerge(destinationKey, sourceKeys[0])));
|
transaction(new LettuceTxResult(getConnection().pfmerge(destinationKey, sourceKeys[0])));
|
||||||
} else {
|
} else {
|
||||||
transaction(new LettuceTxResult(getConnection().pfmerge(destinationKey, sourceKeys[0],
|
transaction(new LettuceTxResult(
|
||||||
LettuceConverters.subarray(sourceKeys, 1))));
|
getConnection().pfmerge(destinationKey, sourceKeys[0], LettuceConverters.subarray(sourceKeys, 1))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4182,8 +4411,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrangebylex(key, min, max, limit.getOffset(),
|
pipeline(
|
||||||
limit.getCount()), LettuceConverters.bytesListToBytesSet()));
|
new LettuceResult(getAsyncConnection().zrangebylex(key, min, max, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
} else {
|
} else {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().zrangebylex(key, min, max),
|
pipeline(new LettuceResult(getAsyncConnection().zrangebylex(key, min, max),
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
@@ -4192,18 +4422,19 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
transaction(new LettuceTxResult(getConnection().zrangebylex(key, min, max, limit.getOffset(),
|
transaction(
|
||||||
limit.getCount()), LettuceConverters.bytesListToBytesSet()));
|
new LettuceTxResult(getConnection().zrangebylex(key, min, max, limit.getOffset(), limit.getCount()),
|
||||||
|
LettuceConverters.bytesListToBytesSet()));
|
||||||
} else {
|
} else {
|
||||||
transaction(new LettuceTxResult(getConnection().zrangebylex(key, min, max),
|
transaction(
|
||||||
LettuceConverters.bytesListToBytesSet()));
|
new LettuceTxResult(getConnection().zrangebylex(key, min, max), LettuceConverters.bytesListToBytesSet()));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
return LettuceConverters.bytesListToBytesSet().convert(
|
return LettuceConverters.bytesListToBytesSet()
|
||||||
getConnection().zrangebylex(key, min, max, limit.getOffset(), limit.getCount()));
|
.convert(getConnection().zrangebylex(key, min, max, limit.getOffset(), limit.getCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return LettuceConverters.bytesListToBytesSet().convert(getConnection().zrangebylex(key, min, max));
|
return LettuceConverters.bytesListToBytesSet().convert(getConnection().zrangebylex(key, min, max));
|
||||||
@@ -4230,13 +4461,13 @@ public class LettuceConnection extends AbstractRedisConnection {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new LettuceResult(getAsyncConnection().migrate(target.getHost(), target.getPort(), key, dbIndex,
|
pipeline(
|
||||||
timeout)));
|
new LettuceResult(getAsyncConnection().migrate(target.getHost(), target.getPort(), key, dbIndex, timeout)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isQueueing()) {
|
if (isQueueing()) {
|
||||||
transaction(new LettuceTxResult(getConnection().migrate(target.getHost(), target.getPort(), key, dbIndex,
|
transaction(
|
||||||
timeout)));
|
new LettuceTxResult(getConnection().migrate(target.getHost(), target.getPort(), key, dbIndex, timeout)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getConnection().migrate(target.getHost(), target.getPort(), key, dbIndex, timeout);
|
getConnection().migrate(target.getHost(), target.getPort(), key, dbIndex, timeout);
|
||||||
|
|||||||
@@ -28,14 +28,22 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.lambdaworks.redis.*;
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResult;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Metrics;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.connection.DefaultTuple;
|
import org.springframework.data.redis.connection.DefaultTuple;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
|
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode.LinkState;
|
import org.springframework.data.redis.connection.RedisClusterNode.LinkState;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
|
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||||
import org.springframework.data.redis.connection.RedisNode;
|
import org.springframework.data.redis.connection.RedisNode;
|
||||||
import org.springframework.data.redis.connection.RedisNode.NodeType;
|
import org.springframework.data.redis.connection.RedisNode.NodeType;
|
||||||
@@ -51,16 +59,21 @@ import org.springframework.data.redis.connection.convert.Converters;
|
|||||||
import org.springframework.data.redis.connection.convert.ListConverter;
|
import org.springframework.data.redis.connection.convert.ListConverter;
|
||||||
import org.springframework.data.redis.connection.convert.LongToBooleanConverter;
|
import org.springframework.data.redis.connection.convert.LongToBooleanConverter;
|
||||||
import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
|
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.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.lambdaworks.redis.GeoArgs;
|
||||||
|
import com.lambdaworks.redis.GeoCoordinates;
|
||||||
|
import com.lambdaworks.redis.GeoWithin;
|
||||||
|
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.Partitions;
|
||||||
import com.lambdaworks.redis.cluster.models.partitions.RedisClusterNode.NodeFlag;
|
import com.lambdaworks.redis.cluster.models.partitions.RedisClusterNode.NodeFlag;
|
||||||
import com.lambdaworks.redis.protocol.LettuceCharsets;
|
import com.lambdaworks.redis.protocol.LettuceCharsets;
|
||||||
@@ -73,6 +86,7 @@ import com.lambdaworks.redis.protocol.SetArgs;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
abstract public class LettuceConverters extends Converters {
|
abstract public class LettuceConverters extends Converters {
|
||||||
|
|
||||||
@@ -92,10 +106,8 @@ abstract public class LettuceConverters extends Converters {
|
|||||||
private static final Converter<String[], List<RedisClientInfo>> STRING_TO_LIST_OF_CLIENT_INFO = new StringToRedisClientInfoConverter();
|
private static final Converter<String[], List<RedisClientInfo>> STRING_TO_LIST_OF_CLIENT_INFO = new StringToRedisClientInfoConverter();
|
||||||
private static final Converter<Partitions, List<RedisClusterNode>> PARTITIONS_TO_CLUSTER_NODES;
|
private static final Converter<Partitions, List<RedisClusterNode>> PARTITIONS_TO_CLUSTER_NODES;
|
||||||
private static Converter<com.lambdaworks.redis.cluster.models.partitions.RedisClusterNode, RedisClusterNode> CLUSTER_NODE_TO_CLUSTER_NODE_CONVERTER;
|
private static Converter<com.lambdaworks.redis.cluster.models.partitions.RedisClusterNode, RedisClusterNode> CLUSTER_NODE_TO_CLUSTER_NODE_CONVERTER;
|
||||||
private static final Converter<com.lambdaworks.redis.GeoCoordinates, GeoCoordinate> GEO_COORDINATE_CONVERTER;
|
private static final Converter<GeoCoordinates, Point> GEO_COORDINATE_TO_POINT_CONVERTER;
|
||||||
private static final ListConverter<com.lambdaworks.redis.GeoCoordinates, GeoCoordinate> GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST;
|
private static final ListConverter<GeoCoordinates, Point> GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER;
|
||||||
private static final Converter<Set<byte[]>, List<GeoRadiusResponse>> BYTES_SET_TO_GEO_RADIUS_RESPONSE_LIST;
|
|
||||||
private static final Converter<List<GeoWithin<byte[]>>, List<GeoRadiusResponse>> GEOWITHIN_LIST_TO_GEO_RADIUS_RESPONSE_LIST;
|
|
||||||
|
|
||||||
public static final byte[] PLUS_BYTES;
|
public static final byte[] PLUS_BYTES;
|
||||||
public static final byte[] MINUS_BYTES;
|
public static final byte[] MINUS_BYTES;
|
||||||
@@ -210,8 +222,8 @@ abstract public class LettuceConverters extends Converters {
|
|||||||
List<Tuple> tuples = new ArrayList<Tuple>();
|
List<Tuple> tuples = new ArrayList<Tuple>();
|
||||||
Iterator<byte[]> it = source.iterator();
|
Iterator<byte[]> it = source.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
tuples.add(new DefaultTuple(it.next(), it.hasNext() ? Double.valueOf(LettuceConverters.toString(it.next()))
|
tuples.add(
|
||||||
: null));
|
new DefaultTuple(it.next(), it.hasNext() ? Double.valueOf(LettuceConverters.toString(it.next())) : null));
|
||||||
}
|
}
|
||||||
return tuples;
|
return tuples;
|
||||||
}
|
}
|
||||||
@@ -245,8 +257,8 @@ abstract public class LettuceConverters extends Converters {
|
|||||||
return RedisClusterNode.newRedisClusterNode().listeningAt(source.getUri().getHost(), source.getUri().getPort())
|
return RedisClusterNode.newRedisClusterNode().listeningAt(source.getUri().getHost(), source.getUri().getPort())
|
||||||
.withId(source.getNodeId()).promotedAs(flags.contains(Flag.MASTER) ? NodeType.MASTER : NodeType.SLAVE)
|
.withId(source.getNodeId()).promotedAs(flags.contains(Flag.MASTER) ? NodeType.MASTER : NodeType.SLAVE)
|
||||||
.serving(new SlotRange(source.getSlots())).withFlags(flags)
|
.serving(new SlotRange(source.getSlots())).withFlags(flags)
|
||||||
.linkState(source.isConnected() ? LinkState.CONNECTED : LinkState.DISCONNECTED)
|
.linkState(source.isConnected() ? LinkState.CONNECTED : LinkState.DISCONNECTED).slaveOf(source.getSlaveOf())
|
||||||
.slaveOf(source.getSlaveOf()).build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Flag> parseFlags(Set<NodeFlag> source) {
|
private Set<Flag> parseFlags(Set<NodeFlag> source) {
|
||||||
@@ -290,53 +302,14 @@ abstract public class LettuceConverters extends Converters {
|
|||||||
POSITIVE_INFINITY_BYTES = toBytes("+inf");
|
POSITIVE_INFINITY_BYTES = toBytes("+inf");
|
||||||
NEGATIVE_INFINITY_BYTES = toBytes("-inf");
|
NEGATIVE_INFINITY_BYTES = toBytes("-inf");
|
||||||
|
|
||||||
GEO_COORDINATE_CONVERTER = new Converter<com.lambdaworks.redis.GeoCoordinates, GeoCoordinate>() {
|
GEO_COORDINATE_TO_POINT_CONVERTER = new Converter<com.lambdaworks.redis.GeoCoordinates, Point>() {
|
||||||
@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<com.lambdaworks.redis.GeoCoordinates, GeoCoordinate>(GEO_COORDINATE_CONVERTER);
|
|
||||||
|
|
||||||
BYTES_SET_TO_GEO_RADIUS_RESPONSE_LIST = new Converter<Set<byte[]>, List<GeoRadiusResponse>>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> convert(Set<byte[]> source) {
|
public Point convert(com.lambdaworks.redis.GeoCoordinates geoCoordinate) {
|
||||||
|
return geoCoordinate != null ? new Point(geoCoordinate.x.doubleValue(), geoCoordinate.y.doubleValue()) : null;
|
||||||
if (CollectionUtils.isEmpty(source)) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<GeoRadiusResponse> geoRadiusResponses = new ArrayList<GeoRadiusResponse>();
|
|
||||||
Iterator<byte[]> it = source.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
geoRadiusResponses.add(new GeoRadiusResponse(it.next()));
|
|
||||||
}
|
|
||||||
return geoRadiusResponses;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GEOWITHIN_LIST_TO_GEO_RADIUS_RESPONSE_LIST = new Converter<List<GeoWithin<byte[]>>, List<GeoRadiusResponse>>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoRadiusResponse> convert(List<GeoWithin<byte[]>> source) {
|
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(source)) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<GeoRadiusResponse> geoRadiusResponses = new ArrayList<GeoRadiusResponse>();
|
|
||||||
Iterator<GeoWithin<byte[]>> it = source.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
GeoWithin<byte[]> 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;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER = new ListConverter<GeoCoordinates, Point>(
|
||||||
|
GEO_COORDINATE_TO_POINT_CONVERTER);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,14 +321,6 @@ abstract public class LettuceConverters extends Converters {
|
|||||||
return BYTES_LIST_TO_TUPLE_LIST_CONVERTER;
|
return BYTES_LIST_TO_TUPLE_LIST_CONVERTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Converter<Set<byte[]>, List<GeoRadiusResponse>> bytesSetToGeoRadiusResponseListConverter() {
|
|
||||||
return BYTES_SET_TO_GEO_RADIUS_RESPONSE_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Converter<List<GeoWithin<byte[]>>, List<GeoRadiusResponse>> getGeowithinListToGeoRadiusResponseList() {
|
|
||||||
return GEOWITHIN_LIST_TO_GEO_RADIUS_RESPONSE_LIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Converter<String, List<RedisClientInfo>> stringToRedisClientListConverter() {
|
public static Converter<String, List<RedisClientInfo>> stringToRedisClientListConverter() {
|
||||||
return new Converter<String, List<RedisClientInfo>>() {
|
return new Converter<String, List<RedisClientInfo>>() {
|
||||||
|
|
||||||
@@ -406,8 +371,6 @@ abstract public class LettuceConverters extends Converters {
|
|||||||
return EXCEPTION_CONVERTER;
|
return EXCEPTION_CONVERTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ListConverter<com.lambdaworks.redis.GeoCoordinates, GeoCoordinate> geoCoordinateListToGeoCoordinateList() { return GEO_COORDINATE_LIST_TO_GEO_COORDINATE_LIST; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
* @sice 1.3
|
* @sice 1.3
|
||||||
@@ -579,8 +542,8 @@ abstract public class LettuceConverters extends Converters {
|
|||||||
for (RedisNode sentinel : sentinels) {
|
for (RedisNode sentinel : sentinels) {
|
||||||
|
|
||||||
if (builder == null) {
|
if (builder == null) {
|
||||||
builder = RedisURI.Builder.sentinel(sentinel.getHost(), sentinel.getPort(), sentinelConfiguration.getMaster()
|
builder = RedisURI.Builder.sentinel(sentinel.getHost(), sentinel.getPort(),
|
||||||
.getName());
|
sentinelConfiguration.getMaster().getName());
|
||||||
} else {
|
} else {
|
||||||
builder.withSentinel(sentinel.getHost(), sentinel.getPort());
|
builder.withSentinel(sentinel.getHost(), sentinel.getPort());
|
||||||
}
|
}
|
||||||
@@ -717,36 +680,176 @@ abstract public class LettuceConverters extends Converters {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static com.lambdaworks.redis.GeoArgs.Unit toGeoArgsUnit(GeoUnit geoUnit){
|
/**
|
||||||
switch (geoUnit){
|
* Convert {@link Metric} into {@link GeoArgs.Unit}.
|
||||||
case Meters: return GeoArgs.Unit.m;
|
*
|
||||||
case KiloMeters: return GeoArgs.Unit.km;
|
* @param metric
|
||||||
case Miles: return GeoArgs.Unit.mi;
|
* @return
|
||||||
case Feet: return GeoArgs.Unit.ft;
|
* @since 1.8
|
||||||
default: throw new IllegalArgumentException("geoUnit not supported");
|
*/
|
||||||
}
|
public static GeoArgs.Unit toGeoArgsUnit(Metric metric) {
|
||||||
}
|
|
||||||
|
|
||||||
public static com.lambdaworks.redis.GeoArgs toGeoArgs(GeoRadiusParam geoRadiusParam){
|
Metric metricToUse = metric == null || ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, metric) ? DistanceUnit.METERS
|
||||||
com.lambdaworks.redis.GeoArgs geoArgs = new GeoArgs();
|
: metric;
|
||||||
for (String k : geoRadiusParam.getParams().keySet()){
|
return ObjectUtils.caseInsensitiveValueOf(GeoArgs.Unit.values(), metricToUse.getAbbreviation());
|
||||||
if (k.equals(GeoRadiusParam.getASC()))
|
}
|
||||||
geoArgs.asc();
|
|
||||||
else if (k.equals(GeoRadiusParam.getDESC()))
|
/**
|
||||||
geoArgs.desc();
|
* Convert {@link GeoRadiusCommandArgs} into {@link GeoArgs}.
|
||||||
else if (k.equals(GeoRadiusParam.getCOUNT()))
|
*
|
||||||
geoArgs.withCount((Integer)geoRadiusParam.getParams().get(k));
|
* @param args
|
||||||
else if (k.equals(GeoRadiusParam.getWITHCOORD()))
|
* @return
|
||||||
geoArgs.withCoordinates();
|
* @since 1.8
|
||||||
else if (k.equals(GeoRadiusParam.getWITHDIST()))
|
*/
|
||||||
geoArgs.withDistance();
|
public static GeoArgs toGeoArgs(GeoRadiusCommandArgs args) {
|
||||||
else
|
|
||||||
throw new IllegalArgumentException("unknown key value");
|
GeoArgs geoArgs = new GeoArgs();
|
||||||
|
|
||||||
|
if (args.hasFlags()) {
|
||||||
|
for (GeoRadiusCommandArgs.Flag flag : args.getFlags()) {
|
||||||
|
switch (flag) {
|
||||||
|
case WITHCOORD:
|
||||||
|
geoArgs.withCoordinates();
|
||||||
|
break;
|
||||||
|
case WITHDIST:
|
||||||
|
geoArgs.withDistance();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.hasSortDirection()) {
|
||||||
|
switch (args.getSortDirection()) {
|
||||||
|
case ASC:
|
||||||
|
geoArgs.asc();
|
||||||
|
break;
|
||||||
|
case DESC:
|
||||||
|
geoArgs.desc();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.hasLimit()) {
|
||||||
|
geoArgs.withCount(args.getLimit());
|
||||||
}
|
}
|
||||||
return geoArgs;
|
return geoArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get {@link Converter} capable of {@link Set} of {@link Byte} into {@link GeoResults}.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static Converter<Set<byte[]>, GeoResults<GeoLocation<byte[]>>> bytesSetToGeoResultsConverter() {
|
||||||
|
return new Converter<Set<byte[]>, GeoResults<GeoLocation<byte[]>>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> convert(Set<byte[]> source) {
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(source)) {
|
||||||
|
return new GeoResults<GeoLocation<byte[]>>(Collections.<GeoResult<GeoLocation<byte[]>>> emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<GeoResult<GeoLocation<byte[]>>> results = new ArrayList<GeoResult<GeoLocation<byte[]>>>(source.size());
|
||||||
|
Iterator<byte[]> it = source.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
results.add(new GeoResult<GeoLocation<byte[]>>(new GeoLocation<byte[]>(it.next(), null), new Distance(0D)));
|
||||||
|
}
|
||||||
|
return new GeoResults<GeoLocation<byte[]>>(results);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get {@link Converter} capable of convering {@link GeoWithin} into {@link GeoResults}.
|
||||||
|
*
|
||||||
|
* @param metric
|
||||||
|
* @return
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static Converter<List<GeoWithin<byte[]>>, GeoResults<GeoLocation<byte[]>>> geoRadiusResponseToGeoResultsConverter(
|
||||||
|
Metric metric) {
|
||||||
|
return GeoResultsConverterFactory.INSTANCE.forMetric(metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public static ListConverter<com.lambdaworks.redis.GeoCoordinates, Point> geoCoordinatesToPointConverter() {
|
||||||
|
return GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
static enum GeoResultsConverterFactory {
|
||||||
|
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
Converter<List<GeoWithin<byte[]>>, GeoResults<GeoLocation<byte[]>>> forMetric(Metric metric) {
|
||||||
|
return new GeoResultsConverter(
|
||||||
|
metric == null || ObjectUtils.nullSafeEquals(Metrics.NEUTRAL, metric) ? DistanceUnit.METERS : metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GeoResultsConverter
|
||||||
|
implements Converter<List<GeoWithin<byte[]>>, GeoResults<GeoLocation<byte[]>>> {
|
||||||
|
|
||||||
|
private Metric metric;
|
||||||
|
|
||||||
|
public GeoResultsConverter(Metric metric) {
|
||||||
|
this.metric = metric;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> convert(List<GeoWithin<byte[]>> source) {
|
||||||
|
|
||||||
|
List<GeoResult<GeoLocation<byte[]>>> results = new ArrayList<GeoResult<GeoLocation<byte[]>>>(source.size());
|
||||||
|
|
||||||
|
Converter<GeoWithin<byte[]>, GeoResult<GeoLocation<byte[]>>> converter = GeoResultConverterFactory.INSTANCE
|
||||||
|
.forMetric(metric);
|
||||||
|
for (GeoWithin<byte[]> result : source) {
|
||||||
|
results.add(converter.convert(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GeoResults<GeoLocation<byte[]>>(results, metric);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
static enum GeoResultConverterFactory {
|
||||||
|
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
Converter<GeoWithin<byte[]>, GeoResult<GeoLocation<byte[]>>> forMetric(Metric metric) {
|
||||||
|
return new GeoResultConverter(metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GeoResultConverter implements Converter<GeoWithin<byte[]>, GeoResult<GeoLocation<byte[]>>> {
|
||||||
|
|
||||||
|
private Metric metric;
|
||||||
|
|
||||||
|
public GeoResultConverter(Metric metric) {
|
||||||
|
this.metric = metric;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResult<GeoLocation<byte[]>> convert(GeoWithin<byte[]> source) {
|
||||||
|
|
||||||
|
Point point = GEO_COORDINATE_TO_POINT_CONVERTER.convert(source.coordinates);
|
||||||
|
|
||||||
|
return new GeoResult<GeoLocation<byte[]>>(new GeoLocation<byte[]>(source.member, point),
|
||||||
|
new Distance(source.distance != null ? source.distance : 0D, metric));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ import java.util.concurrent.Future;
|
|||||||
|
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.ExceptionTranslationStrategy;
|
import org.springframework.data.redis.ExceptionTranslationStrategy;
|
||||||
import org.springframework.data.redis.FallbackExceptionTranslationStrategy;
|
import org.springframework.data.redis.FallbackExceptionTranslationStrategy;
|
||||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||||
@@ -44,11 +49,17 @@ import org.springframework.data.redis.connection.RedisSubscribedConnectionExcept
|
|||||||
import org.springframework.data.redis.connection.ReturnType;
|
import org.springframework.data.redis.connection.ReturnType;
|
||||||
import org.springframework.data.redis.connection.SortParameters;
|
import org.springframework.data.redis.connection.SortParameters;
|
||||||
import org.springframework.data.redis.connection.Subscription;
|
import org.springframework.data.redis.connection.Subscription;
|
||||||
import org.springframework.data.redis.core.*;
|
import org.springframework.data.redis.core.Cursor;
|
||||||
|
import org.springframework.data.redis.core.ScanOptions;
|
||||||
import org.springframework.data.redis.core.types.Expiration;
|
import org.springframework.data.redis.core.types.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
|
import com.google.common.util.concurrent.Futures;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
import redis.Command;
|
import redis.Command;
|
||||||
import redis.client.RedisClient;
|
import redis.client.RedisClient;
|
||||||
import redis.client.RedisClient.Pipeline;
|
import redis.client.RedisClient.Pipeline;
|
||||||
@@ -56,11 +67,6 @@ import redis.client.RedisException;
|
|||||||
import redis.reply.MultiBulkReply;
|
import redis.reply.MultiBulkReply;
|
||||||
import redis.reply.Reply;
|
import redis.reply.Reply;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
|
||||||
import com.google.common.util.concurrent.Futures;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code RedisConnection} implementation on top of <a href="https://github.com/spullara/redis-protocol">spullara Redis
|
* {@code RedisConnection} implementation on top of <a href="https://github.com/spullara/redis-protocol">spullara Redis
|
||||||
* Protocol</a> library.
|
* Protocol</a> library.
|
||||||
@@ -70,6 +76,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author David Liu
|
* @author David Liu
|
||||||
|
* @author Ninad Divadkar
|
||||||
* @deprecated since 1.7. Will be removed in subsequent version.
|
* @deprecated since 1.7. Will be removed in subsequent version.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@@ -134,8 +141,8 @@ public class SrpConnection extends AbstractRedisConnection {
|
|||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
if (futureResults.size() != results.size() + txResults) {
|
if (futureResults.size() != results.size() + txResults) {
|
||||||
throw new RedisPipelineException("Received a different number of results than expected. Expected: "
|
throw new RedisPipelineException(
|
||||||
+ futureResults.size(), results);
|
"Received a different number of results than expected. Expected: " + futureResults.size(), results);
|
||||||
}
|
}
|
||||||
List<Object> convertedResults = new ArrayList<Object>();
|
List<Object> convertedResults = new ArrayList<Object>();
|
||||||
|
|
||||||
@@ -1747,8 +1754,8 @@ public class SrpConnection extends AbstractRedisConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count) {
|
public Set<byte[]> 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())
|
return zRevRangeByScore(key, new Range().gte(min).lte(max),
|
||||||
.count(Long.valueOf(count).intValue()));
|
new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1785,8 +1792,8 @@ public class SrpConnection extends AbstractRedisConnection {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new SrpResult(pipeline.zrevrangebyscore(key, max, min, null, params),
|
pipeline(
|
||||||
SrpConverters.repliesToBytesSet()));
|
new SrpResult(pipeline.zrevrangebyscore(key, max, min, null, params), SrpConverters.repliesToBytesSet()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return SrpConverters.toBytesSet(client.zrevrangebyscore(key, max, min, null, params).data());
|
return SrpConverters.toBytesSet(client.zrevrangebyscore(key, max, min, null, params).data());
|
||||||
@@ -2137,8 +2144,8 @@ public class SrpConnection extends AbstractRedisConnection {
|
|||||||
public List<Boolean> scriptExists(String... scriptSha1) {
|
public List<Boolean> scriptExists(String... scriptSha1) {
|
||||||
try {
|
try {
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new SrpGenericResult(pipeline.script_exists((Object[]) scriptSha1),
|
pipeline(
|
||||||
SrpConverters.repliesToBooleanList()));
|
new SrpGenericResult(pipeline.script_exists((Object[]) scriptSha1), SrpConverters.repliesToBooleanList()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return SrpConverters.toBooleanList(((MultiBulkReply) client.script_exists_((Object[]) scriptSha1)).data());
|
return SrpConverters.toBooleanList(((MultiBulkReply) client.script_exists_((Object[]) scriptSha1)).data());
|
||||||
@@ -2155,8 +2162,8 @@ public class SrpConnection extends AbstractRedisConnection {
|
|||||||
new SrpScriptReturnConverter(returnType)));
|
new SrpScriptReturnConverter(returnType)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (T) new SrpScriptReturnConverter(returnType).convert(client.eval(script, numKeys, (Object[]) keysAndArgs)
|
return (T) new SrpScriptReturnConverter(returnType)
|
||||||
.data());
|
.convert(client.eval(script, numKeys, (Object[]) keysAndArgs).data());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertSrpAccessException(ex);
|
throw convertSrpAccessException(ex);
|
||||||
}
|
}
|
||||||
@@ -2170,8 +2177,8 @@ public class SrpConnection extends AbstractRedisConnection {
|
|||||||
new SrpScriptReturnConverter(returnType)));
|
new SrpScriptReturnConverter(returnType)));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (T) new SrpScriptReturnConverter(returnType).convert(client.evalsha(scriptSha1, numKeys,
|
return (T) new SrpScriptReturnConverter(returnType)
|
||||||
(Object[]) keysAndArgs).data());
|
.convert(client.evalsha(scriptSha1, numKeys, (Object[]) keysAndArgs).data());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw convertSrpAccessException(ex);
|
throw convertSrpAccessException(ex);
|
||||||
}
|
}
|
||||||
@@ -2240,58 +2247,130 @@ public class SrpConnection extends AbstractRedisConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) {
|
* (non-Javadoc)
|
||||||
throw new UnsupportedOperationException();
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.geo.Point, byte[])
|
||||||
}
|
*/
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long geoAdd(byte[] key, Map<byte[], GeoCoordinate> 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<byte[]> geoHash(byte[] key, byte[]... members) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoCoordinate> geoPos(byte[] key, byte[]... members) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) {
|
public Long geoAdd(byte[] key, Point point, byte[] member) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Long geoAdd(byte[] key, GeoLocation<byte[]> location) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.util.Map)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) {
|
public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoAdd(byte[], java.lang.Iterable)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[])
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long geoRemove(byte[] key, byte[]... values) {
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoDist(byte[], byte[], byte[], org.springframework.data.geo.Metric)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoHash(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> geoHash(byte[] key, byte[]... members) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoPos(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Point> geoPos(byte[] key, byte[]... members) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadius(byte[], org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs args) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], double)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, double radius) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#georadiusByMember(byte[], byte[], org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
|
||||||
|
GeoRadiusCommandArgs param) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoRemove(byte[], byte[][])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoRemove(byte[] key, byte[]... members) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2626,7 +2705,8 @@ public class SrpConnection extends AbstractRedisConnection {
|
|||||||
String keyStr = new String(key, "UTF-8");
|
String keyStr = new String(key, "UTF-8");
|
||||||
Object[] limit = limitParams(offset, count);
|
Object[] limit = limitParams(offset, count);
|
||||||
if (isPipelined()) {
|
if (isPipelined()) {
|
||||||
pipeline(new SrpResult(pipeline.zrangebyscore(keyStr, min, max, null, limit), SrpConverters.repliesToBytesSet()));
|
pipeline(
|
||||||
|
new SrpResult(pipeline.zrangebyscore(keyStr, min, max, null, limit), SrpConverters.repliesToBytesSet()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return SrpConverters.toBytesSet(client.zrangebyscore(keyStr, min, max, null, limit).data());
|
return SrpConverters.toBytesSet(client.zrangebyscore(keyStr, min, max, null, limit).data());
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2015 the original author or authors.
|
* Copyright 2011-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,9 +23,12 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
import org.springframework.data.redis.connection.DefaultTuple;
|
import org.springframework.data.redis.connection.DefaultTuple;
|
||||||
import org.springframework.data.redis.connection.RedisConnection;
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||||
|
import org.springframework.data.redis.connection.convert.Converters;
|
||||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
import org.springframework.data.redis.serializer.SerializationUtils;
|
import org.springframework.data.redis.serializer.SerializationUtils;
|
||||||
@@ -334,4 +337,20 @@ abstract class AbstractOperations<K, V> {
|
|||||||
}
|
}
|
||||||
return (HV) hashValueSerializer().deserialize(value);
|
return (HV) hashValueSerializer().deserialize(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize {@link GeoLocation} of {@link GeoResults}.
|
||||||
|
*
|
||||||
|
* @param source can be {@literal null}.
|
||||||
|
* @return converted or {@literal null}.
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<V>> deserializeGeoResults(GeoResults<GeoLocation<byte[]>> source) {
|
||||||
|
|
||||||
|
if (valueSerializer() == null) {
|
||||||
|
return (GeoResults<GeoLocation<V>>) (Object) source;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Converters.deserializingGeoResultsConverter((RedisSerializer<V>) valueSerializer()).convert(source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2014 the original author or authors.
|
* Copyright 2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,35 +18,157 @@ package org.springframework.data.redis.core;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash operations bound to a certain key.
|
* {@link GeoOperations} bound to a certain key.
|
||||||
*
|
*
|
||||||
* @author Ninad Divadkar
|
* @author Ninad Divadkar
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public interface BoundGeoOperations<K,M> extends BoundKeyOperations<K> {
|
public interface BoundGeoOperations<K, M> extends BoundKeyOperations<K> {
|
||||||
Long geoAdd(K key, double longitude, double latitude, M member);
|
|
||||||
|
|
||||||
Long geoAdd(K key, Map<M, GeoCoordinate> memberCoordinateMap);
|
/**
|
||||||
|
* Add {@link Point} with given member {@literal name} to {@literal key}.
|
||||||
|
*
|
||||||
|
* @param point must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @return Number of elements added.
|
||||||
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
|
*/
|
||||||
|
Long geoAdd(Point point, M member);
|
||||||
|
|
||||||
Double geoDist(K key, M member1, M member2);
|
/**
|
||||||
|
* Add {@link GeoLocation} to {@literal key}.
|
||||||
|
*
|
||||||
|
* @param location must not be {@literal null}.
|
||||||
|
* @return Number of elements added.
|
||||||
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
|
*/
|
||||||
|
Long geoAdd(GeoLocation<M> location);
|
||||||
|
|
||||||
Double geoDist(K key, M member1, M member2, GeoUnit unit);
|
/**
|
||||||
|
* Add {@link Map} of member / {@link Point} pairs to {@literal key}.
|
||||||
|
*
|
||||||
|
* @param memberCoordinateMap must not be {@literal null}.
|
||||||
|
* @return Number of elements added.
|
||||||
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
|
*/
|
||||||
|
Long geoAdd(Map<M, Point> memberCoordinateMap);
|
||||||
|
|
||||||
List<byte[]> geoHash(K key, M... members);
|
/**
|
||||||
|
* Add {@link GeoLocation}s to {@literal key}
|
||||||
|
*
|
||||||
|
* @param locations must not be {@literal null}.
|
||||||
|
* @return Number of elements added.
|
||||||
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
|
*/
|
||||||
|
Long geoAdd(Iterable<GeoLocation<M>> locations);
|
||||||
|
|
||||||
List<GeoCoordinate> geoPos(K key, M... members);
|
/**
|
||||||
|
* Get the {@link Distance} between {@literal member1} and {@literal member2}.
|
||||||
|
*
|
||||||
|
* @param member1 must not be {@literal null}.
|
||||||
|
* @param member2 must not be {@literal null}.
|
||||||
|
* @return can be {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geodist">http://redis.io/commands/geodist</a>
|
||||||
|
*/
|
||||||
|
Distance geoDist(M member1, M member2);
|
||||||
|
|
||||||
List<GeoRadiusResponse> georadius(K key, double longitude, double latitude,
|
/**
|
||||||
double radius, GeoUnit unit);
|
* Get the {@link Distance} between {@literal member1} and {@literal member2} in the given {@link Metric}.
|
||||||
|
*
|
||||||
|
* @param member1 must not be {@literal null}.
|
||||||
|
* @param member2 must not be {@literal null}.
|
||||||
|
* @param metric must not be {@literal null}.
|
||||||
|
* @return can be {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geodist">http://redis.io/commands/geodist</a>
|
||||||
|
*/
|
||||||
|
Distance geoDist(M member1, M member2, Metric metric);
|
||||||
|
|
||||||
List<GeoRadiusResponse> georadius(K key, double longitude, double latitude,
|
/**
|
||||||
double radius, GeoUnit unit, GeoRadiusParam param);
|
* Get Geohash representation of the position for one or more {@literal member}s.
|
||||||
|
*
|
||||||
|
* @param members must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geohash">http://redis.io/commands/geohash</a>
|
||||||
|
*/
|
||||||
|
List<String> geoHash(M... members);
|
||||||
|
|
||||||
List<GeoRadiusResponse> georadiusByMember(K key, M member, double radius,
|
/**
|
||||||
GeoUnit unit);
|
* Get the {@link Point} representation of positions for one or more {@literal member}s.
|
||||||
|
*
|
||||||
|
* @param members must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geopos">http://redis.io/commands/geopos</a>
|
||||||
|
*/
|
||||||
|
List<Point> geoPos(M... members);
|
||||||
|
|
||||||
List<GeoRadiusResponse> georadiusByMember(K key, M member, double radius,
|
/**
|
||||||
GeoUnit unit, GeoRadiusParam param);
|
* Get the {@literal member}s within the boundaries of a given {@link Circle}.
|
||||||
|
*
|
||||||
|
* @param within must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadius">http://redis.io/commands/georadius</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadius(Circle within);
|
||||||
|
|
||||||
Long geoRemove(K key, M... members);
|
/**
|
||||||
|
* Get the {@literal member}s within the boundaries of a given {@link Circle} applying {@link GeoRadiusCommandArgs}.
|
||||||
|
*
|
||||||
|
* @param within must not be {@literal null}.
|
||||||
|
* @param args must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadius">http://redis.io/commands/georadius</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadius(Circle within, GeoRadiusCommandArgs args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@literal radius}.
|
||||||
|
*
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param radius
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadiusByMember(K key, M member, double radius);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@literal radius} applying {@link Metric}.
|
||||||
|
*
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param distance must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadiusByMember(M member, Distance distance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@literal radius} applying {@link Metric} and {@link GeoRadiusCommandArgs}.
|
||||||
|
*
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param distance must not be {@literal null}.
|
||||||
|
* @param args must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadiusByMember(M member, Distance distance, GeoRadiusCommandArgs args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the {@literal member}s.
|
||||||
|
*
|
||||||
|
* @param members must not be {@literal null}.
|
||||||
|
* @return Number of elements removed.
|
||||||
|
*/
|
||||||
|
Long geoRemove(M... members);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 the original author or authors.
|
* Copyright 2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,87 +15,174 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.core;
|
package org.springframework.data.redis.core;
|
||||||
|
|
||||||
import org.springframework.data.redis.connection.DataType;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
import org.springframework.data.redis.connection.DataType;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Default implementation of {@link BoundGeoOperations}.
|
||||||
|
*
|
||||||
* @author Ninad Divadkar
|
* @author Ninad Divadkar
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
class DefaultBoundGeoOperations<K, M> extends DefaultBoundKeyOperations<K> implements BoundGeoOperations<K, M> {
|
class DefaultBoundGeoOperations<K, M> extends DefaultBoundKeyOperations<K> implements BoundGeoOperations<K, M> {
|
||||||
|
|
||||||
private final GeoOperations<K, M> ops;
|
private final GeoOperations<K, M> ops;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new <code>DefaultBoundGeoOperations</code> instance.
|
* Constructs a new {@code DefaultBoundGeoOperations}.
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key must not be {@literal null}.
|
||||||
* @param operations
|
* @param operations must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public DefaultBoundGeoOperations(K key, RedisOperations<K, M> operations) {
|
public DefaultBoundGeoOperations(K key, RedisOperations<K, M> operations) {
|
||||||
|
|
||||||
super(key, operations);
|
super(key, operations);
|
||||||
this.ops = operations.opsForGeo();
|
this.ops = operations.opsForGeo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Long geoAdd(K key, double longitude, double latitude, M member) {
|
* (non-Javadoc)
|
||||||
return ops.geoAdd(key, longitude, latitude, member);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoAdd(org.springframework.data.geo.Point, java.lang.Object)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(Point point, M member) {
|
||||||
|
return ops.geoAdd(getKey(), point, member);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Long geoAdd(K key, Map<M, GeoCoordinate> memberCoordinateMap) {
|
* (non-Javadoc)
|
||||||
return ops.geoAdd(key, memberCoordinateMap);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoAdd(org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(GeoLocation<M> location) {
|
||||||
|
return ops.geoAdd(getKey(), location);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Double geoDist(K key, M member1, M member2) {
|
* (non-Javadoc)
|
||||||
return ops.geoDist(key, member1, member2);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoAdd(java.util.Map)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(Map<M, Point> memberCoordinateMap) {
|
||||||
|
return ops.geoAdd(getKey(), memberCoordinateMap);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Double geoDist(K key, M member1, M member2, GeoUnit unit) {
|
* (non-Javadoc)
|
||||||
return ops.geoDist(key, member1, member2, unit);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoAdd(java.lang.Iterable)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(Iterable<GeoLocation<M>> locations) {
|
||||||
|
return ops.geoAdd(getKey(), locations);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<byte[]> geoHash(K key, M... members) {
|
* (non-Javadoc)
|
||||||
return ops.geoHash(key, members);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoDist(java.lang.Object, java.lang.Object)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(M member1, M member2) {
|
||||||
|
return ops.geoDist(getKey(), member1, member2);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<GeoCoordinate> geoPos(K key, M... members) {
|
* (non-Javadoc)
|
||||||
return ops.geoPos(key, members);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoDist(java.lang.Object, java.lang.Object, org.springframework.data.geo.Metric)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(M member1, M member2, Metric unit) {
|
||||||
|
return ops.geoDist(getKey(), member1, member2, unit);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<GeoRadiusResponse> georadius(K key, double longitude, double latitude, double radius, GeoUnit unit) {
|
* (non-Javadoc)
|
||||||
return ops.georadius(key, longitude, latitude, radius, unit);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoHash(java.lang.Object[])
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> geoHash(M... members) {
|
||||||
|
return ops.geoHash(getKey(), members);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<GeoRadiusResponse> georadius(K key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
|
* (non-Javadoc)
|
||||||
return ops.georadius(key, longitude, latitude, radius, unit, param);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoPos(java.lang.Object[])
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Point> geoPos(M... members) {
|
||||||
|
return ops.geoPos(getKey(), members);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<GeoRadiusResponse> georadiusByMember(K key, M member, double radius, GeoUnit unit) {
|
* (non-Javadoc)
|
||||||
return ops.georadiusByMember(key, member, radius, unit);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#georadius(org.springframework.data.geo.Circle)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadius(Circle within) {
|
||||||
|
return ops.georadius(getKey(), within);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<GeoRadiusResponse> georadiusByMember(K key, M member, double radius, GeoUnit unit, GeoRadiusParam param) {
|
* (non-Javadoc)
|
||||||
return ops.georadiusByMember(key, member, radius, unit, param);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#georadius(org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadius(Circle within, GeoRadiusCommandArgs param) {
|
||||||
|
return ops.georadius(getKey(), within, param);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Long geoRemove(K key, M... members) {
|
* (non-Javadoc)
|
||||||
return ops.geoRemove(key, members);
|
* @see org.springframework.data.redis.core.BoundGeoOperations#georadiusByMember(java.lang.Object, java.lang.Object, double)
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadiusByMember(K key, M member, double radius) {
|
||||||
|
return ops.georadiusByMember(getKey(), member, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.BoundGeoOperations#georadiusByMember(java.lang.Object, org.springframework.data.geo.Distance)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadiusByMember(M member, Distance distance) {
|
||||||
|
return ops.georadiusByMember(getKey(), member, distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.BoundGeoOperations#georadiusByMember(java.lang.Object, org.springframework.data.geo.Distance, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadiusByMember(M member, Distance distance, GeoRadiusCommandArgs param) {
|
||||||
|
return ops.georadiusByMember(getKey(), member, distance, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.BoundGeoOperations#geoRemove(java.lang.Object[])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoRemove(M... members) {
|
||||||
|
return ops.geoRemove(getKey(), members);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.BoundKeyOperations#getType()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DataType getType() {
|
||||||
|
return DataType.ZSET;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DataType getType() {
|
|
||||||
return DataType.STRING;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2014 the original author or authors.
|
* Copyright 2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,166 +15,289 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.core;
|
package org.springframework.data.redis.core;
|
||||||
|
|
||||||
import org.springframework.data.redis.connection.RedisConnection;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default implementation of {@link GeoOperations}.
|
* Default implementation of {@link GeoOperations}.
|
||||||
*
|
*
|
||||||
* @author Ninad Divadkar
|
* @author Ninad Divadkar
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public class DefaultGeoOperations<K, M> extends AbstractOperations<K, M> implements GeoOperations<K, M> {
|
public class DefaultGeoOperations<K, M> extends AbstractOperations<K, M> implements GeoOperations<K, M> {
|
||||||
DefaultGeoOperations(RedisTemplate<K, M> template) {
|
|
||||||
super(template);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public Long geoAdd(K key, final double longitude, final double latitude, M member) {
|
* Creates new {@link DefaultGeoOperations}.
|
||||||
final byte[] rawKey = rawKey(key);
|
*
|
||||||
final byte[] rawMember = rawValue(member);
|
* @param template must not be {@literal null}.
|
||||||
|
*/
|
||||||
|
DefaultGeoOperations(RedisTemplate<K, M> template) {
|
||||||
|
super(template);
|
||||||
|
}
|
||||||
|
|
||||||
return execute(new RedisCallback<Long>() {
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.GeoOperations#geoAdd(java.lang.Object, org.springframework.data.geo.Point, java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoAdd(K key, final Point point, M member) {
|
||||||
|
|
||||||
public Long doInRedis(RedisConnection connection) {
|
final byte[] rawKey = rawKey(key);
|
||||||
return connection.geoAdd(rawKey, longitude, latitude, rawMember);
|
final byte[] rawMember = rawValue(member);
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return execute(new RedisCallback<Long>() {
|
||||||
public Long geoAdd(K key, Map<M, GeoCoordinate> memberCoordinateMap) {
|
|
||||||
final byte[] rawKey = rawKey(key);
|
|
||||||
final Map<byte[], GeoCoordinate> rawMemberCoordinateMap = new HashMap<byte[], GeoCoordinate>();
|
|
||||||
for(M member : memberCoordinateMap.keySet()){
|
|
||||||
final byte[] rawMember = rawValue(member);
|
|
||||||
rawMemberCoordinateMap.put(rawMember, memberCoordinateMap.get(member));
|
|
||||||
}
|
|
||||||
|
|
||||||
return execute(new RedisCallback<Long>() {
|
public Long doInRedis(RedisConnection connection) {
|
||||||
|
return connection.geoAdd(rawKey, point, rawMember);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
public Long doInRedis(RedisConnection connection) {
|
/*
|
||||||
return connection.geoAdd(rawKey, rawMemberCoordinateMap);
|
* (non-Javadoc)
|
||||||
}
|
* @see org.springframework.data.redis.core.GeoOperations#geoAdd(java.lang.Object, org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation)
|
||||||
}, true);
|
*/
|
||||||
}
|
@Override
|
||||||
|
public Long geoAdd(K key, GeoLocation<M> location) {
|
||||||
|
return geoAdd(key, location.getPoint(), location.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public Double geoDist(K key, final M member1, final M member2) {
|
* (non-Javadoc)
|
||||||
final byte[] rawKey = rawKey(key);
|
* @see org.springframework.data.redis.core.GeoOperations#geoAdd(java.lang.Object, java.util.Map)
|
||||||
final byte[] rawMember1 = rawValue(member1);
|
*/
|
||||||
final byte[] rawMember2 = rawValue(member2);
|
@Override
|
||||||
|
public Long geoAdd(K key, Map<M, Point> memberCoordinateMap) {
|
||||||
|
|
||||||
return execute(new RedisCallback<Double>() {
|
final byte[] rawKey = rawKey(key);
|
||||||
|
final Map<byte[], Point> rawMemberCoordinateMap = new HashMap<byte[], Point>();
|
||||||
|
|
||||||
public Double doInRedis(RedisConnection connection) {
|
for (M member : memberCoordinateMap.keySet()) {
|
||||||
return connection.geoDist(rawKey, rawMember1, rawMember2);
|
final byte[] rawMember = rawValue(member);
|
||||||
}
|
rawMemberCoordinateMap.put(rawMember, memberCoordinateMap.get(member));
|
||||||
}, true);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return execute(new RedisCallback<Long>() {
|
||||||
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<Double>() {
|
public Long doInRedis(RedisConnection connection) {
|
||||||
|
return connection.geoAdd(rawKey, rawMemberCoordinateMap);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
public Double doInRedis(RedisConnection connection) {
|
/*
|
||||||
return connection.geoDist(rawKey, rawMember1, rawMember2, unit);
|
* (non-Javadoc)
|
||||||
}
|
* @see org.springframework.data.redis.core.GeoOperations#geoAdd(java.lang.Object, java.lang.Iterable)
|
||||||
}, true);
|
*/
|
||||||
}
|
@Override
|
||||||
|
public Long geoAdd(K key, Iterable<GeoLocation<M>> locations) {
|
||||||
|
|
||||||
@Override
|
Map<M, Point> memberCoordinateMap = new LinkedHashMap<M, Point>();
|
||||||
public List<byte[]> geoHash(K key, final M... members) {
|
for (GeoLocation<M> location : locations) {
|
||||||
final byte[] rawKey = rawKey(key);
|
memberCoordinateMap.put(location.getName(), location.getPoint());
|
||||||
final byte[][] rawMembers = rawValues(members);
|
}
|
||||||
|
|
||||||
return execute(new RedisCallback<List<byte[]>>() {
|
return geoAdd(key, memberCoordinateMap);
|
||||||
|
}
|
||||||
|
|
||||||
public List<byte[]> doInRedis(RedisConnection connection) {
|
/*
|
||||||
return connection.geoHash(rawKey, rawMembers);
|
* (non-Javadoc)
|
||||||
}
|
* @see org.springframework.data.redis.core.GeoOperations#geoDist(java.lang.Object, java.lang.Object, java.lang.Object)
|
||||||
}, true);
|
*/
|
||||||
}
|
@Override
|
||||||
|
public Distance geoDist(K key, final M member1, final M member2) {
|
||||||
|
|
||||||
@Override
|
final byte[] rawKey = rawKey(key);
|
||||||
public List<GeoCoordinate> geoPos(K key, M... members) {
|
final byte[] rawMember1 = rawValue(member1);
|
||||||
final byte[] rawKey = rawKey(key);
|
final byte[] rawMember2 = rawValue(member2);
|
||||||
final byte[][] rawMembers = rawValues(members);
|
|
||||||
|
|
||||||
return execute(new RedisCallback<List<GeoCoordinate>>() {
|
return execute(new RedisCallback<Distance>() {
|
||||||
|
|
||||||
public List<GeoCoordinate> doInRedis(RedisConnection connection) {
|
public Distance doInRedis(RedisConnection connection) {
|
||||||
return connection.geoPos(rawKey, rawMembers);
|
return connection.geoDist(rawKey, rawMember1, rawMember2);
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public List<GeoRadiusResponse> georadius(K key, final double longitude, final double latitude, final double radius, final GeoUnit unit) {
|
* (non-Javadoc)
|
||||||
final byte[] rawKey = rawKey(key);
|
* @see org.springframework.data.redis.core.GeoOperations#geoDist(java.lang.Object, java.lang.Object, java.lang.Object, org.springframework.data.geo.Metric)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(K key, M member1, M member2, final Metric metric) {
|
||||||
|
|
||||||
return execute(new RedisCallback<List<GeoRadiusResponse>>() {
|
final byte[] rawKey = rawKey(key);
|
||||||
|
final byte[] rawMember1 = rawValue(member1);
|
||||||
|
final byte[] rawMember2 = rawValue(member2);
|
||||||
|
|
||||||
public List<GeoRadiusResponse> doInRedis(RedisConnection connection) {
|
return execute(new RedisCallback<Distance>() {
|
||||||
return connection.georadius(rawKey, longitude, latitude, radius, unit);
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public Distance doInRedis(RedisConnection connection) {
|
||||||
public List<GeoRadiusResponse> georadius(K key, final double longitude, final double latitude, final double radius, final GeoUnit unit, final GeoRadiusParam param) {
|
return connection.geoDist(rawKey, rawMember1, rawMember2, metric);
|
||||||
final byte[] rawKey = rawKey(key);
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
return execute(new RedisCallback<List<GeoRadiusResponse>>() {
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.GeoOperations#geoHash(java.lang.Object, java.lang.Object[])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> geoHash(K key, final M... members) {
|
||||||
|
|
||||||
public List<GeoRadiusResponse> doInRedis(RedisConnection connection) {
|
final byte[] rawKey = rawKey(key);
|
||||||
return connection.georadius(rawKey, longitude, latitude, radius, unit, param);
|
final byte[][] rawMembers = rawValues(members);
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return execute(new RedisCallback<List<String>>() {
|
||||||
public List<GeoRadiusResponse> 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<List<GeoRadiusResponse>>() {
|
public List<String> doInRedis(RedisConnection connection) {
|
||||||
|
return connection.geoHash(rawKey, rawMembers);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
public List<GeoRadiusResponse> doInRedis(RedisConnection connection) {
|
/*
|
||||||
return connection.georadiusByMember(rawKey, rawMember, radius, unit);
|
* (non-Javadoc)
|
||||||
}
|
* @see org.springframework.data.redis.core.GeoOperations#geoPos(java.lang.Object, java.lang.Object[])
|
||||||
}, true);
|
*/
|
||||||
}
|
@Override
|
||||||
|
public List<Point> geoPos(K key, M... members) {
|
||||||
|
final byte[] rawKey = rawKey(key);
|
||||||
|
final byte[][] rawMembers = rawValues(members);
|
||||||
|
|
||||||
@Override
|
return execute(new RedisCallback<List<Point>>() {
|
||||||
public List<GeoRadiusResponse> 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<List<GeoRadiusResponse>>() {
|
public List<Point> doInRedis(RedisConnection connection) {
|
||||||
|
return connection.geoPos(rawKey, rawMembers);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
public List<GeoRadiusResponse> doInRedis(RedisConnection connection) {
|
/*
|
||||||
return connection.georadiusByMember(rawKey, rawMember, radius, unit, param);
|
* (non-Javadoc)
|
||||||
}
|
* @see org.springframework.data.redis.core.GeoOperations#georadius(java.lang.Object, org.springframework.data.geo.Circle)
|
||||||
}, true);
|
*/
|
||||||
}
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadius(K key, final Circle within) {
|
||||||
|
|
||||||
@Override
|
final byte[] rawKey = rawKey(key);
|
||||||
public Long geoRemove(K key, M... members) {
|
|
||||||
final byte[] rawKey = rawKey(key);
|
|
||||||
final byte[][] rawMembers = rawValues(members);
|
|
||||||
|
|
||||||
return execute(new RedisCallback<Long>() {
|
GeoResults<GeoLocation<byte[]>> raw = execute(new RedisCallback<GeoResults<GeoLocation<byte[]>>>() {
|
||||||
|
|
||||||
public Long doInRedis(RedisConnection connection) {
|
public GeoResults<GeoLocation<byte[]>> doInRedis(RedisConnection connection) {
|
||||||
return connection.zRem(rawKey, rawMembers);
|
return connection.geoRadius(rawKey, within);
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
}
|
|
||||||
|
return deserializeGeoResults(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.GeoOperations#georadius(java.lang.Object, org.springframework.data.geo.Circle, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadius(K key, final Circle within, final GeoRadiusCommandArgs args) {
|
||||||
|
|
||||||
|
final byte[] rawKey = rawKey(key);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> raw = execute(new RedisCallback<GeoResults<GeoLocation<byte[]>>>() {
|
||||||
|
|
||||||
|
public GeoResults<GeoLocation<byte[]>> doInRedis(RedisConnection connection) {
|
||||||
|
return connection.geoRadius(rawKey, within, args);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
return deserializeGeoResults(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.GeoOperations#georadiusByMember(java.lang.Object, java.lang.Object, double)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadiusByMember(K key, M member, final double radius) {
|
||||||
|
|
||||||
|
final byte[] rawKey = rawKey(key);
|
||||||
|
final byte[] rawMember = rawValue(member);
|
||||||
|
GeoResults<GeoLocation<byte[]>> raw = execute(new RedisCallback<GeoResults<GeoLocation<byte[]>>>() {
|
||||||
|
|
||||||
|
public GeoResults<GeoLocation<byte[]>> doInRedis(RedisConnection connection) {
|
||||||
|
return connection.geoRadiusByMember(rawKey, rawMember, radius);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
return deserializeGeoResults(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.GeoOperations#georadiusByMember(java.lang.Object, java.lang.Object, org.springframework.data.geo.Distance)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadiusByMember(K key, M member, final Distance distance) {
|
||||||
|
|
||||||
|
final byte[] rawKey = rawKey(key);
|
||||||
|
final byte[] rawMember = rawValue(member);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> raw = execute(new RedisCallback<GeoResults<GeoLocation<byte[]>>>() {
|
||||||
|
|
||||||
|
public GeoResults<GeoLocation<byte[]>> doInRedis(RedisConnection connection) {
|
||||||
|
return connection.geoRadiusByMember(rawKey, rawMember, distance);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
return deserializeGeoResults(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.GeoOperations#georadiusByMember(java.lang.Object, java.lang.Object, double, org.springframework.data.geo.Metric, org.springframework.data.redis.core.GeoRadiusCommandArgs)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<M>> georadiusByMember(K key, M member, final Distance distance,
|
||||||
|
final GeoRadiusCommandArgs param) {
|
||||||
|
|
||||||
|
final byte[] rawKey = rawKey(key);
|
||||||
|
final byte[] rawMember = rawValue(member);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> raw = execute(new RedisCallback<GeoResults<GeoLocation<byte[]>>>() {
|
||||||
|
|
||||||
|
public GeoResults<GeoLocation<byte[]>> doInRedis(RedisConnection connection) {
|
||||||
|
return connection.geoRadiusByMember(rawKey, rawMember, distance, param);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
return deserializeGeoResults(raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.GeoOperations#geoRemove(java.lang.Object, java.lang.Object[])
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Long geoRemove(K key, M... members) {
|
||||||
|
|
||||||
|
final byte[] rawKey = rawKey(key);
|
||||||
|
final byte[][] rawMembers = rawValues(members);
|
||||||
|
|
||||||
|
return execute(new RedisCallback<Long>() {
|
||||||
|
|
||||||
|
public Long doInRedis(RedisConnection connection) {
|
||||||
|
return connection.zRem(rawKey, rawMembers);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2014 the original author or authors.
|
* Copyright 2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,35 +18,172 @@ package org.springframework.data.redis.core;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis operations for geo commands.
|
* Redis operations for geo commands.
|
||||||
*
|
*
|
||||||
* @author Ninad Divadkar
|
* @author Ninad Divadkar
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @see <a href="http://redis.io/commands#geo">http://redis.io/commands#geo</a>
|
||||||
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public interface GeoOperations<K, M> {
|
public interface GeoOperations<K, M> {
|
||||||
Long geoAdd(K key, double longitude, double latitude, M member);
|
|
||||||
|
|
||||||
Long geoAdd(K key, Map<M, GeoCoordinate> memberCoordinateMap);
|
/**
|
||||||
|
* Add {@link Point} with given member {@literal name} to {@literal key}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param point must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @return Number of elements added.
|
||||||
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
|
*/
|
||||||
|
Long geoAdd(K key, Point point, M member);
|
||||||
|
|
||||||
Double geoDist(K key, M member1, M member2);
|
/**
|
||||||
|
* Add {@link GeoLocation} to {@literal key}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param location must not be {@literal null}.
|
||||||
|
* @return Number of elements added.
|
||||||
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
|
*/
|
||||||
|
Long geoAdd(K key, GeoLocation<M> location);
|
||||||
|
|
||||||
Double geoDist(K key, M member1, M member2, GeoUnit unit);
|
/**
|
||||||
|
* Add {@link Map} of member / {@link Point} pairs to {@literal key}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param memberCoordinateMap must not be {@literal null}.
|
||||||
|
* @return Number of elements added.
|
||||||
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
|
*/
|
||||||
|
Long geoAdd(K key, Map<M, Point> memberCoordinateMap);
|
||||||
|
|
||||||
List<byte[]> geoHash(K key, M... members);
|
/**
|
||||||
|
* Add {@link GeoLocation}s to {@literal key}
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param locations must not be {@literal null}.
|
||||||
|
* @return Number of elements added.
|
||||||
|
* @see <a href="http://redis.io/commands/geoadd">http://redis.io/commands/geoadd</a>
|
||||||
|
*/
|
||||||
|
Long geoAdd(K key, Iterable<GeoLocation<M>> locations);
|
||||||
|
|
||||||
List<GeoCoordinate> geoPos(K key, M... members);
|
/**
|
||||||
|
* Get the {@link Distance} between {@literal member1} and {@literal member2}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member1 must not be {@literal null}.
|
||||||
|
* @param member2 must not be {@literal null}.
|
||||||
|
* @return can be {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geodist">http://redis.io/commands/geodist</a>
|
||||||
|
*/
|
||||||
|
Distance geoDist(K key, M member1, M member2);
|
||||||
|
|
||||||
List<GeoRadiusResponse> georadius(K key, double longitude, double latitude,
|
/**
|
||||||
double radius, GeoUnit unit);
|
* Get the {@link Distance} between {@literal member1} and {@literal member2} in the given {@link Metric}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member1 must not be {@literal null}.
|
||||||
|
* @param member2 must not be {@literal null}.
|
||||||
|
* @param metric must not be {@literal null}.
|
||||||
|
* @return can be {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geodist">http://redis.io/commands/geodist</a>
|
||||||
|
*/
|
||||||
|
Distance geoDist(K key, M member1, M member2, Metric metric);
|
||||||
|
|
||||||
List<GeoRadiusResponse> georadius(K key, double longitude, double latitude,
|
/**
|
||||||
double radius, GeoUnit unit, GeoRadiusParam param);
|
* Get Geohash representation of the position for one or more {@literal member}s.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param members must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geohash">http://redis.io/commands/geohash</a>
|
||||||
|
*/
|
||||||
|
List<String> geoHash(K key, M... members);
|
||||||
|
|
||||||
List<GeoRadiusResponse> georadiusByMember(K key, M member, double radius,
|
/**
|
||||||
GeoUnit unit);
|
* Get the {@link Point} representation of positions for one or more {@literal member}s.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param members must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/geopos">http://redis.io/commands/geopos</a>
|
||||||
|
*/
|
||||||
|
List<Point> geoPos(K key, M... members);
|
||||||
|
|
||||||
List<GeoRadiusResponse> georadiusByMember(K key, M member, double radius,
|
/**
|
||||||
GeoUnit unit, GeoRadiusParam param);
|
* Get the {@literal member}s within the boundaries of a given {@link Circle}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param within must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadius">http://redis.io/commands/georadius</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadius(K key, Circle within);
|
||||||
|
|
||||||
Long geoRemove(K key, M... members);
|
/**
|
||||||
|
* Get the {@literal member}s within the boundaries of a given {@link Circle} applying {@link GeoRadiusCommandArgs}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param within must not be {@literal null}.
|
||||||
|
* @param args must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadius">http://redis.io/commands/georadius</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadius(K key, Circle within, GeoRadiusCommandArgs args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@literal radius}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param radius
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadiusByMember(K key, M member, double radius);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@literal radius} applying {@link Metric}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param distance must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadiusByMember(K key, M member, Distance distance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@literal member}s within the circle defined by the {@literal members} coordinates and given
|
||||||
|
* {@literal radius} applying {@link Metric} and {@link GeoRadiusCommandArgs}.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param member must not be {@literal null}.
|
||||||
|
* @param distance must not be {@literal null}.
|
||||||
|
* @param args must not be {@literal null}.
|
||||||
|
* @return never {@literal null}.
|
||||||
|
* @see <a href="http://redis.io/commands/georadiusbymember">http://redis.io/commands/georadiusbymember</a>
|
||||||
|
*/
|
||||||
|
GeoResults<GeoLocation<M>> georadiusByMember(K key, M member, Distance distance, GeoRadiusCommandArgs args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the {@literal member}s.
|
||||||
|
*
|
||||||
|
* @param key must not be {@literal null}.
|
||||||
|
* @param members must not be {@literal null}.
|
||||||
|
* @return Number of elements removed.
|
||||||
|
*/
|
||||||
|
Long geoRemove(K key, M... members);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2013 the original author or authors.
|
* Copyright 2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,13 +18,16 @@ package org.springframework.data.redis.core;
|
|||||||
import java.beans.PropertyEditorSupport;
|
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}.
|
* PropertyEditor allowing for easy injection of {@link org.springframework.data.redis.core.GeoOperations} from
|
||||||
|
* {@link org.springframework.data.redis.core.RedisOperations}.
|
||||||
*
|
*
|
||||||
* @author Ninad Divadkar
|
* @author Ninad Divadkar
|
||||||
|
* @author Christoph Strobl
|
||||||
*/
|
*/
|
||||||
class GeoOperationsEditor extends PropertyEditorSupport {
|
class GeoOperationsEditor extends PropertyEditorSupport {
|
||||||
|
|
||||||
public void setValue(Object value) {
|
public void setValue(Object value) {
|
||||||
|
|
||||||
if (value instanceof RedisOperations) {
|
if (value instanceof RedisOperations) {
|
||||||
super.setValue(((RedisOperations) value).opsForGeo());
|
super.setValue(((RedisOperations) value).opsForGeo());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
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<String, Object> 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<String, Object>();
|
|
||||||
}
|
|
||||||
params.put(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addParam(String name) {
|
|
||||||
if (params == null) {
|
|
||||||
params = new HashMap<String, Object>();
|
|
||||||
}
|
|
||||||
params.put(name, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package org.springframework.data.redis.core;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ndivadkar on 3/29/16.
|
|
||||||
*/
|
|
||||||
public enum GeoUnit {
|
|
||||||
Meters,
|
|
||||||
KiloMeters,
|
|
||||||
Miles,
|
|
||||||
Feet;
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -28,6 +28,7 @@ import org.springframework.util.StringUtils;
|
|||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
|
* @author Ninad Divadkar
|
||||||
* @since 1.3
|
* @since 1.3
|
||||||
* @see Redis command list:
|
* @see Redis command list:
|
||||||
* https://github.com/antirez/redis/blob/93e7a130fc9594e41ccfc996b5eca7626ae5356a/src/redis.c#L119
|
* https://github.com/antirez/redis/blob/93e7a130fc9594e41ccfc996b5eca7626ae5356a/src/redis.c#L119
|
||||||
@@ -78,7 +79,12 @@ public enum RedisCommand {
|
|||||||
GETBIT("r", 2, 2), //
|
GETBIT("r", 2, 2), //
|
||||||
GETRANGE("r", 3, 3), //
|
GETRANGE("r", 3, 3), //
|
||||||
GETSET("rw", 2, 2), //
|
GETSET("rw", 2, 2), //
|
||||||
GEOADD("w", 3, 2),
|
GEOADD("w", 3), //
|
||||||
|
GEODIST("r", 2), //
|
||||||
|
GEOHASH("r", 2), //
|
||||||
|
GEOPOS("r", 2), //
|
||||||
|
GEORADIUS("r", 4), //
|
||||||
|
GEORADIUSBYMEMBER("r", 3),
|
||||||
// -- H
|
// -- H
|
||||||
HDEL("rw", 2), //
|
HDEL("rw", 2), //
|
||||||
HEXISTS("r", 2, 2), //
|
HEXISTS("r", 2, 2), //
|
||||||
@@ -332,13 +338,13 @@ public enum RedisCommand {
|
|||||||
if (requiresArguments()) {
|
if (requiresArguments()) {
|
||||||
if (requiresExactNumberOfArguments()) {
|
if (requiresExactNumberOfArguments()) {
|
||||||
if (nrArguments != maxArgs) {
|
if (nrArguments != maxArgs) {
|
||||||
throw new IllegalArgumentException(String.format("%s command requires %s arguments.", this.name(),
|
throw new IllegalArgumentException(
|
||||||
this.maxArgs));
|
String.format("%s command requires %s arguments.", this.name(), this.maxArgs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nrArguments < minArgs) {
|
if (nrArguments < minArgs) {
|
||||||
throw new IllegalArgumentException(String.format("%s command requires at least %s arguments.", this.name(),
|
throw new IllegalArgumentException(
|
||||||
this.minArgs));
|
String.format("%s command requires at least %s arguments.", this.name(), this.minArgs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2015 the original author or authors.
|
* Copyright 2011-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -33,6 +33,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
|||||||
*
|
*
|
||||||
* @author Costin Leau
|
* @author Costin Leau
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
public interface RedisOperations<K, V> {
|
public interface RedisOperations<K, V> {
|
||||||
|
|
||||||
@@ -283,20 +284,22 @@ public interface RedisOperations<K, V> {
|
|||||||
*/
|
*/
|
||||||
<HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key);
|
<HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the operations performed on geo values.
|
* Returns geospatial specific operations interface.
|
||||||
*
|
*
|
||||||
* @return geo operations
|
* @return never {@literal null}.
|
||||||
*/
|
* @since 1.8
|
||||||
GeoOperations<K, V> opsForGeo();
|
*/
|
||||||
|
GeoOperations<K, V> opsForGeo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the operations performed on values bound to the given key.
|
* Returns geospatial specific operations interface bound to the given key.
|
||||||
*
|
*
|
||||||
* @param key Redis key
|
* @param key must not be {@literal null}.
|
||||||
* @return geo operations bound to the given key.
|
* @return never {@literal null}.
|
||||||
*/
|
* @since 1.8
|
||||||
BoundGeoOperations<K, V> boundGeoOps(K key);
|
*/
|
||||||
|
BoundGeoOperations<K, V> boundGeoOps(K key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cluster specific operations interface.
|
* Returns the cluster specific operations interface.
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
*
|
*
|
||||||
* @author Costin Leau
|
* @author Costin Leau
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Ninad Divadkar
|
||||||
* @param <K> the Redis key type against which the template works (usually a String)
|
* @param <K> the Redis key type against which the template works (usually a String)
|
||||||
* @param <V> the Redis value type against which the template works
|
* @param <V> the Redis value type against which the template works
|
||||||
* @see StringRedisTemplate
|
* @see StringRedisTemplate
|
||||||
@@ -98,7 +99,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
|||||||
private ListOperations<K, V> listOps;
|
private ListOperations<K, V> listOps;
|
||||||
private SetOperations<K, V> setOps;
|
private SetOperations<K, V> setOps;
|
||||||
private ZSetOperations<K, V> zSetOps;
|
private ZSetOperations<K, V> zSetOps;
|
||||||
private GeoOperations<K, V> geoOps;
|
private GeoOperations<K, V> geoOps;
|
||||||
private HyperLogLogOperations<K, V> hllOps;
|
private HyperLogLogOperations<K, V> hllOps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1007,23 +1008,32 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
|||||||
return zSetOps;
|
return zSetOps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public GeoOperations<K, V> opsForGeo() {
|
* (non-Javadoc)
|
||||||
if (geoOps == null) {
|
* @see org.springframework.data.redis.core.RedisOperations#opsForGeo()
|
||||||
geoOps = new DefaultGeoOperations<K, V>(this);
|
*/
|
||||||
}
|
@Override
|
||||||
return geoOps;
|
public GeoOperations<K, V> opsForGeo() {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (geoOps == null) {
|
||||||
public BoundGeoOperations<K, V> boundGeoOps(K key) {
|
geoOps = new DefaultGeoOperations<K, V>(this);
|
||||||
return new DefaultBoundGeoOperations<K, V>(key, this);
|
}
|
||||||
}
|
return geoOps;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see org.springframework.data.redis.core.RedisOperations#opsForHyperLogLog()
|
* @see org.springframework.data.redis.core.RedisOperations#boundGeoOps(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
|
public BoundGeoOperations<K, V> boundGeoOps(K key) {
|
||||||
|
return new DefaultBoundGeoOperations<K, V>(key, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.redis.core.RedisOperations#opsForHyperLogLog()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HyperLogLogOperations<K, V> opsForHyperLogLog() {
|
public HyperLogLogOperations<K, V> opsForHyperLogLog() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011-2015 the original author or authors.
|
* Copyright 2011-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -39,6 +39,7 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
|
|||||||
private static final String REDIS_26 = "2.6";
|
private static final String REDIS_26 = "2.6";
|
||||||
private static final String REDIS_28 = "2.8";
|
private static final String REDIS_28 = "2.8";
|
||||||
private static final String REDIS_30 = "3.0";
|
private static final String REDIS_30 = "3.0";
|
||||||
|
private static final String REDIS_32 = "3.2";
|
||||||
private static final String REDIS_VERSION_KEY = "redisVersion";
|
private static final String REDIS_VERSION_KEY = "redisVersion";
|
||||||
|
|
||||||
private static RedisTestProfileValueSource INSTANCE;
|
private static RedisTestProfileValueSource INSTANCE;
|
||||||
@@ -95,6 +96,10 @@ public class RedisTestProfileValueSource implements ProfileValueSource {
|
|||||||
return System.getProperty(key);
|
return System.getProperty(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_32)) >= 0) {
|
||||||
|
return REDIS_32;
|
||||||
|
}
|
||||||
|
|
||||||
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_30)) >= 0) {
|
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_30)) >= 0) {
|
||||||
return REDIS_30;
|
return REDIS_30;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,14 @@
|
|||||||
package org.springframework.data.redis.connection;
|
package org.springframework.data.redis.connection;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.hamcrest.collection.IsCollectionWithSize.*;
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
import static org.hamcrest.number.IsCloseTo.*;
|
import static org.hamcrest.number.IsCloseTo.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assume.*;
|
import static org.junit.Assume.*;
|
||||||
import static org.springframework.data.redis.SpinBarrier.*;
|
import static org.springframework.data.redis.SpinBarrier.*;
|
||||||
|
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
|
||||||
|
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
|
||||||
import static org.springframework.data.redis.core.ScanOptions.*;
|
import static org.springframework.data.redis.core.ScanOptions.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -48,10 +52,16 @@ import org.junit.Test;
|
|||||||
import org.junit.internal.AssumptionViolatedException;
|
import org.junit.internal.AssumptionViolatedException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metrics;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.RedisSystemException;
|
import org.springframework.data.redis.RedisSystemException;
|
||||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||||
import org.springframework.data.redis.RedisVersionUtils;
|
import org.springframework.data.redis.RedisVersionUtils;
|
||||||
import org.springframework.data.redis.TestCondition;
|
import org.springframework.data.redis.TestCondition;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||||
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
||||||
@@ -86,6 +96,14 @@ import org.springframework.test.annotation.ProfileValueSourceConfiguration;
|
|||||||
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
|
@ProfileValueSourceConfiguration(RedisTestProfileValueSource.class)
|
||||||
public abstract class AbstractConnectionIntegrationTests {
|
public abstract class AbstractConnectionIntegrationTests {
|
||||||
|
|
||||||
|
private static final Point POINT_ARIGENTO = new Point(13.583333, 37.316667);
|
||||||
|
private static final Point POINT_CATANIA = new Point(15.087269, 37.502669);
|
||||||
|
private static final Point POINT_PALERMO = new Point(13.361389, 38.115556);
|
||||||
|
|
||||||
|
private static final GeoLocation<String> ARIGENTO = new GeoLocation<String>("arigento", POINT_ARIGENTO);
|
||||||
|
private static final GeoLocation<String> CATANIA = new GeoLocation<String>("catania", POINT_CATANIA);
|
||||||
|
private static final GeoLocation<String> PALERMO = new GeoLocation<String>("palermo", POINT_PALERMO);
|
||||||
|
|
||||||
protected StringRedisConnection connection;
|
protected StringRedisConnection connection;
|
||||||
protected RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
|
protected RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
|
||||||
protected RedisSerializer<String> stringSerializer = new StringRedisSerializer();
|
protected RedisSerializer<String> stringSerializer = new StringRedisSerializer();
|
||||||
@@ -1219,7 +1237,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.rPush("PopList", "world"));
|
actual.add(connection.rPush("PopList", "world"));
|
||||||
connection.lSet("PopList", 1, "cruel");
|
connection.lSet("PopList", 1, "cruel");
|
||||||
actual.add(connection.lRange("PopList", 0, -1));
|
actual.add(connection.lRange("PopList", 0, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "cruel", "world" }) }));
|
verifyResults(
|
||||||
|
Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "cruel", "world" }) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1318,8 +1337,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("myset", "foo"));
|
actual.add(connection.sAdd("myset", "foo"));
|
||||||
actual.add(connection.sAdd("myset", "bar"));
|
actual.add(connection.sAdd("myset", "bar"));
|
||||||
actual.add(connection.sMembers("myset"));
|
actual.add(connection.sMembers("myset"));
|
||||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l,
|
verifyResults(
|
||||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })) }));
|
Arrays.asList(new Object[] { 1l, 1l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1327,8 +1346,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("myset", "foo", "bar"));
|
actual.add(connection.sAdd("myset", "foo", "bar"));
|
||||||
actual.add(connection.sAdd("myset", "baz"));
|
actual.add(connection.sAdd("myset", "baz"));
|
||||||
actual.add(connection.sMembers("myset"));
|
actual.add(connection.sMembers("myset"));
|
||||||
verifyResults(Arrays.asList(new Object[] { 2l, 1l,
|
verifyResults(Arrays
|
||||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
|
.asList(new Object[] { 2l, 1l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1355,7 +1374,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("otherset", "bar"));
|
actual.add(connection.sAdd("otherset", "bar"));
|
||||||
actual.add(connection.sDiffStore("thirdset", "myset", "otherset"));
|
actual.add(connection.sDiffStore("thirdset", "myset", "otherset"));
|
||||||
actual.add(connection.sMembers("thirdset"));
|
actual.add(connection.sMembers("thirdset"));
|
||||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("foo")) }));
|
verifyResults(
|
||||||
|
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("foo")) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1374,7 +1394,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("otherset", "bar"));
|
actual.add(connection.sAdd("otherset", "bar"));
|
||||||
actual.add(connection.sInterStore("thirdset", "myset", "otherset"));
|
actual.add(connection.sInterStore("thirdset", "myset", "otherset"));
|
||||||
actual.add(connection.sMembers("thirdset"));
|
actual.add(connection.sMembers("thirdset"));
|
||||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("bar")) }));
|
verifyResults(
|
||||||
|
Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Collections.singletonList("bar")) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1400,7 +1421,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("myset", "foo"));
|
actual.add(connection.sAdd("myset", "foo"));
|
||||||
actual.add(connection.sAdd("myset", "bar"));
|
actual.add(connection.sAdd("myset", "bar"));
|
||||||
actual.add(connection.sPop("myset"));
|
actual.add(connection.sPop("myset"));
|
||||||
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
|
assertTrue(
|
||||||
|
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1408,7 +1430,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("myset", "foo"));
|
actual.add(connection.sAdd("myset", "foo"));
|
||||||
actual.add(connection.sAdd("myset", "bar"));
|
actual.add(connection.sAdd("myset", "bar"));
|
||||||
actual.add(connection.sRandMember("myset"));
|
actual.add(connection.sRandMember("myset"));
|
||||||
assertTrue(new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
|
assertTrue(
|
||||||
|
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1452,7 +1475,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sRem("myset", "foo"));
|
actual.add(connection.sRem("myset", "foo"));
|
||||||
actual.add(connection.sRem("myset", "baz"));
|
actual.add(connection.sRem("myset", "baz"));
|
||||||
actual.add(connection.sMembers("myset"));
|
actual.add(connection.sMembers("myset"));
|
||||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l, new HashSet<String>(Collections.singletonList("bar")) }));
|
verifyResults(
|
||||||
|
Arrays.asList(new Object[] { 1l, 1l, 1l, 0l, new HashSet<String>(Collections.singletonList("bar")) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1462,7 +1486,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("myset", "baz"));
|
actual.add(connection.sAdd("myset", "baz"));
|
||||||
actual.add(connection.sRem("myset", "foo", "nope", "baz"));
|
actual.add(connection.sRem("myset", "foo", "nope", "baz"));
|
||||||
actual.add(connection.sMembers("myset"));
|
actual.add(connection.sMembers("myset"));
|
||||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 2l, new HashSet<String>(Collections.singletonList("bar")) }));
|
verifyResults(
|
||||||
|
Arrays.asList(new Object[] { 1l, 1l, 1l, 2l, new HashSet<String>(Collections.singletonList("bar")) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1472,8 +1497,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("otherset", "bar"));
|
actual.add(connection.sAdd("otherset", "bar"));
|
||||||
actual.add(connection.sAdd("otherset", "baz"));
|
actual.add(connection.sAdd("otherset", "baz"));
|
||||||
actual.add(connection.sUnion("myset", "otherset"));
|
actual.add(connection.sUnion("myset", "otherset"));
|
||||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l,
|
verifyResults(Arrays.asList(
|
||||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
|
new Object[] { 1l, 1l, 1l, 1l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1484,8 +1509,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.sAdd("otherset", "baz"));
|
actual.add(connection.sAdd("otherset", "baz"));
|
||||||
actual.add(connection.sUnionStore("thirdset", "myset", "otherset"));
|
actual.add(connection.sUnionStore("thirdset", "myset", "otherset"));
|
||||||
actual.add(connection.sMembers("thirdset"));
|
actual.add(connection.sMembers("thirdset"));
|
||||||
verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, 3l,
|
verifyResults(Arrays.asList(
|
||||||
new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
|
new Object[] { 1l, 1l, 1l, 1l, 3l, new HashSet<String>(Arrays.asList(new String[] { "foo", "bar", "baz" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZSet
|
// ZSet
|
||||||
@@ -1495,8 +1520,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRange("myset", 0, -1));
|
actual.add(connection.zRange("myset", 0, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true,
|
verifyResults(Arrays.asList(
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "James", "Bob" })) }));
|
new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "James", "Bob" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1509,8 +1534,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", strTuples));
|
actual.add(connection.zAdd("myset", strTuples));
|
||||||
actual.add(connection.zAdd("myset".getBytes(), tuples));
|
actual.add(connection.zAdd("myset".getBytes(), tuples));
|
||||||
actual.add(connection.zRange("myset", 0, -1));
|
actual.add(connection.zRange("myset", 0, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] { 2l, 1l,
|
verifyResults(Arrays.asList(
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "James", "Bob", "Joe" })) }));
|
new Object[] { 2l, 1l, new LinkedHashSet<String>(Arrays.asList(new String[] { "James", "Bob", "Joe" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1537,8 +1562,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 4, "Joe"));
|
actual.add(connection.zAdd("myset", 4, "Joe"));
|
||||||
actual.add(connection.zIncrBy("myset", 2, "Joe"));
|
actual.add(connection.zIncrBy("myset", 2, "Joe"));
|
||||||
actual.add(connection.zRangeByScore("myset", 6, 6));
|
actual.add(connection.zRangeByScore("myset", 6, 6));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true, true, 6d,
|
verifyResults(Arrays
|
||||||
new LinkedHashSet<String>(Collections.singletonList("Joe")) }));
|
.asList(new Object[] { true, true, true, 6d, new LinkedHashSet<String>(Collections.singletonList("Joe")) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1564,16 +1589,10 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset"));
|
actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset"));
|
||||||
|
|
||||||
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
|
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] {
|
verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 2l,
|
||||||
true,
|
new LinkedHashSet<StringTuple>(
|
||||||
true,
|
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
|
||||||
true,
|
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
|
||||||
true,
|
|
||||||
true,
|
|
||||||
2l,
|
|
||||||
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
|
|
||||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d),
|
|
||||||
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1581,12 +1600,10 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRangeWithScores("myset", 0, -1));
|
actual.add(connection.zRangeWithScores("myset", 0, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] {
|
verifyResults(Arrays.asList(new Object[] { true, true,
|
||||||
true,
|
new LinkedHashSet<StringTuple>(
|
||||||
true,
|
Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), "James", 1d),
|
||||||
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
|
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
|
||||||
new DefaultStringTuple("James".getBytes(), "James", 1d),
|
|
||||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1594,8 +1611,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRangeByScore("myset", 1, 1));
|
actual.add(connection.zRangeByScore("myset", 1, 1));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true,
|
verifyResults(
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "James" })) }));
|
Arrays.asList(new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "James" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1603,8 +1620,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRangeByScore("myset", 1d, 3d, 1, -1));
|
actual.add(connection.zRangeByScore("myset", 1d, 3d, 1, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true,
|
verifyResults(
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
|
Arrays.asList(new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1612,11 +1629,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRangeByScoreWithScores("myset", 2d, 5d));
|
actual.add(connection.zRangeByScoreWithScores("myset", 2d, 5d));
|
||||||
verifyResults(Arrays.asList(new Object[] {
|
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
|
||||||
true,
|
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
|
||||||
true,
|
|
||||||
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(),
|
|
||||||
"Bob", 2d) })) }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1624,11 +1638,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRangeByScoreWithScores("myset", 1d, 5d, 0, 1));
|
actual.add(connection.zRangeByScoreWithScores("myset", 1d, 5d, 0, 1));
|
||||||
verifyResults(Arrays.asList(new Object[] {
|
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
|
||||||
true,
|
Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
|
||||||
true,
|
|
||||||
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(),
|
|
||||||
"James", 1d) })) }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1636,8 +1647,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRevRange("myset", 0, -1));
|
actual.add(connection.zRevRange("myset", 0, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true,
|
verifyResults(Arrays.asList(
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
|
new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1645,12 +1656,10 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 2, "Bob"));
|
actual.add(connection.zAdd("myset", 2, "Bob"));
|
||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRevRangeWithScores("myset", 0, -1));
|
actual.add(connection.zRevRangeWithScores("myset", 0, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] {
|
verifyResults(Arrays.asList(new Object[] { true, true,
|
||||||
true,
|
new LinkedHashSet<StringTuple>(
|
||||||
true,
|
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
|
||||||
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
|
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
|
||||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
|
|
||||||
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1658,8 +1667,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
|
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
|
||||||
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
|
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
|
||||||
actual.add(connection.zRevRangeByScore("myset", 0d, 3d, 0, 5));
|
actual.add(connection.zRevRangeByScore("myset", 0d, 3d, 0, 5));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true,
|
verifyResults(Arrays.asList(
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
|
new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1667,8 +1676,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
|
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
|
||||||
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
|
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
|
||||||
actual.add(connection.zRevRangeByScore("myset", 0d, 3d));
|
actual.add(connection.zRevRangeByScore("myset", 0d, 3d));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true,
|
verifyResults(Arrays.asList(
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
|
new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob", "James" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1676,11 +1685,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
|
actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes()));
|
||||||
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
|
actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes()));
|
||||||
actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 3d, 0, 1));
|
actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 3d, 0, 1));
|
||||||
verifyResults(Arrays.asList(new Object[] {
|
verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<StringTuple>(
|
||||||
true,
|
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) }));
|
||||||
true,
|
|
||||||
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(),
|
|
||||||
"Bob", 2d) })) }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1689,13 +1695,10 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zAdd("myset", 3, "Joe"));
|
actual.add(connection.zAdd("myset", 3, "Joe"));
|
||||||
actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 2d));
|
actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 2d));
|
||||||
verifyResults(Arrays.asList(new Object[] {
|
verifyResults(Arrays.asList(new Object[] { true, true, true,
|
||||||
true,
|
new LinkedHashSet<StringTuple>(
|
||||||
true,
|
Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
|
||||||
true,
|
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
|
||||||
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
|
|
||||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 2d),
|
|
||||||
new DefaultStringTuple("James".getBytes(), "James", 1d) })) }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1713,8 +1716,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRem("myset", "James"));
|
actual.add(connection.zRem("myset", "James"));
|
||||||
actual.add(connection.zRange("myset", 0l, -1l));
|
actual.add(connection.zRange("myset", 0l, -1l));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true, 1l,
|
verifyResults(Arrays
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
|
.asList(new Object[] { true, true, 1l, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1744,8 +1747,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("myset", 1, "James"));
|
actual.add(connection.zAdd("myset", 1, "James"));
|
||||||
actual.add(connection.zRemRangeByScore("myset", 0d, 1d));
|
actual.add(connection.zRemRangeByScore("myset", 0d, 1d));
|
||||||
actual.add(connection.zRange("myset", 0l, -1l));
|
actual.add(connection.zRange("myset", 0l, -1l));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true, 1l,
|
verifyResults(Arrays
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
|
.asList(new Object[] { true, true, 1l, new LinkedHashSet<String>(Arrays.asList(new String[] { "Bob" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1788,13 +1791,7 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.zAdd("otherset", 4, "James"));
|
actual.add(connection.zAdd("otherset", 4, "James"));
|
||||||
actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset"));
|
actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset"));
|
||||||
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
|
actual.add(connection.zRangeWithScores("thirdset", 0, -1));
|
||||||
verifyResults(Arrays.asList(new Object[] {
|
verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 3l,
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
3l,
|
|
||||||
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
|
new LinkedHashSet<StringTuple>(Arrays.asList(new StringTuple[] {
|
||||||
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), new DefaultStringTuple("Joe".getBytes(), "Joe", 8d),
|
new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), new DefaultStringTuple("Joe".getBytes(), "Joe", 8d),
|
||||||
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
|
new DefaultStringTuple("James".getBytes(), "James", 12d) })) }));
|
||||||
@@ -1868,8 +1865,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
actual.add(connection.hSet("test", "key", "2"));
|
actual.add(connection.hSet("test", "key", "2"));
|
||||||
actual.add(connection.hSet("test", "key2", "2"));
|
actual.add(connection.hSet("test", "key2", "2"));
|
||||||
actual.add(connection.hKeys("test"));
|
actual.add(connection.hKeys("test"));
|
||||||
verifyResults(Arrays.asList(new Object[] { true, true,
|
verifyResults(Arrays
|
||||||
new LinkedHashSet<String>(Arrays.asList(new String[] { "key", "key2" })) }));
|
.asList(new Object[] { true, true, new LinkedHashSet<String>(Arrays.asList(new String[] { "key", "key2" })) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -2098,8 +2095,8 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
connection.hSet("hscankey", "foo-2", "v-2");
|
connection.hSet("hscankey", "foo-2", "v-2");
|
||||||
connection.hSet("hscankey", "foo-3", "v-3");
|
connection.hSet("hscankey", "foo-3", "v-3");
|
||||||
|
|
||||||
Cursor<Map.Entry<String, String>> cursor = connection
|
Cursor<Map.Entry<String, String>> cursor = connection.hScan("hscankey",
|
||||||
.hScan("hscankey", scanOptions().count(2).match("fo*").build());
|
scanOptions().count(2).match("fo*").build());
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@@ -2509,6 +2506,269 @@ public abstract class AbstractConnectionIntegrationTests {
|
|||||||
assertThat(((Long) result.get(1)).doubleValue(), is(closeTo(-2, 0)));
|
assertThat(((Long) result.get(1)).doubleValue(), is(closeTo(-2, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoAddSingleGeoLocation() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, PALERMO));
|
||||||
|
|
||||||
|
List<Object> result = getResults();
|
||||||
|
assertThat((Long) result.get(0), is(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoAddMultipleGeoLocations() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, ARIGENTO, CATANIA, PALERMO)));
|
||||||
|
|
||||||
|
List<Object> result = getResults();
|
||||||
|
assertThat((Long) result.get(0), is(3L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoDist() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
|
||||||
|
actual.add(connection.geoDist(key, PALERMO.getName(), CATANIA.getName()));
|
||||||
|
|
||||||
|
List<Object> result = getResults();
|
||||||
|
assertThat(((Distance) result.get(1)).getValue(), is(closeTo(166274.15156960033D, 0.005)));
|
||||||
|
assertThat(((Distance) result.get(1)).getUnit(), is("m"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoDistWithMetric() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
|
||||||
|
actual.add(connection.geoDist(key, PALERMO.getName(), CATANIA.getName(), Metrics.KILOMETERS));
|
||||||
|
|
||||||
|
List<Object> result = getResults();
|
||||||
|
assertThat(((Distance) result.get(1)).getValue(), is(closeTo(166.27415156960033D, 0.005)));
|
||||||
|
assertThat(((Distance) result.get(1)).getUnit(), is("km"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS })
|
||||||
|
public void geoHash() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
|
||||||
|
actual.add(connection.geoHash(key, PALERMO.getName(), CATANIA.getName()));
|
||||||
|
|
||||||
|
List<Object> result = getResults();
|
||||||
|
assertThat(((List<String>) result.get(1)).get(0), is("sqc8b49rny0"));
|
||||||
|
assertThat(((List<String>) result.get(1)).get(1), is("sqdtr74hyu0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS })
|
||||||
|
public void geoHashNonExisting() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
|
||||||
|
actual.add(connection.geoHash(key, PALERMO.getName(), ARIGENTO.getName(), CATANIA.getName()));
|
||||||
|
|
||||||
|
List<Object> result = getResults();
|
||||||
|
assertThat(((List<String>) result.get(1)).get(0), is("sqc8b49rny0"));
|
||||||
|
assertThat(((List<String>) result.get(1)).get(1), is(nullValue()));
|
||||||
|
assertThat(((List<String>) result.get(1)).get(2), is("sqdtr74hyu0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoPosition() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
|
||||||
|
|
||||||
|
actual.add(connection.geoPos(key, PALERMO.getName(), CATANIA.getName()));
|
||||||
|
|
||||||
|
List<Object> result = getResults();
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoPositionNonExisting() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA)));
|
||||||
|
|
||||||
|
actual.add(connection.geoPos(key, PALERMO.getName(), ARIGENTO.getName(), CATANIA.getName()));
|
||||||
|
|
||||||
|
List<Object> result = getResults();
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(1), is(nullValue()));
|
||||||
|
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(2).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(((List<Point>) result.get(1)).get(2).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoRadiusShouldReturnMembersCorrectly() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
|
||||||
|
|
||||||
|
actual.add(connection.georadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS))));
|
||||||
|
actual.add(connection.georadius(key, new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS))));
|
||||||
|
|
||||||
|
List<Object> results = getResults();
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(3));
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(2)).getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoRadiusShouldReturnDistanceCorrectly() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
|
||||||
|
|
||||||
|
actual.add(connection.georadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)),
|
||||||
|
newGeoRadiusArgs().includeDistance()));
|
||||||
|
|
||||||
|
List<Object> results = getResults();
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(3));
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getDistance().getValue(),
|
||||||
|
is(closeTo(130.423D, 0.005)));
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getDistance().getUnit(),
|
||||||
|
is("km"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoRadiusShouldApplyLimit() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
|
||||||
|
|
||||||
|
actual.add(connection.georadius(key, new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)),
|
||||||
|
newGeoRadiusArgs().limit(2)));
|
||||||
|
|
||||||
|
List<Object> results = getResults();
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
|
||||||
|
|
||||||
|
actual.add(connection.georadiusByMember(key, PALERMO.getName(), new Distance(100, KILOMETERS),
|
||||||
|
newGeoRadiusArgs().sortAscending()));
|
||||||
|
|
||||||
|
List<Object> results = getResults();
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getContent().getName(),
|
||||||
|
is(PALERMO.getName()));
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(1).getContent().getName(),
|
||||||
|
is(ARIGENTO.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
|
||||||
|
|
||||||
|
actual.add(connection.georadiusByMember(key, PALERMO.getName(), new Distance(100, KILOMETERS),
|
||||||
|
newGeoRadiusArgs().includeDistance()));
|
||||||
|
|
||||||
|
List<Object> results = getResults();
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(2));
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getDistance().getValue(),
|
||||||
|
is(closeTo(90.978D, 0.005)));
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent().get(0).getDistance().getUnit(),
|
||||||
|
is("km"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE })
|
||||||
|
public void geoRadiusByMemberShouldApplyLimit() {
|
||||||
|
|
||||||
|
String key = "geo-" + UUID.randomUUID();
|
||||||
|
actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO)));
|
||||||
|
|
||||||
|
actual.add(connection.georadiusByMember(key, PALERMO.getName(), new Distance(200, KILOMETERS),
|
||||||
|
newGeoRadiusArgs().limit(2)));
|
||||||
|
|
||||||
|
List<Object> results = getResults();
|
||||||
|
assertThat(((GeoResults<GeoLocation<String>>) results.get(1)).getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
protected void verifyResults(List<Object> expected) {
|
protected void verifyResults(List<Object> expected) {
|
||||||
assertEquals(expected, getResults());
|
assertEquals(expected, getResults());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.connection;
|
package org.springframework.data.redis.connection;
|
||||||
|
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
*/
|
*/
|
||||||
public interface ClusterConnectionTests {
|
public interface ClusterConnectionTests {
|
||||||
|
|
||||||
|
static final Point POINT_ARIGENTO = new Point(13.583333, 37.316667);
|
||||||
|
static final Point POINT_CATANIA = new Point(15.087269, 37.502669);
|
||||||
|
static final Point POINT_PALERMO = new Point(13.361389, 38.115556);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DATAREDIS-315
|
* @see DATAREDIS-315
|
||||||
*/
|
*/
|
||||||
@@ -946,4 +952,78 @@ public interface ClusterConnectionTests {
|
|||||||
*/
|
*/
|
||||||
void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists();
|
void setWithExpirationAndIfPresentShouldNotBeAppliedWhenKeyDoesNotExists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoAddSingleGeoLocation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoAddMultipleGeoLocations();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoDist();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoDistWithMetric();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoHash();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoHashNonExisting();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoPosition();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoPositionNonExisting();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoRadiusShouldReturnMembersCorrectly();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoRadiusShouldReturnDistanceCorrectly();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoRadiusShouldApplyLimit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoRadiusByMemberShouldReturnMembersCorrectly();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoRadiusByMemberShouldReturnDistanceCorrectly();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoRadiusByMemberShouldApplyLimit();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
void geoRemoveDeletesMembers();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,16 +17,22 @@ package org.springframework.data.redis.connection;
|
|||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test of {@link DefaultStringRedisConnection} that executes commands in a pipeline
|
* Unit test of {@link DefaultStringRedisConnection} that executes commands in a pipeline
|
||||||
*
|
*
|
||||||
* @author Jennifer Hickey
|
* @author Jennifer Hickey
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedisConnectionTests {
|
public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedisConnectionTests {
|
||||||
|
|
||||||
@@ -1287,155 +1293,282 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testZUnionStoreAggWeights() {
|
public void testZUnionStoreAggWeights() {
|
||||||
doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Collections.singletonList(5l)).when(nativeConnection).closePipeline();
|
||||||
super.testZUnionStoreAggWeights();
|
super.testZUnionStoreAggWeights();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testZUnionStoreBytes() {
|
public void testZUnionStoreBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline();
|
||||||
super.testZUnionStoreBytes();
|
super.testZUnionStoreBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testZUnionStore() {
|
public void testZUnionStore() {
|
||||||
doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline();
|
||||||
super.testZUnionStore();
|
super.testZUnionStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoAddBytes(){
|
public void testGeoAddBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoAddBytes();
|
super.testGeoAddBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoAdd(){
|
public void testGeoAdd() {
|
||||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoAddBytes();
|
super.testGeoAddBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void testGeoAddWithGeoLocationBytes() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddWithGeoLocationBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void testGeoAddWithGeoLocation() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddWithGeoLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoAddCoordinateMapBytes(){
|
public void testGeoAddCoordinateMapBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoAddCoordinateMapBytes();
|
super.testGeoAddCoordinateMapBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoAddCoordinateMap(){
|
public void testGeoAddCoordinateMap() {
|
||||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoAddCoordinateMap();
|
super.testGeoAddCoordinateMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void testGeoAddWithIterableOfGeoLocationBytes() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddWithIterableOfGeoLocationBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void testGeoAddWithIterableOfGeoLocation() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddWithIterableOfGeoLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoDistBytes(){
|
public void testGeoDistBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).closePipeline();
|
||||||
super.testGeoDistBytes();
|
super.testGeoDistBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoDist(){
|
public void testGeoDist() {
|
||||||
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).closePipeline();
|
doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).closePipeline();
|
||||||
super.testGeoDist();
|
super.testGeoDist();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoHashBytes(){
|
public void testGeoHashBytes() {
|
||||||
List<byte[]> expected = new ArrayList<byte[]>();
|
|
||||||
expected.add(barBytes);
|
doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).closePipeline();
|
||||||
doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoHashBytes();
|
super.testGeoHashBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoHash(){
|
public void testGeoHash() {
|
||||||
List<byte[]> expected = new ArrayList<byte[]>();
|
|
||||||
expected.add(barBytes);
|
doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).closePipeline();
|
||||||
doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoHash();
|
super.testGeoHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoPosBytes(){
|
public void testGeoPosBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(points)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoPosBytes();
|
super.testGeoPosBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoPos(){
|
public void testGeoPos() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoCoordinates })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(points)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoPos();
|
super.testGeoPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusWithoutParamBytes(){
|
public void testGeoRadiusWithoutParamBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusWithoutParamBytes();
|
super.testGeoRadiusWithoutParamBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusWithoutParam(){
|
public void testGeoRadiusWithoutParam() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusWithoutParam();
|
super.testGeoRadiusWithoutParam();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusWithDistBytes(){
|
public void testGeoRadiusWithDistBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusWithDistBytes();
|
super.testGeoRadiusWithDistBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusWithDist(){
|
public void testGeoRadiusWithDist() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusWithDist();
|
super.testGeoRadiusWithDist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusWithCoordAndDescBytes(){
|
public void testGeoRadiusWithCoordAndDescBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusWithCoordAndDescBytes();
|
super.testGeoRadiusWithCoordAndDescBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusWithCoordAndDesc(){
|
public void testGeoRadiusWithCoordAndDesc() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusWithCoordAndDesc();
|
super.testGeoRadiusWithCoordAndDesc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusByMemberWithoutParamBytes(){
|
public void testGeoRadiusByMemberWithoutParamBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusByMemberWithoutParamBytes();
|
super.testGeoRadiusByMemberWithoutParamBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusByMemberWithoutParam(){
|
public void testGeoRadiusByMemberWithoutParam() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusByMemberWithoutParam();
|
super.testGeoRadiusByMemberWithoutParam();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusByMemberWithDistAndAscBytes(){
|
public void testGeoRadiusByMemberWithDistAndAscBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusByMemberWithDistAndAscBytes();
|
super.testGeoRadiusByMemberWithDistAndAscBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusByMemberWithDistAndAsc(){
|
public void testGeoRadiusByMemberWithDistAndAsc() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusByMemberWithDistAndAsc();
|
super.testGeoRadiusByMemberWithDistAndAsc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusByMemberWithCoordAndCountBytes(){
|
public void testGeoRadiusByMemberWithCoordAndCountBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusByMemberWithCoordAndCountBytes();
|
super.testGeoRadiusByMemberWithCoordAndCountBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoRadiusByMemberWithCoordAndCount(){
|
public void testGeoRadiusByMemberWithCoordAndCount() {
|
||||||
doReturn(Arrays.asList(new Object[] { geoRadiusResponses })).when(nativeConnection).closePipeline();
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline();
|
||||||
super.testGeoRadiusByMemberWithCoordAndCount();
|
super.testGeoRadiusByMemberWithCoordAndCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2016 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;
|
package org.springframework.data.redis.connection;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jennifer Hickey
|
||||||
|
* @author Christoph Strobl
|
||||||
|
* @author Ninad Divadkar
|
||||||
|
*/
|
||||||
public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRedisConnectionTxTests {
|
public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRedisConnectionTxTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -1387,142 +1411,6 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
|
|||||||
super.testZUnionStore();
|
super.testZUnionStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoAddBytes(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoAddBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoAdd(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoAddBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoAddCoordinateMapBytes(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoAddCoordinateMapBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoAddCoordinateMap(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoAddCoordinateMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoDistBytes(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 102121.12d }) })).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoDistBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoDist(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 102121.12d }) })).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoDist();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoHashBytes(){
|
|
||||||
List<byte[]> expected = new ArrayList<byte[]>();
|
|
||||||
expected.add(barBytes);
|
|
||||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { expected }) })).when(nativeConnection).closePipeline();
|
|
||||||
super.testGeoHashBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoHash(){
|
|
||||||
List<byte[]> expected = new ArrayList<byte[]>();
|
|
||||||
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
|
@Test
|
||||||
public void testPExpireBytes() {
|
public void testPExpireBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection)
|
doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection)
|
||||||
@@ -1655,9 +1543,9 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTwoTxs() {
|
public void testTwoTxs() {
|
||||||
doReturn(
|
doReturn(Arrays
|
||||||
Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }), Arrays.asList(new Object[] { fooBytes }) }))
|
.asList(new Object[] { Arrays.asList(new Object[] { barBytes }), Arrays.asList(new Object[] { fooBytes }) }))
|
||||||
.when(nativeConnection).closePipeline();
|
.when(nativeConnection).closePipeline();
|
||||||
connection.get(foo);
|
connection.get(foo);
|
||||||
connection.exec();
|
connection.exec();
|
||||||
connection.get(bar);
|
connection.get(bar);
|
||||||
@@ -1668,6 +1556,268 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe
|
|||||||
results);
|
results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAdd() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddWithGeoLocationBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddWithGeoLocationBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddWithGeoLocation() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddWithGeoLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddCoordinateMapBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddCoordinateMapBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddCoordinateMap() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddCoordinateMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddWithIterableOfGeoLocationBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddWithIterableOfGeoLocationBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddWithIterableOfGeoLocation() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoAddWithIterableOfGeoLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoDistBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS)))).when(nativeConnection)
|
||||||
|
.closePipeline();
|
||||||
|
super.testGeoDistBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoDist() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS)))).when(nativeConnection)
|
||||||
|
.closePipeline();
|
||||||
|
super.testGeoDist();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoHashBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(Collections.singletonList(bar)))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoHashBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoHash() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(Collections.singletonList(bar)))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoPosBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(points))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoPosBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoPos() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(points))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithoutParamBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusWithoutParamBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithoutParam() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusWithoutParam();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithDistBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusWithDistBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithDist() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusWithDist();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithCoordAndDescBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusWithCoordAndDescBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithCoordAndDesc() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusWithCoordAndDesc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithoutParamBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusByMemberWithoutParamBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithoutParam() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusByMemberWithoutParam();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithDistAndAscBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusByMemberWithDistAndAscBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithDistAndAsc() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusByMemberWithDistAndAsc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithCoordAndCountBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusByMemberWithCoordAndCountBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithCoordAndCount() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline();
|
||||||
|
super.testGeoRadiusByMemberWithCoordAndCount();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected List<Object> getResults() {
|
protected List<Object> getResults() {
|
||||||
connection.exec();
|
connection.exec();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,16 +34,21 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResult;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs;
|
||||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||||
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
|
import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOption;
|
||||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||||
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||||
import org.springframework.data.redis.core.GeoCoordinate;
|
import org.springframework.data.redis.connection.convert.Converters;
|
||||||
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;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +56,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|||||||
*
|
*
|
||||||
* @author Jennifer Hickey
|
* @author Jennifer Hickey
|
||||||
* @auhtor Christoph Strobl
|
* @auhtor Christoph Strobl
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
public class DefaultStringRedisConnectionTests {
|
public class DefaultStringRedisConnectionTests {
|
||||||
|
|
||||||
@@ -66,13 +72,13 @@ public class DefaultStringRedisConnectionTests {
|
|||||||
|
|
||||||
protected String bar = "bar";
|
protected String bar = "bar";
|
||||||
|
|
||||||
protected String bar2 = "bar2";
|
protected String bar2 = "bar2";
|
||||||
|
|
||||||
protected byte[] fooBytes = serializer.serialize(foo);
|
protected byte[] fooBytes = serializer.serialize(foo);
|
||||||
|
|
||||||
protected byte[] barBytes = serializer.serialize(bar);
|
protected byte[] barBytes = serializer.serialize(bar);
|
||||||
|
|
||||||
protected byte[] bar2Bytes = serializer.serialize(bar2);
|
protected byte[] bar2Bytes = serializer.serialize(bar2);
|
||||||
|
|
||||||
protected List<byte[]> bytesList = Collections.singletonList(barBytes);
|
protected List<byte[]> bytesList = Collections.singletonList(barBytes);
|
||||||
|
|
||||||
@@ -91,11 +97,12 @@ public class DefaultStringRedisConnectionTests {
|
|||||||
protected Set<StringTuple> stringTupleSet = new HashSet<StringTuple>(
|
protected Set<StringTuple> stringTupleSet = new HashSet<StringTuple>(
|
||||||
Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar)));
|
Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar)));
|
||||||
|
|
||||||
protected GeoCoordinate geoCoordinate = new GeoCoordinate(213.00, 324.343);
|
protected Point point = new Point(213.00, 324.343);
|
||||||
protected List<GeoCoordinate> geoCoordinates = new ArrayList<GeoCoordinate>();
|
protected List<Point> points = new ArrayList<Point>();
|
||||||
|
|
||||||
protected GeoRadiusResponse geoRadiusResponse = new GeoRadiusResponse(barBytes);
|
protected List<GeoResult<GeoLocation<byte[]>>> geoResultList = Collections
|
||||||
protected List<GeoRadiusResponse> geoRadiusResponses = new ArrayList<GeoRadiusResponse>();
|
.singletonList(new GeoResult<GeoLocation<byte[]>>(new GeoLocation<byte[]>(barBytes, null), new Distance(0D)));
|
||||||
|
protected GeoResults<GeoLocation<byte[]>> geoResults = new GeoResults<GeoLocation<byte[]>>(geoResultList);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -103,8 +110,7 @@ public class DefaultStringRedisConnectionTests {
|
|||||||
this.connection = new DefaultStringRedisConnection(nativeConnection);
|
this.connection = new DefaultStringRedisConnection(nativeConnection);
|
||||||
bytesMap.put(fooBytes, barBytes);
|
bytesMap.put(fooBytes, barBytes);
|
||||||
stringMap.put(foo, bar);
|
stringMap.put(foo, bar);
|
||||||
geoCoordinates.add(geoCoordinate);
|
points.add(point);
|
||||||
geoRadiusResponses.add(geoRadiusResponse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1586,188 +1592,6 @@ public class DefaultStringRedisConnectionTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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<byte[], GeoCoordinate> memberGeoCoordinateMap = new HashMap<byte[], GeoCoordinate>();
|
|
||||||
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<String, GeoCoordinate> stringGeoCoordinateMap = new HashMap<String, GeoCoordinate>();
|
|
||||||
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<byte[]> expected = new ArrayList<byte[]>();
|
|
||||||
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<String> expected = new ArrayList<String>();
|
|
||||||
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() {
|
public void testPExpireBytes() {
|
||||||
doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l);
|
doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l);
|
||||||
actual.add(connection.pExpire(fooBytes, 34l));
|
actual.add(connection.pExpire(fooBytes, 34l));
|
||||||
@@ -1960,6 +1784,342 @@ public class DefaultStringRedisConnectionTests {
|
|||||||
verify(nativeConnection, times(1)).getClientName();
|
verify(nativeConnection, times(1)).getClientName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddBytes() {
|
||||||
|
|
||||||
|
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes);
|
||||||
|
|
||||||
|
actual.add(connection.geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes));
|
||||||
|
verifyResults(Collections.singletonList(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAdd() {
|
||||||
|
|
||||||
|
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes);
|
||||||
|
|
||||||
|
actual.add(connection.geoAdd(foo, new Point(1.23232, 34.2342434), bar));
|
||||||
|
verifyResults(Collections.singletonList(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddWithGeoLocationBytes() {
|
||||||
|
|
||||||
|
doReturn(1l).when(nativeConnection).geoAdd(fooBytes,
|
||||||
|
new GeoLocation<byte[]>(barBytes, new Point(1.23232, 34.2342434)));
|
||||||
|
|
||||||
|
actual.add(connection.geoAdd(fooBytes, new GeoLocation<byte[]>(barBytes, new Point(1.23232, 34.2342434))));
|
||||||
|
verifyResults(Collections.singletonList(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddWithGeoLocation() {
|
||||||
|
|
||||||
|
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes);
|
||||||
|
|
||||||
|
actual.add(connection.geoAdd(foo, new GeoLocation<String>(bar, new Point(1.23232, 34.2342434))));
|
||||||
|
verifyResults(Collections.singletonList(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddCoordinateMapBytes() {
|
||||||
|
|
||||||
|
Map<byte[], Point> memberGeoCoordinateMap = Collections.singletonMap(barBytes, new Point(1.23232, 34.2342434));
|
||||||
|
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, memberGeoCoordinateMap);
|
||||||
|
|
||||||
|
actual.add(connection.geoAdd(fooBytes, memberGeoCoordinateMap));
|
||||||
|
verifyResults(Collections.singletonList(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddCoordinateMap() {
|
||||||
|
|
||||||
|
doReturn(1l).when(nativeConnection).geoAdd(any(byte[].class), anyMapOf(byte[].class, Point.class));
|
||||||
|
|
||||||
|
actual.add(connection.geoAdd(foo, Collections.singletonMap(bar, new Point(1.23232, 34.2342434))));
|
||||||
|
verifyResults(Collections.singletonList(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddWithIterableOfGeoLocationBytes() {
|
||||||
|
|
||||||
|
List<GeoLocation<byte[]>> values = Collections.singletonList(new GeoLocation<byte[]>(barBytes, new Point(1, 2)));
|
||||||
|
doReturn(1l).when(nativeConnection).geoAdd(fooBytes, values);
|
||||||
|
|
||||||
|
actual.add(connection.geoAdd(fooBytes, values));
|
||||||
|
verifyResults(Collections.singletonList(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddWithIterableOfGeoLocation() {
|
||||||
|
|
||||||
|
doReturn(1l).when(nativeConnection).geoAdd(eq(fooBytes), anyMapOf(byte[].class, Point.class));
|
||||||
|
|
||||||
|
actual.add(connection.geoAdd(foo, Collections.singletonList(new GeoLocation<String>(bar, new Point(1, 2)))));
|
||||||
|
verifyResults(Collections.singletonList(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoDistBytes() {
|
||||||
|
|
||||||
|
doReturn(new Distance(102121.12d, DistanceUnit.METERS)).when(nativeConnection).geoDist(fooBytes, barBytes,
|
||||||
|
bar2Bytes, DistanceUnit.METERS);
|
||||||
|
|
||||||
|
actual.add(connection.geoDist(fooBytes, barBytes, bar2Bytes, DistanceUnit.METERS));
|
||||||
|
verifyResults(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoDist() {
|
||||||
|
|
||||||
|
doReturn(new Distance(102121.12d, DistanceUnit.METERS)).when(nativeConnection).geoDist(fooBytes, barBytes,
|
||||||
|
bar2Bytes, DistanceUnit.METERS);
|
||||||
|
|
||||||
|
actual.add(connection.geoDist(foo, bar, bar2, DistanceUnit.METERS));
|
||||||
|
verifyResults(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoHashBytes() {
|
||||||
|
|
||||||
|
doReturn(stringList).when(nativeConnection).geoHash(fooBytes, barBytes);
|
||||||
|
|
||||||
|
actual.add(connection.geoHash(fooBytes, barBytes));
|
||||||
|
verifyResults(Arrays.asList(Collections.singletonList(bar)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoHash() {
|
||||||
|
|
||||||
|
doReturn(stringList).when(nativeConnection).geoHash(fooBytes, barBytes);
|
||||||
|
|
||||||
|
actual.add(connection.geoHash(foo, bar));
|
||||||
|
verifyResults(Arrays.asList(Collections.singletonList(bar)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoPosBytes() {
|
||||||
|
|
||||||
|
doReturn(points).when(nativeConnection).geoPos(fooBytes, barBytes);
|
||||||
|
|
||||||
|
actual.add(connection.geoPos(fooBytes, barBytes));
|
||||||
|
verifyResults(Arrays.asList(points));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoPos() {
|
||||||
|
|
||||||
|
doReturn(points).when(nativeConnection).geoPos(fooBytes, barBytes);
|
||||||
|
actual.add(connection.geoPos(foo, bar));
|
||||||
|
verifyResults(Arrays.asList(points));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithoutParamBytes() {
|
||||||
|
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class));
|
||||||
|
|
||||||
|
actual.add(connection.geoRadius(fooBytes, null));
|
||||||
|
verifyResults(Arrays.asList(geoResults));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithoutParam() {
|
||||||
|
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class));
|
||||||
|
|
||||||
|
actual.add(
|
||||||
|
connection.georadius(foo, new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET))));
|
||||||
|
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithDistBytes() {
|
||||||
|
|
||||||
|
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance();
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class), eq(geoRadiusParam));
|
||||||
|
|
||||||
|
actual.add(connection.geoRadius(fooBytes,
|
||||||
|
new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam));
|
||||||
|
verifyResults(Arrays.asList(geoResults));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithDist() {
|
||||||
|
|
||||||
|
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance();
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class), eq(geoRadiusParam));
|
||||||
|
|
||||||
|
actual.add(connection.georadius(foo,
|
||||||
|
new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam));
|
||||||
|
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithCoordAndDescBytes() {
|
||||||
|
|
||||||
|
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeCoordinates().sortDescending();
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class), eq(geoRadiusParam));
|
||||||
|
|
||||||
|
actual.add(connection.geoRadius(fooBytes,
|
||||||
|
new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam));
|
||||||
|
verifyResults(Arrays.asList(geoResults));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithCoordAndDesc() {
|
||||||
|
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeCoordinates().sortDescending();
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any(Circle.class), eq(geoRadiusParam));
|
||||||
|
|
||||||
|
actual.add(connection.georadius(foo,
|
||||||
|
new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam));
|
||||||
|
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithoutParamBytes() {
|
||||||
|
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
|
||||||
|
new Distance(38.115556, DistanceUnit.FEET));
|
||||||
|
|
||||||
|
actual.add(connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET)));
|
||||||
|
verifyResults(Arrays.asList(geoResults));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithoutParam() {
|
||||||
|
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
|
||||||
|
new Distance(38.115556, DistanceUnit.FEET));
|
||||||
|
|
||||||
|
actual.add(connection.georadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET)));
|
||||||
|
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithDistAndAscBytes() {
|
||||||
|
|
||||||
|
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().sortAscending();
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
|
||||||
|
new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam);
|
||||||
|
|
||||||
|
actual.add(
|
||||||
|
connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam));
|
||||||
|
verifyResults(Arrays.asList(geoResults));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithDistAndAsc() {
|
||||||
|
|
||||||
|
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().sortAscending();
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
|
||||||
|
new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam);
|
||||||
|
|
||||||
|
actual.add(connection.georadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam));
|
||||||
|
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithCoordAndCountBytes() {
|
||||||
|
|
||||||
|
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().limit(23);
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
|
||||||
|
new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam);
|
||||||
|
|
||||||
|
actual.add(
|
||||||
|
connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam));
|
||||||
|
verifyResults(Arrays.asList(geoResults));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithCoordAndCount() {
|
||||||
|
|
||||||
|
GeoRadiusCommandArgs geoRadiusParam = GeoRadiusCommandArgs.newGeoRadiusArgs().includeDistance().limit(23);
|
||||||
|
doReturn(geoResults).when(nativeConnection).geoRadiusByMember(fooBytes, barBytes,
|
||||||
|
new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam);
|
||||||
|
|
||||||
|
actual.add(connection.georadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam));
|
||||||
|
verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults)));
|
||||||
|
}
|
||||||
|
|
||||||
protected List<Object> getResults() {
|
protected List<Object> getResults() {
|
||||||
return actual;
|
return actual;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,18 +17,20 @@ package org.springframework.data.redis.connection;
|
|||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.data.redis.core.GeoCoordinate;
|
import org.springframework.data.geo.Distance;
|
||||||
import org.springframework.data.redis.core.GeoRadiusParam;
|
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||||
import org.springframework.data.redis.core.GeoRadiusResponse;
|
|
||||||
import org.springframework.data.redis.core.GeoUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jennifer Hickey
|
* @author Jennifer Hickey
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConnectionTests {
|
public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConnectionTests {
|
||||||
|
|
||||||
@@ -1293,142 +1295,6 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
|
|||||||
super.testZUnionStore();
|
super.testZUnionStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoAddBytes(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
|
|
||||||
super.testGeoAddBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoAdd(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
|
|
||||||
super.testGeoAddBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoAddCoordinateMapBytes(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
|
|
||||||
super.testGeoAddCoordinateMapBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoAddCoordinateMap(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
|
|
||||||
super.testGeoAddCoordinateMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoDistBytes(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).exec();
|
|
||||||
super.testGeoDistBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoDist(){
|
|
||||||
doReturn(Arrays.asList(new Object[] { 102121.12d })).when(nativeConnection).exec();
|
|
||||||
super.testGeoDist();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoHashBytes(){
|
|
||||||
List<byte[]> expected = new ArrayList<byte[]>();
|
|
||||||
expected.add(barBytes);
|
|
||||||
doReturn(Arrays.asList(new Object[] { expected })).when(nativeConnection).exec();
|
|
||||||
super.testGeoHashBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGeoHash(){
|
|
||||||
List<byte[]> expected = new ArrayList<byte[]>();
|
|
||||||
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
|
@Test
|
||||||
public void testPExpireBytes() {
|
public void testPExpireBytes() {
|
||||||
doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec();
|
doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec();
|
||||||
@@ -1580,6 +1446,260 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
|
|||||||
super.testTimeIsDelegatedCorrectlyToNativeConnection();
|
super.testTimeIsDelegatedCorrectlyToNativeConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddBytes() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
|
||||||
|
super.testGeoAddBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAdd() {
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
|
||||||
|
super.testGeoAddBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void testGeoAddWithGeoLocationBytes() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
|
||||||
|
super.testGeoAddWithGeoLocationBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void testGeoAddWithGeoLocation() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
|
||||||
|
super.testGeoAddWithGeoLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddCoordinateMapBytes() {
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
|
||||||
|
super.testGeoAddCoordinateMapBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoAddCoordinateMap() {
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
|
||||||
|
super.testGeoAddCoordinateMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void testGeoAddWithIterableOfGeoLocationBytes() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
|
||||||
|
super.testGeoAddWithIterableOfGeoLocationBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void testGeoAddWithIterableOfGeoLocation() {
|
||||||
|
|
||||||
|
doReturn(Collections.singletonList(1L)).when(nativeConnection).exec();
|
||||||
|
super.testGeoAddWithIterableOfGeoLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoDistBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).exec();
|
||||||
|
super.testGeoDistBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoDist() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).exec();
|
||||||
|
super.testGeoDist();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoHashBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).exec();
|
||||||
|
super.testGeoHashBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoHash() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).exec();
|
||||||
|
super.testGeoHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoPosBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(points)).when(nativeConnection).exec();
|
||||||
|
super.testGeoPosBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoPos() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(points)).when(nativeConnection).exec();
|
||||||
|
super.testGeoPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithoutParamBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusWithoutParamBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithoutParam() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusWithoutParam();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithDistBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusWithDistBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithDist() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusWithDist();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithCoordAndDescBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusWithCoordAndDescBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusWithCoordAndDesc() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusWithCoordAndDesc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithoutParamBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusByMemberWithoutParamBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithoutParam() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusByMemberWithoutParam();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithDistAndAscBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusByMemberWithDistAndAscBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithDistAndAsc() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusByMemberWithDistAndAsc();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithCoordAndCountBytes() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusByMemberWithCoordAndCountBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRadiusByMemberWithCoordAndCount() {
|
||||||
|
|
||||||
|
doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec();
|
||||||
|
super.testGeoRadiusByMemberWithCoordAndCount();
|
||||||
|
}
|
||||||
|
|
||||||
protected List<Object> getResults() {
|
protected List<Object> getResults() {
|
||||||
return connection.exec();
|
return connection.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2015 the original author or authors.
|
* Copyright 2014-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,8 +27,14 @@ import java.util.Set;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Metric;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder;
|
import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder;
|
||||||
import org.springframework.data.redis.core.*;
|
import org.springframework.data.redis.core.Cursor;
|
||||||
|
import org.springframework.data.redis.core.ScanOptions;
|
||||||
import org.springframework.data.redis.core.types.Expiration;
|
import org.springframework.data.redis.core.types.Expiration;
|
||||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
@@ -37,6 +43,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
* @author David Liu
|
* @author David Liu
|
||||||
|
* @author Ninad Divadkar
|
||||||
*/
|
*/
|
||||||
public class RedisConnectionUnitTests {
|
public class RedisConnectionUnitTests {
|
||||||
|
|
||||||
@@ -259,53 +266,69 @@ public class RedisConnectionUnitTests {
|
|||||||
delegate.subscribe(listener, channels);
|
delegate.subscribe(listener, channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long geoAdd(byte[] key, double longitude, double latitude, byte[] member) {
|
public Long geoAdd(byte[] key, Point point, byte[] member) {
|
||||||
return delegate.geoAdd(key, longitude, latitude, member);
|
return delegate.geoAdd(key, point, member);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long geoAdd(byte[] key, Map<byte[], GeoCoordinate> 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<byte[]> geoHash(byte[] key, byte[]... members) {
|
|
||||||
return delegate.geoHash(key, members);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoCoordinate> geoPos(byte[] key, byte[]... members) {
|
|
||||||
return delegate.geoPos(key, members);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) {
|
|
||||||
return delegate.georadius(key, longitude, latitude, radius, unit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadius(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Long geoAdd(byte[] key, GeoLocation<byte[]> location) {
|
||||||
return delegate.georadius(key, longitude, latitude, radius, unit, param);
|
return delegate.geoAdd(key, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) {
|
public Long geoAdd(byte[] key, Map<byte[], Point> memberCoordinateMap) {
|
||||||
return delegate.georadiusByMember(key, member, radius, unit);
|
return delegate.geoAdd(key, memberCoordinateMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GeoRadiusResponse> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) {
|
public Long geoAdd(byte[] key, Iterable<GeoLocation<byte[]>> locations) {
|
||||||
return delegate.georadiusByMember(key, member, radius, unit, param);
|
return delegate.geoAdd(key, locations);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2) {
|
||||||
|
return delegate.geoDist(key, member1, member2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric unit) {
|
||||||
|
return delegate.geoDist(key, member1, member2, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> geoHash(byte[] key, byte[]... members) {
|
||||||
|
return delegate.geoHash(key, members);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Point> geoPos(byte[] key, byte[]... members) {
|
||||||
|
return delegate.geoPos(key, members);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within) {
|
||||||
|
return delegate.geoRadius(key, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadius(byte[] key, Circle within, GeoRadiusCommandArgs param) {
|
||||||
|
return delegate.geoRadius(key, null, param);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, double radius) {
|
||||||
|
return delegate.geoRadiusByMember(key, member, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius) {
|
||||||
|
return delegate.geoRadiusByMember(key, member, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeoResults<GeoLocation<byte[]>> geoRadiusByMember(byte[] key, byte[] member, Distance radius,
|
||||||
|
GeoRadiusCommandArgs param) {
|
||||||
|
return delegate.geoRadiusByMember(key, member, radius, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,13 +16,18 @@
|
|||||||
package org.springframework.data.redis.connection.jedis;
|
package org.springframework.data.redis.connection.jedis;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.hamcrest.collection.IsCollectionWithSize.*;
|
||||||
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
|
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
import static org.hamcrest.number.IsCloseTo.*;
|
import static org.hamcrest.number.IsCloseTo.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
||||||
|
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
|
||||||
|
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
|
||||||
import static org.springframework.data.redis.core.ScanOptions.*;
|
import static org.springframework.data.redis.core.ScanOptions.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -38,14 +43,20 @@ import java.util.Set;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.connection.ClusterConnectionTests;
|
import org.springframework.data.redis.connection.ClusterConnectionTests;
|
||||||
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
|
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
|
||||||
import org.springframework.data.redis.connection.DataType;
|
import org.springframework.data.redis.connection.DataType;
|
||||||
import org.springframework.data.redis.connection.DefaultSortParameters;
|
import org.springframework.data.redis.connection.DefaultSortParameters;
|
||||||
import org.springframework.data.redis.connection.DefaultTuple;
|
import org.springframework.data.redis.connection.DefaultTuple;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||||
import org.springframework.data.redis.connection.RedisNode;
|
import org.springframework.data.redis.connection.RedisNode;
|
||||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||||
@@ -55,7 +66,9 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
|||||||
import org.springframework.data.redis.core.Cursor;
|
import org.springframework.data.redis.core.Cursor;
|
||||||
import org.springframework.data.redis.core.ScanOptions;
|
import org.springframework.data.redis.core.ScanOptions;
|
||||||
import org.springframework.data.redis.core.types.Expiration;
|
import org.springframework.data.redis.core.types.Expiration;
|
||||||
|
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||||
|
import org.springframework.test.annotation.IfProfileValue;
|
||||||
|
|
||||||
import redis.clients.jedis.HostAndPort;
|
import redis.clients.jedis.HostAndPort;
|
||||||
import redis.clients.jedis.JedisCluster;
|
import redis.clients.jedis.JedisCluster;
|
||||||
@@ -82,6 +95,13 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
|||||||
static final byte[] VALUE_2_BYTES = JedisConverters.toBytes(VALUE_2);
|
static final byte[] VALUE_2_BYTES = JedisConverters.toBytes(VALUE_2);
|
||||||
static final byte[] VALUE_3_BYTES = JedisConverters.toBytes(VALUE_3);
|
static final byte[] VALUE_3_BYTES = JedisConverters.toBytes(VALUE_3);
|
||||||
|
|
||||||
|
static final GeoLocation<byte[]> ARIGENTO = new GeoLocation<byte[]>("arigento".getBytes(Charset.forName("UTF-8")),
|
||||||
|
POINT_ARIGENTO);
|
||||||
|
static final GeoLocation<byte[]> CATANIA = new GeoLocation<byte[]>("catania".getBytes(Charset.forName("UTF-8")),
|
||||||
|
POINT_CATANIA);
|
||||||
|
static final GeoLocation<byte[]> PALERMO = new GeoLocation<byte[]>("palermo".getBytes(Charset.forName("UTF-8")),
|
||||||
|
POINT_PALERMO);
|
||||||
|
|
||||||
JedisCluster nativeConnection;
|
JedisCluster nativeConnection;
|
||||||
JedisClusterConnection clusterConnection;
|
JedisClusterConnection clusterConnection;
|
||||||
|
|
||||||
@@ -90,6 +110,11 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
|||||||
*/
|
*/
|
||||||
public static @ClassRule RedisClusterRule clusterRule = new RedisClusterRule();
|
public static @ClassRule RedisClusterRule clusterRule = new RedisClusterRule();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for specific Redis Versions
|
||||||
|
*/
|
||||||
|
public @Rule MinimumRedisVersionRule version = new MinimumRedisVersionRule();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws IOException {
|
||||||
|
|
||||||
@@ -2454,4 +2479,245 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
|||||||
|
|
||||||
assertThat(nativeConnection.exists(KEY_1_BYTES), is(false));
|
assertThat(nativeConnection.exists(KEY_1_BYTES), is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoAddSingleGeoLocation() {
|
||||||
|
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO), is(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoAddMultipleGeoLocations() {
|
||||||
|
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, Arrays.asList(PALERMO, ARIGENTO, CATANIA, PALERMO)), is(3L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoDist() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
Distance distance = clusterConnection.geoDist(KEY_1_BYTES, PALERMO.getName(), CATANIA.getName());
|
||||||
|
assertThat(distance.getValue(), is(closeTo(166274.15156960033D, 0.005)));
|
||||||
|
assertThat(distance.getUnit(), is("m"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoDistWithMetric() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
Distance distance = clusterConnection.geoDist(KEY_1_BYTES, PALERMO.getName(), CATANIA.getName(), KILOMETERS);
|
||||||
|
assertThat(distance.getValue(), is(closeTo(166.27415156960033D, 0.005)));
|
||||||
|
assertThat(distance.getUnit(), is("km"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoHash() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO.getName(), CATANIA.getName());
|
||||||
|
assertThat(result, contains("sqc8b49rny0", "sqdtr74hyu0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoHashNonExisting() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO.getName(), ARIGENTO.getName(),
|
||||||
|
CATANIA.getName());
|
||||||
|
assertThat(result, contains("sqc8b49rny0", (String) null, "sqdtr74hyu0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoPosition() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
List<Point> positions = clusterConnection.geoPos(KEY_1_BYTES, PALERMO.getName(), CATANIA.getName());
|
||||||
|
|
||||||
|
assertThat(positions.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(positions.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
|
||||||
|
assertThat(positions.get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(positions.get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoPositionNonExisting() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
List<Point> positions = clusterConnection.geoPos(KEY_1_BYTES, PALERMO.getName(), ARIGENTO.getName(),
|
||||||
|
CATANIA.getName());
|
||||||
|
|
||||||
|
assertThat(positions.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(positions.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
|
||||||
|
assertThat(positions.get(1), is(nullValue()));
|
||||||
|
|
||||||
|
assertThat(positions.get(2).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(positions.get(2).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusShouldReturnMembersCorrectly() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
|
||||||
|
new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS)));
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusShouldReturnDistanceCorrectly() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
|
||||||
|
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().includeDistance());
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(3));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(130.423D, 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getUnit(), is("km"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusShouldApplyLimit() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
|
||||||
|
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2));
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(),
|
||||||
|
new Distance(100, KILOMETERS), newGeoRadiusArgs().sortAscending());
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(0).getContent().getName(), is(PALERMO.getName()));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getName(), is(ARIGENTO.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(),
|
||||||
|
new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance());
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getUnit(), is("km"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusByMemberShouldApplyLimit() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO.getName(),
|
||||||
|
new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2));
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRemoveDeletesMembers() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1_BYTES, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
assertThat(clusterConnection.geoRemove(KEY_1_BYTES, ARIGENTO.getName()), is(1L));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,13 +16,14 @@
|
|||||||
package org.springframework.data.redis.connection.jedis;
|
package org.springframework.data.redis.connection.jedis;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.ClassRule;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -32,6 +33,7 @@ import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
|||||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||||
import org.springframework.data.redis.connection.RedisServer;
|
import org.springframework.data.redis.connection.RedisServer;
|
||||||
import org.springframework.data.redis.connection.ReturnType;
|
import org.springframework.data.redis.connection.ReturnType;
|
||||||
|
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||||
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
||||||
import org.springframework.test.annotation.IfProfileValue;
|
import org.springframework.test.annotation.IfProfileValue;
|
||||||
|
|
||||||
@@ -40,20 +42,19 @@ import org.springframework.test.annotation.IfProfileValue;
|
|||||||
* @author Thomas Darimont
|
* @author Thomas Darimont
|
||||||
*/
|
*/
|
||||||
public class JedisSentinelIntegrationTests extends AbstractConnectionIntegrationTests {
|
public class JedisSentinelIntegrationTests extends AbstractConnectionIntegrationTests {
|
||||||
|
|
||||||
private static final String MASTER_NAME = "mymaster";
|
private static final String MASTER_NAME = "mymaster";
|
||||||
private static final RedisServer SENTINEL_0 = new RedisServer("127.0.0.1", 26379);
|
private static final RedisServer SENTINEL_0 = new RedisServer("127.0.0.1", 26379);
|
||||||
private static final RedisServer SENTINEL_1 = new RedisServer("127.0.0.1", 26380);
|
private static final RedisServer SENTINEL_1 = new RedisServer("127.0.0.1", 26380);
|
||||||
|
|
||||||
private static final RedisServer SLAVE_0 = new RedisServer("127.0.0.1", 6380);
|
private static final RedisServer SLAVE_0 = new RedisServer("127.0.0.1", 6380);
|
||||||
private static final RedisServer SLAVE_1 = new RedisServer("127.0.0.1", 6381);
|
private static final RedisServer SLAVE_1 = new RedisServer("127.0.0.1", 6381);
|
||||||
|
|
||||||
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
|
|
||||||
.master(MASTER_NAME)
|
|
||||||
.sentinel(SENTINEL_0)
|
|
||||||
.sentinel(SENTINEL_1);
|
|
||||||
|
|
||||||
public @Rule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
|
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
|
||||||
|
.master(MASTER_NAME).sentinel(SENTINEL_0).sentinel(SENTINEL_1);
|
||||||
|
|
||||||
|
public static @ClassRule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
|
||||||
|
public @Rule MinimumRedisVersionRule minimumVersionRule = new MinimumRedisVersionRule();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -129,9 +130,9 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
|
|||||||
|
|
||||||
List<RedisServer> servers = (List<RedisServer>) connectionFactory.getSentinelConnection().masters();
|
List<RedisServer> servers = (List<RedisServer>) connectionFactory.getSentinelConnection().masters();
|
||||||
assertThat(servers.size(), is(1));
|
assertThat(servers.size(), is(1));
|
||||||
assertThat(servers.get(0).getName(),is(MASTER_NAME));
|
assertThat(servers.get(0).getName(), is(MASTER_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DATAREDIS-330
|
* @see DATAREDIS-330
|
||||||
*/
|
*/
|
||||||
@@ -139,10 +140,10 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
|
|||||||
public void shouldReadSlavesOfMastersCorrectly() {
|
public void shouldReadSlavesOfMastersCorrectly() {
|
||||||
|
|
||||||
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
|
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
|
||||||
|
|
||||||
List<RedisServer> servers = (List<RedisServer>) sentinelConnection.masters();
|
List<RedisServer> servers = (List<RedisServer>) sentinelConnection.masters();
|
||||||
assertThat(servers.size(), is(1));
|
assertThat(servers.size(), is(1));
|
||||||
|
|
||||||
Collection<RedisServer> slaves = sentinelConnection.slaves(servers.get(0));
|
Collection<RedisServer> slaves = sentinelConnection.slaves(servers.get(0));
|
||||||
assertThat(slaves.size(), is(2));
|
assertThat(slaves.size(), is(2));
|
||||||
assertThat(slaves, hasItems(SLAVE_0, SLAVE_1));
|
assertThat(slaves, hasItems(SLAVE_0, SLAVE_1));
|
||||||
|
|||||||
@@ -16,12 +16,18 @@
|
|||||||
package org.springframework.data.redis.connection.lettuce;
|
package org.springframework.data.redis.connection.lettuce;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.hamcrest.collection.IsCollectionWithSize.*;
|
||||||
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
|
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
import static org.hamcrest.number.IsCloseTo.*;
|
import static org.hamcrest.number.IsCloseTo.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
||||||
|
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
|
||||||
|
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
|
||||||
import static org.springframework.data.redis.core.ScanOptions.*;
|
import static org.springframework.data.redis.core.ScanOptions.*;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -36,14 +42,21 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
import org.springframework.data.redis.connection.ClusterConnectionTests;
|
import org.springframework.data.redis.connection.ClusterConnectionTests;
|
||||||
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
|
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
|
||||||
import org.springframework.data.redis.connection.DataType;
|
import org.springframework.data.redis.connection.DataType;
|
||||||
import org.springframework.data.redis.connection.DefaultSortParameters;
|
import org.springframework.data.redis.connection.DefaultSortParameters;
|
||||||
import org.springframework.data.redis.connection.DefaultTuple;
|
import org.springframework.data.redis.connection.DefaultTuple;
|
||||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||||
import org.springframework.data.redis.connection.RedisNode;
|
import org.springframework.data.redis.connection.RedisNode;
|
||||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||||
@@ -54,7 +67,9 @@ import org.springframework.data.redis.connection.jedis.JedisConverters;
|
|||||||
import org.springframework.data.redis.core.Cursor;
|
import org.springframework.data.redis.core.Cursor;
|
||||||
import org.springframework.data.redis.core.ScanOptions;
|
import org.springframework.data.redis.core.ScanOptions;
|
||||||
import org.springframework.data.redis.core.types.Expiration;
|
import org.springframework.data.redis.core.types.Expiration;
|
||||||
|
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||||
import org.springframework.data.redis.test.util.RedisClusterRule;
|
import org.springframework.data.redis.test.util.RedisClusterRule;
|
||||||
|
import org.springframework.test.annotation.IfProfileValue;
|
||||||
|
|
||||||
import com.lambdaworks.redis.RedisURI.Builder;
|
import com.lambdaworks.redis.RedisURI.Builder;
|
||||||
import com.lambdaworks.redis.cluster.RedisAdvancedClusterConnection;
|
import com.lambdaworks.redis.cluster.RedisAdvancedClusterConnection;
|
||||||
@@ -78,12 +93,28 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
|||||||
static final byte[] VALUE_2_BYTES = LettuceConverters.toBytes(VALUE_2);
|
static final byte[] VALUE_2_BYTES = LettuceConverters.toBytes(VALUE_2);
|
||||||
static final byte[] VALUE_3_BYTES = LettuceConverters.toBytes(VALUE_3);
|
static final byte[] VALUE_3_BYTES = LettuceConverters.toBytes(VALUE_3);
|
||||||
|
|
||||||
|
static final GeoLocation<String> ARIGENTO = new GeoLocation<String>("arigento", POINT_ARIGENTO);
|
||||||
|
static final GeoLocation<String> CATANIA = new GeoLocation<String>("catania", POINT_CATANIA);
|
||||||
|
static final GeoLocation<String> PALERMO = new GeoLocation<String>("palermo", POINT_PALERMO);
|
||||||
|
|
||||||
|
static final GeoLocation<byte[]> ARIGENTO_BYTES = new GeoLocation<byte[]>(
|
||||||
|
"arigento".getBytes(Charset.forName("UTF-8")), POINT_ARIGENTO);
|
||||||
|
static final GeoLocation<byte[]> CATANIA_BYTES = new GeoLocation<byte[]>("catania".getBytes(Charset.forName("UTF-8")),
|
||||||
|
POINT_CATANIA);
|
||||||
|
static final GeoLocation<byte[]> PALERMO_BYTES = new GeoLocation<byte[]>("palermo".getBytes(Charset.forName("UTF-8")),
|
||||||
|
POINT_PALERMO);
|
||||||
|
|
||||||
RedisClusterClient client;
|
RedisClusterClient client;
|
||||||
RedisAdvancedClusterConnection<String, String> nativeConnection;
|
RedisAdvancedClusterConnection<String, String> nativeConnection;
|
||||||
LettuceClusterConnection clusterConnection;
|
LettuceClusterConnection clusterConnection;
|
||||||
|
|
||||||
public static @ClassRule RedisClusterRule clusterAvailable = new RedisClusterRule();
|
public static @ClassRule RedisClusterRule clusterAvailable = new RedisClusterRule();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for specific Redis Versions
|
||||||
|
*/
|
||||||
|
public @Rule MinimumRedisVersionRule version = new MinimumRedisVersionRule();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
@@ -2441,4 +2472,249 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
|||||||
|
|
||||||
assertThat(nativeConnection.exists(KEY_1), is(false));
|
assertThat(nativeConnection.exists(KEY_1), is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoAddSingleGeoLocation() {
|
||||||
|
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO_BYTES), is(1L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoAddMultipleGeoLocations() {
|
||||||
|
assertThat(clusterConnection.geoAdd(KEY_1_BYTES,
|
||||||
|
Arrays.asList(PALERMO_BYTES, ARIGENTO_BYTES, CATANIA_BYTES, PALERMO_BYTES)), is(3L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoDist() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
Distance distance = clusterConnection.geoDist(KEY_1_BYTES, PALERMO_BYTES.getName(), CATANIA_BYTES.getName());
|
||||||
|
assertThat(distance.getValue(), is(closeTo(166274.15156960033D, 0.005)));
|
||||||
|
assertThat(distance.getUnit(), is("m"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoDistWithMetric() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
Distance distance = clusterConnection.geoDist(KEY_1_BYTES, PALERMO_BYTES.getName(), CATANIA_BYTES.getName(),
|
||||||
|
KILOMETERS);
|
||||||
|
assertThat(distance.getValue(), is(closeTo(166.27415156960033D, 0.005)));
|
||||||
|
assertThat(distance.getUnit(), is("km"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoHash() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO_BYTES.getName(), CATANIA_BYTES.getName());
|
||||||
|
assertThat(result, contains("sqc8b49rny0", "sqdtr74hyu0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoHashNonExisting() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
List<String> result = clusterConnection.geoHash(KEY_1_BYTES, PALERMO_BYTES.getName(), ARIGENTO_BYTES.getName(),
|
||||||
|
CATANIA_BYTES.getName());
|
||||||
|
assertThat(result, contains("sqc8b49rny0", (String) null, "sqdtr74hyu0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoPosition() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
List<Point> positions = clusterConnection.geoPos(KEY_1_BYTES, PALERMO_BYTES.getName(), CATANIA_BYTES.getName());
|
||||||
|
|
||||||
|
assertThat(positions.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(positions.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
|
||||||
|
assertThat(positions.get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(positions.get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoPositionNonExisting() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
List<Point> positions = clusterConnection.geoPos(KEY_1_BYTES, PALERMO_BYTES.getName(), ARIGENTO_BYTES.getName(),
|
||||||
|
CATANIA_BYTES.getName());
|
||||||
|
|
||||||
|
assertThat(positions.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(positions.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
|
||||||
|
assertThat(positions.get(1), is(nullValue()));
|
||||||
|
|
||||||
|
assertThat(positions.get(2).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(positions.get(2).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusShouldReturnMembersCorrectly() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
|
||||||
|
new Circle(new Point(15D, 37D), new Distance(150D, KILOMETERS)));
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusShouldReturnDistanceCorrectly() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
|
||||||
|
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().includeDistance());
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(3));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(130.423D, 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getUnit(), is("km"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusShouldApplyLimit() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadius(KEY_1_BYTES,
|
||||||
|
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)), newGeoRadiusArgs().limit(2));
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(),
|
||||||
|
new Distance(100, KILOMETERS), newGeoRadiusArgs().sortAscending());
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(0).getContent().getName(), is(PALERMO_BYTES.getName()));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getName(), is(ARIGENTO_BYTES.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(),
|
||||||
|
new Distance(100, KILOMETERS), newGeoRadiusArgs().includeDistance());
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.978D, 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getUnit(), is("km"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRadiusByMemberShouldApplyLimit() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<byte[]>> result = clusterConnection.geoRadiusByMember(KEY_1_BYTES, PALERMO_BYTES.getName(),
|
||||||
|
new Distance(200, KILOMETERS), newGeoRadiusArgs().limit(2));
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2+")
|
||||||
|
public void geoRemoveDeletesMembers() {
|
||||||
|
|
||||||
|
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, ARIGENTO.getPoint().getX(), ARIGENTO.getPoint().getY(), ARIGENTO.getName());
|
||||||
|
nativeConnection.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA.getName());
|
||||||
|
|
||||||
|
assertThat(clusterConnection.geoRemove(KEY_1_BYTES, ARIGENTO_BYTES.getName()), is(1L));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import static org.junit.Assert.*;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
|
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
|
||||||
@@ -67,4 +68,83 @@ public class LettuceConnectionTransactionIntegrationTests extends AbstractConnec
|
|||||||
super.testSelect();
|
super.testSelect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoPosition() {
|
||||||
|
super.geoPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoPositionNonExisting() {
|
||||||
|
super.geoPositionNonExisting();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoRadiusByMemberShouldApplyLimit() {
|
||||||
|
super.geoRadiusByMemberShouldApplyLimit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
|
||||||
|
super.geoRadiusByMemberShouldReturnDistanceCorrectly();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
|
||||||
|
super.geoRadiusByMemberShouldReturnMembersCorrectly();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoRadiusShouldApplyLimit() {
|
||||||
|
super.geoRadiusShouldApplyLimit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#")
|
||||||
|
public void geoRadiusShouldReturnDistanceCorrectly() {
|
||||||
|
super.geoRadiusShouldReturnDistanceCorrectly();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoRadiusShouldReturnMembersCorrectly() {
|
||||||
|
super.geoRadiusShouldReturnMembersCorrectly();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.data.redis.ConnectionFactoryTracker;
|
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||||
@@ -34,6 +36,7 @@ import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
|||||||
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
import org.springframework.data.redis.connection.RedisSentinelConnection;
|
||||||
import org.springframework.data.redis.connection.RedisServer;
|
import org.springframework.data.redis.connection.RedisServer;
|
||||||
import org.springframework.data.redis.connection.StringRedisConnection;
|
import org.springframework.data.redis.connection.StringRedisConnection;
|
||||||
|
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||||
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
import org.springframework.data.redis.test.util.RedisSentinelRule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +55,8 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
|||||||
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
|
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
|
||||||
.master(MASTER_NAME).sentinel(SENTINEL_0).sentinel(SENTINEL_1);
|
.master(MASTER_NAME).sentinel(SENTINEL_0).sentinel(SENTINEL_1);
|
||||||
|
|
||||||
public @Rule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
|
public static @ClassRule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
|
||||||
|
public @Rule MinimumRedisVersionRule minimumVersionRule = new MinimumRedisVersionRule();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -121,4 +125,23 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoHash() {
|
||||||
|
super.geoHash();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
@Ignore("see mp911de/lettuce#241")
|
||||||
|
public void geoHashNonExisting() {
|
||||||
|
super.geoHashNonExisting();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,51 +15,76 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.core;
|
package org.springframework.data.redis.core;
|
||||||
|
|
||||||
|
import static org.hamcrest.collection.IsCollectionWithSize.*;
|
||||||
|
import static org.hamcrest.core.Is.*;
|
||||||
|
import static org.hamcrest.core.IsEqual.*;
|
||||||
|
import static org.hamcrest.core.IsNull.*;
|
||||||
|
import static org.hamcrest.number.IsCloseTo.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit.*;
|
||||||
|
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import org.springframework.data.geo.Circle;
|
||||||
|
import org.springframework.data.geo.Distance;
|
||||||
|
import org.springframework.data.geo.GeoResults;
|
||||||
|
import org.springframework.data.geo.Point;
|
||||||
|
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||||
import org.springframework.data.redis.ObjectFactory;
|
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.connection.RedisConnection;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
|
||||||
|
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||||
import java.text.DecimalFormat;
|
import org.springframework.test.annotation.IfProfileValue;
|
||||||
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}
|
* Integration test of {@link org.springframework.data.redis.core.DefaultGeoOperations}
|
||||||
*
|
*
|
||||||
* @author Ninad Divadkar
|
* @author Ninad Divadkar
|
||||||
|
* @author Christoph Strobl
|
||||||
*/
|
*/
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
|
@IfProfileValue(name = "redisVersion", value = "3.2.0+")
|
||||||
public class DefaultGeoOperationsTests<K, M> {
|
public class DefaultGeoOperationsTests<K, M> {
|
||||||
|
|
||||||
|
public static @ClassRule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
|
||||||
|
|
||||||
|
private static final Point POINT_ARIGENTO = new Point(13.583333, 37.316667);
|
||||||
|
private static final Point POINT_CATANIA = new Point(15.087269, 37.502669);
|
||||||
|
private static final Point POINT_PALERMO = new Point(13.361389, 38.115556);
|
||||||
|
|
||||||
|
private static final double DISTANCE_PALERMO_CATANIA_METERS = 166274.15156960033;
|
||||||
|
private static final double DISTANCE_PALERMO_CATANIA_KILOMETERS = 166.27415156960033;
|
||||||
|
private static final double DISTANCE_PALERMO_CATANIA_MILES = 103.31822459492733;
|
||||||
|
private static final double DISTANCE_PALERMO_CATANIA_FEET = 545518.8699790037;
|
||||||
|
|
||||||
private RedisTemplate<K, M> redisTemplate;
|
private RedisTemplate<K, M> redisTemplate;
|
||||||
|
|
||||||
private ObjectFactory<K> keyFactory;
|
private ObjectFactory<K> keyFactory;
|
||||||
|
|
||||||
private ObjectFactory<M> valueFactory;
|
private ObjectFactory<M> valueFactory;
|
||||||
|
|
||||||
private GeoOperations<K, M> geoOperations;
|
private GeoOperations<K, M> geoOperations;
|
||||||
|
|
||||||
public DefaultGeoOperationsTests(RedisTemplate<K, M> redisTemplate, ObjectFactory<K> keyFactory,
|
public DefaultGeoOperationsTests(RedisTemplate<K, M> redisTemplate, ObjectFactory<K> keyFactory,
|
||||||
ObjectFactory<M> valueFactory) {
|
ObjectFactory<M> valueFactory) {
|
||||||
|
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.keyFactory = keyFactory;
|
this.keyFactory = keyFactory;
|
||||||
this.valueFactory = valueFactory;
|
this.valueFactory = valueFactory;
|
||||||
|
|
||||||
|
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
@@ -67,6 +92,11 @@ public class DefaultGeoOperationsTests<K, M> {
|
|||||||
return AbstractOperationsTestParams.testParams();
|
return AbstractOperationsTestParams.testParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp() {
|
||||||
|
ConnectionFactoryTracker.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
geoOperations = redisTemplate.opsForGeo();
|
geoOperations = redisTemplate.opsForGeo();
|
||||||
@@ -74,6 +104,7 @@ public class DefaultGeoOperationsTests<K, M> {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
|
||||||
redisTemplate.execute(new RedisCallback<Object>() {
|
redisTemplate.execute(new RedisCallback<Object>() {
|
||||||
public Object doInRedis(RedisConnection connection) {
|
public Object doInRedis(RedisConnection connection) {
|
||||||
connection.flushDb();
|
connection.flushDb();
|
||||||
@@ -82,174 +113,370 @@ public class DefaultGeoOperationsTests<K, M> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGeoAdd() throws Exception {
|
public void testGeoAdd() {
|
||||||
K key = keyFactory.instance();
|
|
||||||
M v1 = valueFactory.instance();
|
Long numAdded = geoOperations.geoAdd(keyFactory.instance(), POINT_PALERMO, valueFactory.instance());
|
||||||
Long numAdded = geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
|
|
||||||
assertEquals(numAdded.longValue(), 1L);
|
assertThat(numAdded, is(1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/**
|
||||||
public void testGeoAdd2() throws Exception {
|
* @see DATAREDIS-438
|
||||||
K key = keyFactory.instance();
|
*/
|
||||||
Map<M, GeoCoordinate> memberCoordinateMap = new HashMap<M, GeoCoordinate>();
|
@Test
|
||||||
memberCoordinateMap.put(valueFactory.instance(), new GeoCoordinate(2.2323, 43.324));
|
public void testGeoAddWithLocationMap() {
|
||||||
memberCoordinateMap.put(valueFactory.instance(), new GeoCoordinate(12.993, 31.3994));
|
|
||||||
Long numAdded = geoOperations.geoAdd(key, memberCoordinateMap);
|
|
||||||
assertEquals(numAdded.longValue(), 2L);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
Map<M, Point> memberCoordinateMap = new HashMap<M, Point>();
|
||||||
public void testGeoDist() throws Exception {
|
memberCoordinateMap.put(valueFactory.instance(), POINT_PALERMO);
|
||||||
K key = keyFactory.instance();
|
memberCoordinateMap.put(valueFactory.instance(), POINT_CATANIA);
|
||||||
M v1 = valueFactory.instance();
|
|
||||||
M v2 = valueFactory.instance();
|
|
||||||
|
|
||||||
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
|
Long numAdded = geoOperations.geoAdd(keyFactory.instance(), memberCoordinateMap);
|
||||||
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
|
|
||||||
|
|
||||||
Double dist = geoOperations.geoDist(key, v1, v2);
|
assertThat(numAdded, is(2L));
|
||||||
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);
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoDistShouldReturnDistanceInMetersByDefault() {
|
||||||
|
|
||||||
dist = geoOperations.geoDist(key, v1, v2, GeoUnit.Miles);
|
K key = keyFactory.instance();
|
||||||
assertEquals(dist.doubleValue(), 103.31822459492733, 0.00001);
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
|
||||||
dist = geoOperations.geoDist(key, v1, v2, GeoUnit.Feet);
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
assertEquals(dist.doubleValue(), 545518.8699790037, 0.00001);
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
Distance dist = geoOperations.geoDist(key, member1, member2);
|
||||||
public void testGeoHash() throws Exception {
|
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_METERS, 0.005));
|
||||||
K key = keyFactory.instance();
|
assertThat(dist.getUnit(), is(equalTo("m")));
|
||||||
M v1 = valueFactory.instance();
|
}
|
||||||
M v2 = valueFactory.instance();
|
|
||||||
|
|
||||||
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
|
/**
|
||||||
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoDistShouldReturnDistanceInKilometersCorrectly() {
|
||||||
|
|
||||||
List<byte[]> result = geoOperations.geoHash(key, v1, v2);
|
K key = keyFactory.instance();
|
||||||
assertEquals(result.size(), 2);
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
|
||||||
final RedisSerializer<String> serializer = new StringRedisSerializer();
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
|
||||||
assertEquals(serializer.deserialize(result.get(0)), "sqc8b49rny0");
|
Distance dist = geoOperations.geoDist(key, member1, member2, KILOMETERS);
|
||||||
assertEquals(serializer.deserialize(result.get(1)), "sqdtr74hyu0");
|
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_KILOMETERS, 0.005));
|
||||||
}
|
assertThat(dist.getUnit(), is(equalTo("km")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
/**
|
||||||
public void testGeoPos() throws Exception {
|
* @see DATAREDIS-438
|
||||||
K key = keyFactory.instance();
|
*/
|
||||||
M v1 = valueFactory.instance();
|
@Test
|
||||||
M v2 = valueFactory.instance();
|
public void geoDistShouldReturnDistanceInMilesCorrectly() {
|
||||||
M v3 = valueFactory.instance();
|
|
||||||
|
|
||||||
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
|
K key = keyFactory.instance();
|
||||||
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
|
||||||
List<GeoCoordinate> result = geoOperations.geoPos(key, v1, v2, v3);// v3 is nonexisting
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
assertEquals(result.size(), 3);
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
|
||||||
assertEquals(result.get(0).getLongitude(), 13.361389338970184, 0.000001);
|
Distance dist = geoOperations.geoDist(key, member1, member2, DistanceUnit.MILES);
|
||||||
assertEquals(result.get(0).getLatitude(), 38.115556395496299, 0.000001);
|
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_MILES, 0.005));
|
||||||
|
assertThat(dist.getUnit(), is(equalTo("mi")));
|
||||||
|
}
|
||||||
|
|
||||||
assertEquals(result.get(1).getLongitude(), 15.087267458438873, 0.000001);
|
/**
|
||||||
assertEquals(result.get(1).getLatitude(), 37.50266842333162, 0.000001);
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoDistShouldReturnDistanceInFeeCorrectly() {
|
||||||
|
|
||||||
assertNull(result.get(2));
|
K key = keyFactory.instance();
|
||||||
}
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
|
||||||
@Test
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
public void testGeoRadius() throws Exception{
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
K key = keyFactory.instance();
|
|
||||||
M v1 = valueFactory.instance();
|
|
||||||
M v2 = valueFactory.instance();
|
|
||||||
|
|
||||||
geoOperations.geoAdd(key, 13.361389, 38.115556, v1);
|
Distance dist = geoOperations.geoDist(key, member1, member2, DistanceUnit.FEET);
|
||||||
geoOperations.geoAdd(key, 15.087269, 37.502669, v2);
|
assertThat(dist.getValue(), closeTo(DISTANCE_PALERMO_CATANIA_FEET, 0.005));
|
||||||
|
assertThat(dist.getUnit(), is(equalTo("ft")));
|
||||||
|
}
|
||||||
|
|
||||||
List<GeoRadiusResponse> result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters);
|
/**
|
||||||
Assert.assertEquals(2, result.size());
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoHash() {
|
||||||
|
|
||||||
// with dist, descending
|
K key = keyFactory.instance();
|
||||||
result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withDist().sortDescending());
|
M v1 = valueFactory.instance();
|
||||||
Assert.assertEquals(2, result.size());
|
M v2 = valueFactory.instance();
|
||||||
Assert.assertEquals(result.get(0).getDistance(), 190.4424d, 0.0001);
|
|
||||||
Assert.assertEquals(result.get(1).getDistance(), 56.4413d, 0.0001);
|
|
||||||
|
|
||||||
// with coord, ascending
|
geoOperations.geoAdd(key, POINT_PALERMO, v1);
|
||||||
result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().sortAscending());
|
geoOperations.geoAdd(key, POINT_CATANIA, v2);
|
||||||
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
|
List<String> result = geoOperations.geoHash(key, v1, v2);
|
||||||
result = geoOperations.georadius(key, 15, 37, 200, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().withDist().sortAscending());
|
assertThat(result, hasSize(2));
|
||||||
Assert.assertEquals(2, result.size());
|
|
||||||
|
|
||||||
Assert.assertEquals(result.get(0).getDistance(), 56.4413d, 0.0001);
|
final RedisSerializer<String> serializer = new StringRedisSerializer();
|
||||||
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
|
assertThat(result.get(0), is(equalTo("sqc8b49rny0")));
|
||||||
public void testGeoRadiusByMember() throws Exception{
|
assertThat(result.get(1), is(equalTo("sqdtr74hyu0")));
|
||||||
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
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoPos() {
|
||||||
|
|
||||||
geoOperations.geoAdd(key, 13.583333, 37.316667, v3);//Agrigento
|
K key = keyFactory.instance();
|
||||||
|
M v1 = valueFactory.instance();
|
||||||
|
M v2 = valueFactory.instance();
|
||||||
|
M v3 = valueFactory.instance();
|
||||||
|
|
||||||
List<GeoRadiusResponse> result = geoOperations.georadiusByMember(key, v3, 200, GeoUnit.KiloMeters);
|
geoOperations.geoAdd(key, POINT_PALERMO, v1);
|
||||||
Assert.assertEquals(3, result.size());
|
geoOperations.geoAdd(key, POINT_CATANIA, v2);
|
||||||
|
|
||||||
// with dist, descending
|
List<Point> result = geoOperations.geoPos(key, v1, v2, v3);// v3 is nonexisting
|
||||||
result = geoOperations.georadiusByMember(key, v3, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withDist().sortDescending());
|
assertThat(result, hasSize(3));
|
||||||
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
|
assertThat(result.get(0).getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
result = geoOperations.georadiusByMember(key, v3, 100, GeoUnit.KiloMeters, GeoRadiusParam.geoRadiusParam().withCoord().sortAscending());
|
assertThat(result.get(0).getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
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);
|
|
||||||
|
|
||||||
|
assertThat(result.get(1).getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(result.get(1).getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
|
||||||
// with coord and dist, ascending
|
assertThat(result.get(2), is(nullValue()));
|
||||||
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);
|
* @see DATAREDIS-438
|
||||||
Assert.assertEquals(result.get(0).getCoordinate().getLatitude(), 38.1155563954963d, 0.0001);
|
*/
|
||||||
Assert.assertEquals(result.get(1).getDistance(), 90.9778d, 0.0001);
|
@Test
|
||||||
Assert.assertEquals(result.get(1).getCoordinate().getLongitude(), 13.583331406116486d, 0.0001);
|
public void geoRadiusShouldReturnMembersCorrectly() {
|
||||||
Assert.assertEquals(result.get(1).getCoordinate().getLatitude(), 37.316668049938166d, 0.0001);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
K key = keyFactory.instance();
|
||||||
public void testGeoRemove(){
|
M member1 = valueFactory.instance();
|
||||||
K key = keyFactory.instance();
|
M member2 = valueFactory.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);
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
assertEquals(1L, numRemoved.longValue());
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
}
|
|
||||||
|
GeoResults<GeoLocation<M>> result = geoOperations.georadius(key,
|
||||||
|
new Circle(new Point(15D, 37D), new Distance(200D, KILOMETERS)));
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoRadiusShouldReturnLocationsWithDistance() {
|
||||||
|
|
||||||
|
K key = keyFactory.instance();
|
||||||
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
|
||||||
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<M>> result = geoOperations.georadius(key,
|
||||||
|
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
|
||||||
|
newGeoRadiusArgs().includeDistance().sortDescending());
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(190.4424d, 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getUnit(), is(equalTo("km")));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(56.4413d, 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getDistance().getUnit(), is(equalTo("km")));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getName(), is(member2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoRadiusShouldReturnLocationsWithCoordinates() {
|
||||||
|
|
||||||
|
K key = keyFactory.instance();
|
||||||
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
|
||||||
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<M>> result = geoOperations.georadius(key,
|
||||||
|
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
|
||||||
|
newGeoRadiusArgs().includeCoordinates().sortAscending());
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getName(), is(member2));
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoRadiusShouldReturnLocationsWithCoordinatesAndDistance() {
|
||||||
|
|
||||||
|
K key = keyFactory.instance();
|
||||||
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
|
||||||
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<M>> result = geoOperations.georadius(key,
|
||||||
|
new Circle(new Point(15, 37), new Distance(200, KILOMETERS)),
|
||||||
|
newGeoRadiusArgs().includeCoordinates().includeDistance().sortAscending());
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(56.4413d, 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getUnit(), is(equalTo("km")));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_CATANIA.getX(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_CATANIA.getY(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getName(), is(member2));
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(190.4424d, 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getDistance().getUnit(), is(equalTo("km")));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
|
||||||
|
|
||||||
|
K key = keyFactory.instance();
|
||||||
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
M member3 = valueFactory.instance();
|
||||||
|
|
||||||
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
geoOperations.geoAdd(key, POINT_ARIGENTO, member3);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<M>> result = geoOperations.georadiusByMember(key, member3, new Distance(200, KILOMETERS));
|
||||||
|
assertThat(result.getContent(), hasSize(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
|
||||||
|
|
||||||
|
K key = keyFactory.instance();
|
||||||
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
M member3 = valueFactory.instance();
|
||||||
|
|
||||||
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
geoOperations.geoAdd(key, POINT_ARIGENTO, member3);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<M>> result = geoOperations.georadiusByMember(key, member3, new Distance(100, KILOMETERS),
|
||||||
|
newGeoRadiusArgs().includeDistance().sortDescending());
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(90.9778d, 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
|
||||||
|
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(0.0d, 0.005))); // itself
|
||||||
|
assertThat(result.getContent().get(1).getContent().getName(), is(member3));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoRadiusByMemberShouldReturnCoordinates() {
|
||||||
|
|
||||||
|
K key = keyFactory.instance();
|
||||||
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
M member3 = valueFactory.instance();
|
||||||
|
|
||||||
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
geoOperations.geoAdd(key, POINT_ARIGENTO, member3);
|
||||||
|
|
||||||
|
GeoResults<GeoLocation<M>> result = geoOperations.georadiusByMember(key, member3,
|
||||||
|
new Distance(100, DistanceUnit.KILOMETERS), newGeoRadiusArgs().includeCoordinates().sortAscending());
|
||||||
|
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_ARIGENTO.getX(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_ARIGENTO.getY(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getName(), is(member3));
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getName(), is(member1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void geoRadiusByMemberShouldReturnCoordinatesAndDistance() {
|
||||||
|
|
||||||
|
K key = keyFactory.instance();
|
||||||
|
M member1 = valueFactory.instance();
|
||||||
|
M member2 = valueFactory.instance();
|
||||||
|
M member3 = valueFactory.instance();
|
||||||
|
|
||||||
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
geoOperations.geoAdd(key, POINT_CATANIA, member2);
|
||||||
|
geoOperations.geoAdd(key, POINT_ARIGENTO, member3);
|
||||||
|
|
||||||
|
// with coord and dist, ascending
|
||||||
|
GeoResults<GeoLocation<M>> result = geoOperations.georadiusByMember(key, member1, new Distance(100, KILOMETERS),
|
||||||
|
newGeoRadiusArgs().includeCoordinates().includeDistance().sortAscending());
|
||||||
|
assertThat(result.getContent(), hasSize(2));
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(0).getDistance().getValue(), is(closeTo(0.0d, 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getPoint().getX(), is(closeTo(POINT_PALERMO.getX(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getPoint().getY(), is(closeTo(POINT_PALERMO.getY(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(0).getContent().getName(), is(member1));
|
||||||
|
|
||||||
|
assertThat(result.getContent().get(1).getDistance().getValue(), is(closeTo(90.9778d, 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getPoint().getX(), is(closeTo(POINT_ARIGENTO.getX(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getPoint().getY(), is(closeTo(POINT_ARIGENTO.getY(), 0.005)));
|
||||||
|
assertThat(result.getContent().get(1).getContent().getName(), is(member3));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAREDIS-438
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGeoRemove() {
|
||||||
|
|
||||||
|
K key = keyFactory.instance();
|
||||||
|
M member1 = valueFactory.instance();
|
||||||
|
|
||||||
|
geoOperations.geoAdd(key, POINT_PALERMO, member1);
|
||||||
|
|
||||||
|
assertThat(geoOperations.geoRemove(key, member1), is(1L));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,14 @@ import java.util.Iterator;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||||
import org.springframework.data.redis.ObjectFactory;
|
import org.springframework.data.redis.ObjectFactory;
|
||||||
import org.springframework.data.redis.RawObjectFactory;
|
import org.springframework.data.redis.RawObjectFactory;
|
||||||
import org.springframework.data.redis.SettingsUtils;
|
import org.springframework.data.redis.SettingsUtils;
|
||||||
@@ -44,7 +46,6 @@ import org.springframework.test.annotation.IfProfileValue;
|
|||||||
*
|
*
|
||||||
* @author Jennifer Hickey
|
* @author Jennifer Hickey
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Ninad Divadkar
|
|
||||||
* @param <K> Key type
|
* @param <K> Key type
|
||||||
* @param <HK> Hash key type
|
* @param <HK> Hash key type
|
||||||
* @param <HV> Hash value type
|
* @param <HV> Hash value type
|
||||||
@@ -66,10 +67,13 @@ public class DefaultHashOperationsTests<K, HK, HV> {
|
|||||||
|
|
||||||
public DefaultHashOperationsTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
|
public DefaultHashOperationsTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
|
||||||
ObjectFactory<HK> hashKeyFactory, ObjectFactory<HV> hashValueFactory) {
|
ObjectFactory<HK> hashKeyFactory, ObjectFactory<HV> hashValueFactory) {
|
||||||
|
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.keyFactory = keyFactory;
|
this.keyFactory = keyFactory;
|
||||||
this.hashKeyFactory = hashKeyFactory;
|
this.hashKeyFactory = hashKeyFactory;
|
||||||
this.hashValueFactory = hashValueFactory;
|
this.hashValueFactory = hashValueFactory;
|
||||||
|
|
||||||
|
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
@@ -95,6 +99,11 @@ public class DefaultHashOperationsTests<K, HK, HV> {
|
|||||||
{ rawTemplate, rawFactory, rawFactory, rawFactory } });
|
{ rawTemplate, rawFactory, rawFactory, rawFactory } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp() {
|
||||||
|
ConnectionFactoryTracker.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
hashOps = redisTemplate.opsForHash();
|
hashOps = redisTemplate.opsForHash();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 the original author or authors.
|
* Copyright 2014-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,12 +21,14 @@ import static org.junit.Assert.*;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.ClassRule;
|
import org.junit.ClassRule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||||
import org.springframework.data.redis.ObjectFactory;
|
import org.springframework.data.redis.ObjectFactory;
|
||||||
import org.springframework.data.redis.connection.RedisConnection;
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
|
||||||
@@ -51,9 +53,12 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
|
|||||||
|
|
||||||
public DefaultHyperLogLogOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
public DefaultHyperLogLogOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
||||||
ObjectFactory<V> valueFactory) {
|
ObjectFactory<V> valueFactory) {
|
||||||
|
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.keyFactory = keyFactory;
|
this.keyFactory = keyFactory;
|
||||||
this.valueFactory = valueFactory;
|
this.valueFactory = valueFactory;
|
||||||
|
|
||||||
|
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
@@ -61,6 +66,11 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
|
|||||||
return AbstractOperationsTestParams.testParams();
|
return AbstractOperationsTestParams.testParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp() {
|
||||||
|
ConnectionFactoryTracker.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
hyperLogLogOps = redisTemplate.opsForHyperLogLog();
|
hyperLogLogOps = redisTemplate.opsForHyperLogLog();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,11 +25,13 @@ import java.util.Collections;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||||
import org.springframework.data.redis.ObjectFactory;
|
import org.springframework.data.redis.ObjectFactory;
|
||||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||||
import org.springframework.data.redis.connection.RedisConnection;
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
@@ -56,9 +58,12 @@ public class DefaultListOperationsTests<K, V> {
|
|||||||
|
|
||||||
public DefaultListOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
public DefaultListOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
||||||
ObjectFactory<V> valueFactory) {
|
ObjectFactory<V> valueFactory) {
|
||||||
|
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.keyFactory = keyFactory;
|
this.keyFactory = keyFactory;
|
||||||
this.valueFactory = valueFactory;
|
this.valueFactory = valueFactory;
|
||||||
|
|
||||||
|
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
@@ -66,6 +71,11 @@ public class DefaultListOperationsTests<K, V> {
|
|||||||
return AbstractOperationsTestParams.testParams();
|
return AbstractOperationsTestParams.testParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp() {
|
||||||
|
ConnectionFactoryTracker.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
listOps = redisTemplate.opsForList();
|
listOps = redisTemplate.opsForList();
|
||||||
|
|||||||
@@ -29,12 +29,14 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||||
import org.springframework.data.redis.ObjectFactory;
|
import org.springframework.data.redis.ObjectFactory;
|
||||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||||
import org.springframework.data.redis.connection.RedisConnection;
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
@@ -63,9 +65,12 @@ public class DefaultSetOperationsTests<K, V> {
|
|||||||
|
|
||||||
public DefaultSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
public DefaultSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
||||||
ObjectFactory<V> valueFactory) {
|
ObjectFactory<V> valueFactory) {
|
||||||
|
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.keyFactory = keyFactory;
|
this.keyFactory = keyFactory;
|
||||||
this.valueFactory = valueFactory;
|
this.valueFactory = valueFactory;
|
||||||
|
|
||||||
|
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
@@ -73,6 +78,11 @@ public class DefaultSetOperationsTests<K, V> {
|
|||||||
return AbstractOperationsTestParams.testParams();
|
return AbstractOperationsTestParams.testParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp() {
|
||||||
|
ConnectionFactoryTracker.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
setOps = redisTemplate.opsForSet();
|
setOps = redisTemplate.opsForSet();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,14 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.redis.core;
|
package org.springframework.data.redis.core;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assume.*;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.springframework.data.redis.SpinBarrier.*;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.springframework.data.redis.matcher.RedisTestMatchers.*;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assume.assumeTrue;
|
|
||||||
import static org.springframework.data.redis.SpinBarrier.waitFor;
|
|
||||||
import static org.springframework.data.redis.matcher.RedisTestMatchers.isEqual;
|
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -34,11 +30,13 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||||
import org.springframework.data.redis.ObjectFactory;
|
import org.springframework.data.redis.ObjectFactory;
|
||||||
import org.springframework.data.redis.RedisTestProfileValueSource;
|
import org.springframework.data.redis.RedisTestProfileValueSource;
|
||||||
import org.springframework.data.redis.TestCondition;
|
import org.springframework.data.redis.TestCondition;
|
||||||
@@ -65,9 +63,12 @@ public class DefaultValueOperationsTests<K, V> {
|
|||||||
|
|
||||||
public DefaultValueOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
public DefaultValueOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
||||||
ObjectFactory<V> valueFactory) {
|
ObjectFactory<V> valueFactory) {
|
||||||
|
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.keyFactory = keyFactory;
|
this.keyFactory = keyFactory;
|
||||||
this.valueFactory = valueFactory;
|
this.valueFactory = valueFactory;
|
||||||
|
|
||||||
|
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
@@ -75,6 +76,11 @@ public class DefaultValueOperationsTests<K, V> {
|
|||||||
return AbstractOperationsTestParams.testParams();
|
return AbstractOperationsTestParams.testParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp() {
|
||||||
|
ConnectionFactoryTracker.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
valueOps = redisTemplate.opsForValue();
|
valueOps = redisTemplate.opsForValue();
|
||||||
@@ -280,19 +286,19 @@ public class DefaultValueOperationsTests<K, V> {
|
|||||||
assumeTrue(key1 instanceof byte[]);
|
assumeTrue(key1 instanceof byte[]);
|
||||||
assertNotNull(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key1));
|
assertNotNull(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see DATAREDIS-197
|
* @see DATAREDIS-197
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGetBit() {
|
public void testSetAndGetBit() {
|
||||||
|
|
||||||
assumeTrue(redisTemplate instanceof StringRedisTemplate);
|
assumeTrue(redisTemplate instanceof StringRedisTemplate);
|
||||||
|
|
||||||
K key1 = keyFactory.instance();
|
K key1 = keyFactory.instance();
|
||||||
int bitOffset = 65;
|
int bitOffset = 65;
|
||||||
valueOps.setBit(key1, bitOffset, true);
|
valueOps.setBit(key1, bitOffset, true);
|
||||||
|
|
||||||
assertEquals(true, valueOps.getBit(key1, bitOffset));
|
assertEquals(true, valueOps.getBit(key1, bitOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,12 +30,14 @@ import java.util.LinkedHashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import org.springframework.data.redis.ConnectionFactoryTracker;
|
||||||
import org.springframework.data.redis.DoubleAsStringObjectFactory;
|
import org.springframework.data.redis.DoubleAsStringObjectFactory;
|
||||||
import org.springframework.data.redis.DoubleObjectFactory;
|
import org.springframework.data.redis.DoubleObjectFactory;
|
||||||
import org.springframework.data.redis.LongAsStringObjectFactory;
|
import org.springframework.data.redis.LongAsStringObjectFactory;
|
||||||
@@ -71,9 +73,12 @@ public class DefaultZSetOperationsTests<K, V> {
|
|||||||
|
|
||||||
public DefaultZSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
public DefaultZSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
|
||||||
ObjectFactory<V> valueFactory) {
|
ObjectFactory<V> valueFactory) {
|
||||||
|
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.keyFactory = keyFactory;
|
this.keyFactory = keyFactory;
|
||||||
this.valueFactory = valueFactory;
|
this.valueFactory = valueFactory;
|
||||||
|
|
||||||
|
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
@@ -81,6 +86,11 @@ public class DefaultZSetOperationsTests<K, V> {
|
|||||||
return AbstractOperationsTestParams.testParams();
|
return AbstractOperationsTestParams.testParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp() {
|
||||||
|
ConnectionFactoryTracker.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
zSetOps = redisTemplate.opsForZSet();
|
zSetOps = redisTemplate.opsForZSet();
|
||||||
@@ -179,10 +189,8 @@ public class DefaultZSetOperationsTests<K, V> {
|
|||||||
@Test
|
@Test
|
||||||
public void testRangeByLexUnbounded() {
|
public void testRangeByLexUnbounded() {
|
||||||
|
|
||||||
assumeThat(
|
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
|
||||||
valueFactory,
|
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
|
||||||
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
|
|
||||||
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
|
|
||||||
|
|
||||||
K key = keyFactory.instance();
|
K key = keyFactory.instance();
|
||||||
V value1 = valueFactory.instance();
|
V value1 = valueFactory.instance();
|
||||||
@@ -205,10 +213,8 @@ public class DefaultZSetOperationsTests<K, V> {
|
|||||||
@Test
|
@Test
|
||||||
public void testRangeByLexBounded() {
|
public void testRangeByLexBounded() {
|
||||||
|
|
||||||
assumeThat(
|
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
|
||||||
valueFactory,
|
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
|
||||||
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
|
|
||||||
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
|
|
||||||
|
|
||||||
K key = keyFactory.instance();
|
K key = keyFactory.instance();
|
||||||
V value1 = valueFactory.instance();
|
V value1 = valueFactory.instance();
|
||||||
@@ -231,10 +237,8 @@ public class DefaultZSetOperationsTests<K, V> {
|
|||||||
@Test
|
@Test
|
||||||
public void testRangeByLexUnboundedWithLimit() {
|
public void testRangeByLexUnboundedWithLimit() {
|
||||||
|
|
||||||
assumeThat(
|
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
|
||||||
valueFactory,
|
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
|
||||||
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
|
|
||||||
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
|
|
||||||
|
|
||||||
K key = keyFactory.instance();
|
K key = keyFactory.instance();
|
||||||
V value1 = valueFactory.instance();
|
V value1 = valueFactory.instance();
|
||||||
@@ -258,10 +262,8 @@ public class DefaultZSetOperationsTests<K, V> {
|
|||||||
@Test
|
@Test
|
||||||
public void testRangeByLexBoundedWithLimit() {
|
public void testRangeByLexBoundedWithLimit() {
|
||||||
|
|
||||||
assumeThat(
|
assumeThat(valueFactory, anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
|
||||||
valueFactory,
|
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
|
||||||
anyOf(instanceOf(DoubleObjectFactory.class), instanceOf(DoubleAsStringObjectFactory.class),
|
|
||||||
instanceOf(LongAsStringObjectFactory.class), instanceOf(LongObjectFactory.class)));
|
|
||||||
|
|
||||||
K key = keyFactory.instance();
|
K key = keyFactory.instance();
|
||||||
V value1 = valueFactory.instance();
|
V value1 = valueFactory.instance();
|
||||||
@@ -271,8 +273,8 @@ public class DefaultZSetOperationsTests<K, V> {
|
|||||||
zSetOps.add(key, value1, 1.9);
|
zSetOps.add(key, value1, 1.9);
|
||||||
zSetOps.add(key, value2, 3.7);
|
zSetOps.add(key, value2, 3.7);
|
||||||
zSetOps.add(key, value3, 5.8);
|
zSetOps.add(key, value3, 5.8);
|
||||||
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1), RedisZSetCommands.Limit
|
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1),
|
||||||
.limit().count(1).offset(1));
|
RedisZSetCommands.Limit.limit().count(1).offset(1));
|
||||||
|
|
||||||
assertEquals(1, tuples.size());
|
assertEquals(1, tuples.size());
|
||||||
V tuple = tuples.iterator().next();
|
V tuple = tuples.iterator().next();
|
||||||
|
|||||||
Reference in New Issue
Block a user