diff --git a/redisson/src/main/java/org/redisson/RedissonGeo.java b/redisson/src/main/java/org/redisson/RedissonGeo.java index 5f4f67b43..5e50b37d9 100644 --- a/redisson/src/main/java/org/redisson/RedissonGeo.java +++ b/redisson/src/main/java/org/redisson/RedissonGeo.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import org.redisson.api.GeoEntry; +import org.redisson.api.GeoOrder; import org.redisson.api.GeoPosition; import org.redisson.api.GeoUnit; import org.redisson.api.RFuture; @@ -146,6 +147,39 @@ public class RedissonGeo extends RedissonScoredSortedSet implements RGeo> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit) { return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUS, getName(), convert(longitude), convert(latitude), radius, geoUnit); } + + @Override + public List radius(double longitude, double latitude, double radius, GeoUnit geoUnit, int count) { + return get(radiusAsync(longitude, latitude, radius, geoUnit, count)); + } + + @Override + public RFuture> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, int count) { + return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUS, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "COUNT", count); + } + + @Override + public List radius(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + return get(radiusAsync(longitude, latitude, radius, geoUnit, geoOrder)); + } + + @Override + public RFuture> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUS, getName(), convert(longitude), convert(latitude), + radius, geoUnit, geoOrder); + } + + @Override + public List radius(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + return get(radiusAsync(longitude, latitude, radius, geoUnit, geoOrder, count)); + } + + @Override + public RFuture> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUS, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "COUNT", count, geoOrder); + } @Override public Map radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit) { @@ -155,7 +189,44 @@ public class RedissonGeo extends RedissonScoredSortedSet implements RGeo> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit) { RedisCommand> command = new RedisCommand>("GEORADIUS", distanceDecoder); - return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), radius, geoUnit, "WITHDIST"); + return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "WITHDIST"); + } + + @Override + public Map radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit, int count) { + return get(radiusWithDistanceAsync(longitude, latitude, radius, geoUnit, count)); + } + + @Override + public RFuture> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, int count) { + RedisCommand> command = new RedisCommand>("GEORADIUS", distanceDecoder); + return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "WITHDIST", "COUNT", count); + } + + @Override + public Map radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + return get(radiusWithDistanceAsync(longitude, latitude, radius, geoUnit, geoOrder)); + } + + @Override + public RFuture> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + RedisCommand> command = new RedisCommand>("GEORADIUS", distanceDecoder); + return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "WITHDIST", geoOrder); + } + + @Override + public Map radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + return get(radiusWithDistanceAsync(longitude, latitude, radius, geoUnit, geoOrder, count)); + } + + @Override + public RFuture> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + RedisCommand> command = new RedisCommand>("GEORADIUS", distanceDecoder); + return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "WITHDIST", "COUNT", count, geoOrder); } @Override @@ -168,6 +239,42 @@ public class RedissonGeo extends RedissonScoredSortedSet implements RGeo> command = new RedisCommand>("GEORADIUS", postitionDecoder); return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), radius, geoUnit, "WITHCOORD"); } + + @Override + public Map radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit, int count) { + return get(radiusWithPositionAsync(longitude, latitude, radius, geoUnit, count)); + } + + @Override + public RFuture> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, int count) { + RedisCommand> command = new RedisCommand>("GEORADIUS", postitionDecoder); + return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "WITHCOORD", "COUNT", count); + } + + @Override + public Map radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + return get(radiusWithPositionAsync(longitude, latitude, radius, geoUnit, geoOrder)); + } + + @Override + public RFuture> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + RedisCommand> command = new RedisCommand>("GEORADIUS", postitionDecoder); + return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "WITHCOORD", geoOrder); + } + + @Override + public Map radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + return get(radiusWithPositionAsync(longitude, latitude, radius, geoUnit, geoOrder, count)); + } + + @Override + public RFuture> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + RedisCommand> command = new RedisCommand>("GEORADIUS", postitionDecoder); + return commandExecutor.readAsync(getName(), codec, command, getName(), convert(longitude), convert(latitude), + radius, geoUnit, "WITHCOORD", "COUNT", count, geoOrder); + } @Override public List radius(V member, double radius, GeoUnit geoUnit) { @@ -179,6 +286,36 @@ public class RedissonGeo extends RedissonScoredSortedSet implements RGeo radius(V member, double radius, GeoUnit geoUnit, int count) { + return get(radiusAsync(member, radius, geoUnit, count)); + } + + @Override + public RFuture> radiusAsync(V member, double radius, GeoUnit geoUnit, int count) { + return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUSBYMEMBER, getName(), member, radius, geoUnit, "COUNT", count); + } + + @Override + public List radius(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + return get(radiusAsync(member, radius, geoUnit, geoOrder)); + } + + @Override + public RFuture> radiusAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUSBYMEMBER, getName(), member, radius, geoUnit, geoOrder); + } + + @Override + public List radius(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + return get(radiusAsync(member, radius, geoUnit, geoOrder, count)); + } + + @Override + public RFuture> radiusAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + return commandExecutor.readAsync(getName(), codec, RedisCommands.GEORADIUSBYMEMBER, getName(), member, radius, geoUnit, "COUNT", count, geoOrder); + } + @Override public Map radiusWithDistance(V member, double radius, GeoUnit geoUnit) { return get(radiusWithDistanceAsync(member, radius, geoUnit)); @@ -190,6 +327,39 @@ public class RedissonGeo extends RedissonScoredSortedSet implements RGeo radiusWithDistance(V member, double radius, GeoUnit geoUnit, int count) { + return get(radiusWithDistanceAsync(member, radius, geoUnit, count)); + } + + @Override + public RFuture> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit, int count) { + RedisCommand command = new RedisCommand("GEORADIUSBYMEMBER", distanceDecoder, 2); + return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHDIST", "COUNT", count); + } + + @Override + public Map radiusWithDistance(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + return get(radiusWithDistanceAsync(member, radius, geoUnit, geoOrder)); + } + + @Override + public RFuture> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + RedisCommand command = new RedisCommand("GEORADIUSBYMEMBER", distanceDecoder, 2); + return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHDIST", geoOrder); + } + + @Override + public Map radiusWithDistance(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + return get(radiusWithDistanceAsync(member, radius, geoUnit, geoOrder, count)); + } + + @Override + public RFuture> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + RedisCommand command = new RedisCommand("GEORADIUSBYMEMBER", distanceDecoder, 2); + return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHDIST", "COUNT", count, geoOrder); + } + @Override public Map radiusWithPosition(V member, double radius, GeoUnit geoUnit) { return get(radiusWithPositionAsync(member, radius, geoUnit)); @@ -200,4 +370,38 @@ public class RedissonGeo extends RedissonScoredSortedSet implements RGeo> command = new RedisCommand>("GEORADIUSBYMEMBER", postitionDecoder, 2); return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHCOORD"); } + + @Override + public Map radiusWithPosition(V member, double radius, GeoUnit geoUnit, int count) { + return get(radiusWithPositionAsync(member, radius, geoUnit, count)); + } + + @Override + public RFuture> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit, int count) { + RedisCommand> command = new RedisCommand>("GEORADIUSBYMEMBER", postitionDecoder, 2); + return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHCOORD", "COUNT", count); + } + + @Override + public Map radiusWithPosition(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + return get(radiusWithPositionAsync(member, radius, geoUnit, geoOrder)); + } + + @Override + public RFuture> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder) { + RedisCommand> command = new RedisCommand>("GEORADIUSBYMEMBER", postitionDecoder, 2); + return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHCOORD", geoOrder); + } + + @Override + public Map radiusWithPosition(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + return get(radiusWithPositionAsync(member, radius, geoUnit, geoOrder, count)); + } + + @Override + public RFuture> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count) { + RedisCommand> command = new RedisCommand>("GEORADIUSBYMEMBER", postitionDecoder, 2); + return commandExecutor.readAsync(getName(), codec, command, getName(), member, radius, geoUnit, "WITHCOORD", "COUNT", count, geoOrder); + } + } diff --git a/redisson/src/main/java/org/redisson/api/GeoEntry.java b/redisson/src/main/java/org/redisson/api/GeoEntry.java index d88bb6325..cbcfa4b4d 100644 --- a/redisson/src/main/java/org/redisson/api/GeoEntry.java +++ b/redisson/src/main/java/org/redisson/api/GeoEntry.java @@ -15,6 +15,11 @@ */ package org.redisson.api; +/** + * + * @author Nikita Koksharov + * + */ public class GeoEntry { private final double longitude; diff --git a/redisson/src/main/java/org/redisson/api/GeoOrder.java b/redisson/src/main/java/org/redisson/api/GeoOrder.java new file mode 100644 index 000000000..f80b7f5b6 --- /dev/null +++ b/redisson/src/main/java/org/redisson/api/GeoOrder.java @@ -0,0 +1,25 @@ +/** + * Copyright 2016 Nikita Koksharov + * + * 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.redisson.api; + +/** + * + * @author Nikita Koksharov + * + */ +public enum GeoOrder { + ASC, DESC +} diff --git a/redisson/src/main/java/org/redisson/api/GeoPosition.java b/redisson/src/main/java/org/redisson/api/GeoPosition.java index 4815a05c6..9cc9250db 100644 --- a/redisson/src/main/java/org/redisson/api/GeoPosition.java +++ b/redisson/src/main/java/org/redisson/api/GeoPosition.java @@ -15,6 +15,11 @@ */ package org.redisson.api; +/** + * + * @author Nikita Koksharov + * + */ public class GeoPosition { private final double longitude; diff --git a/redisson/src/main/java/org/redisson/api/GeoUnit.java b/redisson/src/main/java/org/redisson/api/GeoUnit.java index 65569f9ce..133663a15 100644 --- a/redisson/src/main/java/org/redisson/api/GeoUnit.java +++ b/redisson/src/main/java/org/redisson/api/GeoUnit.java @@ -15,6 +15,11 @@ */ package org.redisson.api; +/** + * + * @author Nikita Koksharov + * + */ public enum GeoUnit { METERS { diff --git a/redisson/src/main/java/org/redisson/api/RGeo.java b/redisson/src/main/java/org/redisson/api/RGeo.java index e5427c488..2822a2a64 100644 --- a/redisson/src/main/java/org/redisson/api/RGeo.java +++ b/redisson/src/main/java/org/redisson/api/RGeo.java @@ -89,6 +89,53 @@ public interface RGeo extends RScoredSortedSet, RGeoAsync { */ List radius(double longitude, double latitude, double radius, GeoUnit geoUnit); + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return list of objects + */ + List radius(double longitude, double latitude, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - order of result + * @return list of objects + */ + List radius(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - order of result + * @param count - result limit + * @return list of objects + */ + List radius(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); + /** * Returns the distance mapped by member, distance between member and the location. * Members of a sorted set, which are within the @@ -104,6 +151,56 @@ public interface RGeo extends RScoredSortedSet, RGeoAsync { */ Map radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit); + /** + * Returns the distance mapped by member, distance between member and the location. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units and limited by count. + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return distance mapped by object + */ + Map radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the distance mapped by member, distance between member and the location. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - order of result + * @return distance mapped by object + */ + Map radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the distance mapped by member, distance between member and the location. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - order of result + * @param count - result limit + * @return distance mapped by object + */ + Map radiusWithDistance(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); + /** * Returns the geo-position mapped by member. * Members of a sorted set, which are within the @@ -119,6 +216,56 @@ public interface RGeo extends RScoredSortedSet, RGeoAsync { */ Map radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit); + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return geo position mapped by object + */ + Map radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @return geo position mapped by object + */ + Map radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @param count - result limit + * @return geo position mapped by object + */ + Map radiusWithPosition(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); + /** * Returns the members of a sorted set, which are within the * borders of the area specified with the defined member location @@ -132,6 +279,50 @@ public interface RGeo extends RScoredSortedSet, RGeoAsync { */ List radius(V member, double radius, GeoUnit geoUnit); + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return list of objects + */ + List radius(V member, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @return list of objects + */ + List radius(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @param count - result limit + * @return list of objects + */ + List radius(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); + /** * Returns the distance mapped by member, distance between member and the defined member location. * Members of a sorted set, which are within the @@ -146,6 +337,53 @@ public interface RGeo extends RScoredSortedSet, RGeoAsync { */ Map radiusWithDistance(V member, double radius, GeoUnit geoUnit); + /** + * Returns the distance mapped by member, distance between member and the defined member location. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return distance mapped by object + */ + Map radiusWithDistance(V member, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the distance mapped by member, distance between member and the defined member location. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @return distance mapped by object + */ + Map radiusWithDistance(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the distance mapped by member, distance between member and the defined member location. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @param count - result limit + * @return distance mapped by object + */ + Map radiusWithDistance(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); + /** * Returns the geo-position mapped by member. * Members of a sorted set, which are within the @@ -159,5 +397,52 @@ public interface RGeo extends RScoredSortedSet, RGeoAsync { * @return geo position mapped by object */ Map radiusWithPosition(V member, double radius, GeoUnit geoUnit); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return geo position mapped by object + */ + Map radiusWithPosition(V member, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @return geo position mapped by object + */ + Map radiusWithPosition(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @param count - result limit + * @return geo position mapped by object + */ + Map radiusWithPosition(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); } diff --git a/redisson/src/main/java/org/redisson/api/RGeoAsync.java b/redisson/src/main/java/org/redisson/api/RGeoAsync.java index f16c94cf7..bb94e0ce1 100644 --- a/redisson/src/main/java/org/redisson/api/RGeoAsync.java +++ b/redisson/src/main/java/org/redisson/api/RGeoAsync.java @@ -87,6 +87,53 @@ public interface RGeoAsync extends RScoredSortedSetAsync { * @return list of objects */ RFuture> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return list of objects + */ + RFuture> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - order of result + * @return list of objects + */ + RFuture> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - order of result + * @param count - result limit + * @return list of objects + */ + RFuture> radiusAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); /** * Returns the distance mapped by member, distance between member and the location. @@ -103,6 +150,56 @@ public interface RGeoAsync extends RScoredSortedSetAsync { */ RFuture> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit); + /** + * Returns the distance mapped by member, distance between member and the location. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units and limited by count. + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return distance mapped by object + */ + RFuture> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the distance mapped by member, distance between member and the location. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - order of result + * @return distance mapped by object + */ + RFuture> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the distance mapped by member, distance between member and the location. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - order of result + * @param count - result limit + * @return distance mapped by object + */ + RFuture> radiusWithDistanceAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); + /** * Returns the geo-position mapped by member. * Members of a sorted set, which are within the @@ -117,6 +214,56 @@ public interface RGeoAsync extends RScoredSortedSetAsync { * @return geo position mapped by object */ RFuture> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return geo position mapped by object + */ + RFuture> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @return geo position mapped by object + */ + RFuture> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the center location + * and the maximum distance from the center (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param longitude - longitude of object + * @param latitude - latitude of object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @param count - result limit + * @return geo position mapped by object + */ + RFuture> radiusWithPositionAsync(double longitude, double latitude, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); /** * Returns the members of a sorted set, which are within the @@ -130,6 +277,49 @@ public interface RGeoAsync extends RScoredSortedSetAsync { * @return list of objects */ RFuture> radiusAsync(V member, double radius, GeoUnit geoUnit); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return list of objects + */ + RFuture> radiusAsync(V member, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @return list of objects + */ + RFuture> radiusAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @param count - result limit + * @return list of objects + */ + RFuture> radiusAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); /** * Returns the distance mapped by member, distance between member and the defined member location. @@ -145,6 +335,52 @@ public interface RGeoAsync extends RScoredSortedSetAsync { */ RFuture> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit); + /** + * Returns the distance mapped by member, distance between member and the defined member location. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return distance mapped by object + */ + RFuture> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the distance mapped by member, distance between member and the defined member location. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo + * @return distance mapped by object + */ + RFuture> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the distance mapped by member, distance between member and the defined member location. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo + * @return distance mapped by object + */ + RFuture> radiusWithDistanceAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); + /** * Returns the geo-position mapped by member. * Members of a sorted set, which are within the @@ -158,5 +394,52 @@ public interface RGeoAsync extends RScoredSortedSetAsync { * @return geo position mapped by object */ RFuture> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param count - result limit + * @return geo position mapped by object + */ + RFuture> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit, int count); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @return geo position mapped by object + */ + RFuture> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder); + + /** + * Returns the geo-position mapped by member. + * Members of a sorted set, which are within the + * borders of the area specified with the defined member location + * and the maximum distance from the defined member location (the radius) + * in GeoUnit units with GeoOrder + * and limited by count + * + * @param member - object + * @param radius - radius in geo units + * @param geoUnit - geo unit + * @param geoOrder - geo order + * @param count - result limit + * @return geo position mapped by object + */ + RFuture> radiusWithPositionAsync(V member, double radius, GeoUnit geoUnit, GeoOrder geoOrder, int count); } diff --git a/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java b/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java index b9ca4ff80..4dbcf6c18 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/redisson/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -39,13 +39,10 @@ import org.redisson.client.protocol.convertor.TrueReplayConvertor; import org.redisson.client.protocol.convertor.TypeConvertor; import org.redisson.client.protocol.convertor.VoidReplayConvertor; import org.redisson.client.protocol.decoder.ClusterNodesDecoder; -import org.redisson.client.protocol.decoder.FlatNestedMultiDecoder; import org.redisson.client.protocol.decoder.KeyValueObjectDecoder; -import org.redisson.client.protocol.decoder.ListMultiDecoder; import org.redisson.client.protocol.decoder.ListResultReplayDecoder; import org.redisson.client.protocol.decoder.ListScanResult; import org.redisson.client.protocol.decoder.ListScanResultReplayDecoder; -import org.redisson.client.protocol.decoder.LongMultiDecoder; import org.redisson.client.protocol.decoder.MapScanResult; import org.redisson.client.protocol.decoder.MapScanResultReplayDecoder; import org.redisson.client.protocol.decoder.NestedMultiDecoder; diff --git a/redisson/src/main/java/org/redisson/client/protocol/decoder/GeoMapReplayDecoder.java b/redisson/src/main/java/org/redisson/client/protocol/decoder/GeoMapReplayDecoder.java index a405ad357..418643b29 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/decoder/GeoMapReplayDecoder.java +++ b/redisson/src/main/java/org/redisson/client/protocol/decoder/GeoMapReplayDecoder.java @@ -15,7 +15,7 @@ */ package org.redisson.client.protocol.decoder; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -32,7 +32,7 @@ public class GeoMapReplayDecoder implements MultiDecoder> { @Override public Map decode(List parts, State state) { - Map result = new HashMap(parts.size()); + Map result = new LinkedHashMap(parts.size()); for (Object object : parts) { List vals = ((List) object); result.put(vals.get(0), vals.get(1)); diff --git a/redisson/src/test/java/org/redisson/RedissonGeoTest.java b/redisson/src/test/java/org/redisson/RedissonGeoTest.java index 51cbcf4d9..42fef915d 100644 --- a/redisson/src/test/java/org/redisson/RedissonGeoTest.java +++ b/redisson/src/test/java/org/redisson/RedissonGeoTest.java @@ -1,16 +1,17 @@ package org.redisson; -import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; + import org.junit.Assume; import org.junit.BeforeClass; - import org.junit.Test; import org.redisson.api.GeoEntry; +import org.redisson.api.GeoOrder; import org.redisson.api.GeoPosition; import org.redisson.api.GeoUnit; import org.redisson.api.RGeo; @@ -101,6 +102,32 @@ public class RedissonGeoTest extends BaseTest { assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS)).containsExactly("Palermo", "Catania"); } + @Test + public void testRadiusCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS, 1)).containsExactly("Catania"); + } + + @Test + public void testRadiusOrder() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC)).containsExactly("Palermo", "Catania"); + assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC)).containsExactly("Catania", "Palermo"); + } + + @Test + public void testRadiusOrderCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1)).containsExactly("Palermo"); + assertThat(geo.radius(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1)).containsExactly("Catania"); + } + @Test public void testRadiusEmpty() { RGeo geo = redisson.getGeo("test"); @@ -118,7 +145,52 @@ public class RedissonGeoTest extends BaseTest { expected.put("Catania", 56.4413); assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS)).isEqualTo(expected); } + + @Test + public void testRadiusWithDistanceCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map expected = new HashMap(); + expected.put("Catania", 56.4413); + assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, 1)).isEqualTo(expected); + } + @Test + public void testRadiusWithDistanceOrder() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map descExpected = new LinkedHashMap(); + descExpected.put("Palermo", 190.4424); + descExpected.put("Catania", 56.4413); + assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC).entrySet()) + .containsExactlyElementsOf(descExpected.entrySet()); + + Map ascExpected = new LinkedHashMap(); + ascExpected.put("Catania", 56.4413); + ascExpected.put("Palermo", 190.4424); + assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC).entrySet()) + .containsExactlyElementsOf(ascExpected.entrySet()); + } + + @Test + public void testRadiusWithDistanceOrderCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map descExpected = new LinkedHashMap(); + descExpected.put("Palermo", 190.4424); + assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1).entrySet()) + .containsExactlyElementsOf(descExpected.entrySet()); + + Map ascExpected = new LinkedHashMap(); + ascExpected.put("Catania", 56.4413); + assertThat(geo.radiusWithDistance(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1).entrySet()) + .containsExactlyElementsOf(ascExpected.entrySet()); + } + + @Test public void testRadiusWithDistanceHugeAmount() { RGeo geo = redisson.getGeo("test"); @@ -191,6 +263,49 @@ public class RedissonGeoTest extends BaseTest { expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS)).isEqualTo(expected); } + + @Test + public void testRadiusWithPositionCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map expected = new HashMap(); + expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299)); + expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); + assertThat(expected.entrySet().removeAll(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS, 1).entrySet())).isTrue(); + assertThat(expected).hasSize(1); + } + + @Test + public void testRadiusWithPositionOrder() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map descExpected = new LinkedHashMap(); + descExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299)); + descExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); + assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC).entrySet()).containsExactlyElementsOf(descExpected.entrySet()); + + Map ascExpected = new LinkedHashMap(); + ascExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); + ascExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299)); + assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC).entrySet()).containsExactlyElementsOf(ascExpected.entrySet()); + } + + @Test + public void testRadiusWithPositionOrderCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map descExpected = new LinkedHashMap(); + descExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299)); + assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1).entrySet()).containsExactlyElementsOf(descExpected.entrySet()); + + Map ascExpected = new LinkedHashMap(); + ascExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); + assertThat(geo.radiusWithPosition(15, 37, 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1).entrySet()).containsExactlyElementsOf(ascExpected.entrySet()); + } + @Test public void testRadiusWithPositionEmpty() { @@ -207,6 +322,33 @@ public class RedissonGeoTest extends BaseTest { assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS)).containsExactly("Palermo", "Catania"); } + @Test + public void testRadiusMemberCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS, 1)).containsExactly("Palermo"); + } + + @Test + public void testRadiusMemberOrder() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC)).containsExactly("Catania", "Palermo"); + assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.ASC)).containsExactly("Palermo", "Catania"); + } + + @Test + public void testRadiusMemberOrderCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1)).containsExactly("Catania"); + assertThat(geo.radius("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1)).containsExactly("Palermo"); + } + + @Test public void testRadiusMemberEmpty() { RGeo geo = redisson.getGeo("test"); @@ -225,6 +367,48 @@ public class RedissonGeoTest extends BaseTest { assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS)).isEqualTo(expected); } + @Test + public void testRadiusMemberWithDistanceCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map expected = new HashMap(); + expected.put("Palermo", 0.0); + expected.put("Catania", 166.2742); + assertThat(expected.entrySet().removeAll(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS, 1).entrySet())).isTrue(); + assertThat(expected).hasSize(1); + } + + @Test + public void testRadiusMemberWithDistanceOrder() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map ascExpected = new LinkedHashMap(); + ascExpected.put("Palermo", 0.0); + ascExpected.put("Catania", 166.2742); + assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.ASC).entrySet()).containsExactlyElementsOf(ascExpected.entrySet()); + + Map descExpected = new LinkedHashMap(); + descExpected.put("Catania", 166.2742); + descExpected.put("Palermo", 0.0); + assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC).entrySet()).containsExactlyElementsOf(descExpected.entrySet()); + } + + @Test + public void testRadiusMemberWithDistanceOrderCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map ascExpected = new LinkedHashMap(); + ascExpected.put("Palermo", 0.0); + assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1).entrySet()).containsExactlyElementsOf(ascExpected.entrySet()); + + Map descExpected = new LinkedHashMap(); + descExpected.put("Catania", 166.2742); + assertThat(geo.radiusWithDistance("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1).entrySet()).containsExactlyElementsOf(descExpected.entrySet()); + } + @Test public void testRadiusMemberWithDistanceEmpty() { RGeo geo = redisson.getGeo("test"); @@ -242,6 +426,48 @@ public class RedissonGeoTest extends BaseTest { expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS)).isEqualTo(expected); } + + @Test + public void testRadiusMemberWithPositionCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map expected = new HashMap(); + expected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299)); + expected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); + assertThat(expected.entrySet().removeAll(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS, 1).entrySet())).isTrue(); + assertThat(expected).hasSize(1); + } + + @Test + public void testRadiusMemberWithPositionOrder() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map ascExpected = new LinkedHashMap(); + ascExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299)); + ascExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); + assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.ASC).entrySet()).containsExactlyElementsOf(ascExpected.entrySet()); + + Map descExpected = new LinkedHashMap(); + descExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); + descExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299)); + assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC).entrySet()).containsExactlyElementsOf(descExpected.entrySet()); + } + + @Test + public void testRadiusMemberWithPositionOrderCount() { + RGeo geo = redisson.getGeo("test"); + geo.add(new GeoEntry(13.361389, 38.115556, "Palermo"), new GeoEntry(15.087269, 37.502669, "Catania")); + + Map ascExpected = new LinkedHashMap(); + ascExpected.put("Palermo", new GeoPosition(13.361389338970184, 38.115556395496299)); + assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.ASC, 1).entrySet()).containsExactlyElementsOf(ascExpected.entrySet()); + + Map descExpected = new LinkedHashMap(); + descExpected.put("Catania", new GeoPosition(15.087267458438873, 37.50266842333162)); + assertThat(geo.radiusWithPosition("Palermo", 200, GeoUnit.KILOMETERS, GeoOrder.DESC, 1).entrySet()).containsExactlyElementsOf(descExpected.entrySet()); + } @Test public void testRadiusMemberWithPositionEmpty() {