From 173ffbb8b7ae405aeec6edd40c72fa391681c572 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Sun, 28 Jun 2015 13:53:23 +0200 Subject: [PATCH] Adopt API change of lat/long to long/lat #86 --- .../java/com/lambdaworks/redis/GeoArgs.java | 21 ++++++------ .../redis/RedisAsyncConnectionImpl.java | 24 ++++++------- .../redis/RedisCommandBuilder.java | 34 +++++++++---------- .../redis/RedisGeoAsyncConnection.java | 30 ++++++++-------- .../lambdaworks/redis/RedisGeoConnection.java | 30 ++++++++-------- .../com/lambdaworks/redis/GeoCommandTest.java | 24 ++++++------- 6 files changed, 81 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/lambdaworks/redis/GeoArgs.java b/src/main/java/com/lambdaworks/redis/GeoArgs.java index e510b65b0c..19e2f0c10b 100644 --- a/src/main/java/com/lambdaworks/redis/GeoArgs.java +++ b/src/main/java/com/lambdaworks/redis/GeoArgs.java @@ -1,6 +1,7 @@ package com.lambdaworks.redis; import com.lambdaworks.redis.protocol.CommandArgs; +import com.lambdaworks.redis.protocol.CommandKeyword; /** * Args for {@literal GEORADIUS} and {@literal GEORADIUSBYMEMBER} commands. @@ -12,7 +13,7 @@ public class GeoArgs { private boolean withdistance; private boolean withcoordinates; private boolean withhash; - private boolean noproperties; + private Long count; private Sort sort = Sort.none; public GeoArgs withDistance() { @@ -30,8 +31,8 @@ public GeoArgs withHash() { return this; } - public GeoArgs noProperties() { - noproperties = true; + public GeoArgs withCount(long count) { + this.count = count; return this; } @@ -80,24 +81,24 @@ public enum Unit { public void build(CommandArgs args) { if (withdistance) { - args.add("withdistance"); - } - - if (withcoordinates) { - args.add("withcoordinates"); + args.add("withdist"); } if (withhash) { args.add("withhash"); } - if (noproperties) { - args.add("noproperties"); + if (withcoordinates) { + args.add("withcoord"); } if (sort != null && sort != Sort.none) { args.add(sort.name()); } + if (count != null) { + args.add(CommandKeyword.COUNT).add(count); + } + } } diff --git a/src/main/java/com/lambdaworks/redis/RedisAsyncConnectionImpl.java b/src/main/java/com/lambdaworks/redis/RedisAsyncConnectionImpl.java index 6776a6e292..aa48a4a54c 100644 --- a/src/main/java/com/lambdaworks/redis/RedisAsyncConnectionImpl.java +++ b/src/main/java/com/lambdaworks/redis/RedisAsyncConnectionImpl.java @@ -1601,24 +1601,24 @@ public RedisFuture> zrangebylex(K key, String min, String max, long offs } @Override - public RedisFuture geoadd(K key, double latitude, double longitude, V member) { - return dispatch(commandBuilder.geoadd(key, latitude, longitude, member)); + public RedisFuture geoadd(K key, double longitude, double latitude, V member) { + return dispatch(commandBuilder.geoadd(key, longitude, latitude, member)); } @Override - public RedisFuture geoadd(K key, Object... latLongMember) { - return dispatch(commandBuilder.geoadd(key, latLongMember)); + public RedisFuture geoadd(K key, Object... lngLatMember) { + return dispatch(commandBuilder.geoadd(key, lngLatMember)); } @Override - public RedisFuture> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit) { - return dispatch(commandBuilder.georadius(key, latitude, longitude, distance, unit.name())); + public RedisFuture> georadius(K key, double longitude, double latitude, double distance, GeoArgs.Unit unit) { + return dispatch(commandBuilder.georadius(key, longitude, latitude, distance, unit.name())); } @Override - public RedisFuture> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit, + public RedisFuture> georadius(K key, double longitude, double latitude, double distance, GeoArgs.Unit unit, GeoArgs geoArgs) { - return dispatch(commandBuilder.georadius(key, latitude, longitude, distance, unit.name(), geoArgs)); + return dispatch(commandBuilder.georadius(key, longitude, latitude, distance, unit.name(), geoArgs)); } @Override @@ -1632,13 +1632,13 @@ public RedisFuture> georadiusbymember(K key, V member, double dista } @Override - public RedisFuture> geoencode(double latitude, double longitude) { - return dispatch(commandBuilder.geoencode(latitude, longitude, null, null)); + public RedisFuture> geoencode(double longitude, double latitude) { + return dispatch(commandBuilder.geoencode(longitude, latitude, null, null)); } @Override - public RedisFuture> geoencode(double latitude, double longitude, double distance, GeoArgs.Unit unit) { - return dispatch(commandBuilder.geoencode(latitude, longitude, distance, unit.name())); + public RedisFuture> geoencode(double longitude, double latitude, double distance, GeoArgs.Unit unit) { + return dispatch(commandBuilder.geoencode(longitude, latitude, distance, unit.name())); } @Override diff --git a/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java b/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java index 87140772e1..93dc31e751 100644 --- a/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java +++ b/src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java @@ -1720,40 +1720,40 @@ public Command clusterReset(boolean hard) { return createCommand(CLUSTER, new StatusOutput(codec), args); } - public Command geoadd(K key, double latitude, double longitude, V member) { + public Command geoadd(K key, double longitude, double latitude, V member) { CommandArgs args = new CommandArgs(codec).addKey(key).add(latitude).add(longitude).addValue(member); return createCommand(GEOADD, new IntegerOutput(codec), args); } - public Command geoadd(K key, Object[] latLongMember) { + public Command geoadd(K key, Object[] lngLatMember) { - assertNotEmpty(latLongMember, "latLongMember " + MUST_NOT_BE_EMPTY); - assertNoNullElements(latLongMember, "latLongMember " + MUST_NOT_CONTAIN_NULL_ELEMENTS); + assertNotEmpty(lngLatMember, "lngLatMember " + MUST_NOT_BE_EMPTY); + assertNoNullElements(lngLatMember, "lngLatMember " + MUST_NOT_CONTAIN_NULL_ELEMENTS); assertTrue( - latLongMember.length % 3 == 0, - "latLongMember.length must be a multiple of 3 and contain a " - + "sequence of latitude1, longitude1, member1, latitude2, longitude2, member2, ... latitudeN, longitudeN, memberN"); + lngLatMember.length % 3 == 0, + "lngLatMember.length must be a multiple of 3 and contain a " + + "sequence of longitude1, latitude1, member1, longitude2, latitude2, member2, ... longitudeN, latitudeN, memberN"); CommandArgs args = new CommandArgs(codec).addKey(key); - for (int i = 0; i < latLongMember.length; i += 3) { - args.add((Double) latLongMember[i]); - args.add((Double) latLongMember[i + 1]); - args.addValue((V) latLongMember[i + 2]); + for (int i = 0; i < lngLatMember.length; i += 3) { + args.add((Double) lngLatMember[i]); + args.add((Double) lngLatMember[i + 1]); + args.addValue((V) lngLatMember[i + 2]); } return createCommand(GEOADD, new IntegerOutput(codec), args); } - public Command> georadius(K key, double latitude, double longitude, double distance, String unit) { - CommandArgs args = new CommandArgs(codec).addKey(key).add(latitude).add(longitude).add(distance).add(unit); + public Command> georadius(K key, double longitude, double latitude, double distance, String unit) { + CommandArgs args = new CommandArgs(codec).addKey(key).add(longitude).add(latitude).add(distance).add(unit); return createCommand(GEORADIUS, new ValueSetOutput(codec), args); } - public Command> georadius(K key, double latitude, double longitude, double distance, String unit, + public Command> georadius(K key, double longitude, double latitude, double distance, String unit, GeoArgs geoArgs) { - CommandArgs args = new CommandArgs(codec).addKey(key).add(latitude).add(longitude).add(distance).add(unit); + CommandArgs args = new CommandArgs(codec).addKey(key).add(longitude).add(latitude).add(distance).add(unit); if (geoArgs != null) { geoArgs.build(args); @@ -1777,8 +1777,8 @@ public Command> georadiusbymember(K key, V member, double dis return createCommand(GEORADIUSBYMEMBER, new NestedMultiOutput(codec), args); } - public Command> geoencode(double latitude, double longitude, Double distance, String unit) { - CommandArgs args = new CommandArgs(codec).add(latitude).add(longitude); + public Command> geoencode(double longitude, double latitude, Double distance, String unit) { + CommandArgs args = new CommandArgs(codec).add(longitude).add(latitude); if (distance != null && unit != null) { args.add(distance).add(unit); diff --git a/src/main/java/com/lambdaworks/redis/RedisGeoAsyncConnection.java b/src/main/java/com/lambdaworks/redis/RedisGeoAsyncConnection.java index e383452b23..f29eaadbb0 100644 --- a/src/main/java/com/lambdaworks/redis/RedisGeoAsyncConnection.java +++ b/src/main/java/com/lambdaworks/redis/RedisGeoAsyncConnection.java @@ -15,45 +15,45 @@ public interface RedisGeoAsyncConnection { * Single geo add. * * @param key - * @param latitude * @param longitude + * @param latitude * @param member * @return Long integer-reply the number of elements that were added to the set */ - RedisFuture geoadd(K key, double latitude, double longitude, V member); + RedisFuture geoadd(K key, double longitude, double latitude, V member); /** * Multi geo add * * @param key - * @param latLonMember triplets of double latitude, double longitude and V member + * @param lngLatMember triplets of double longitude, double latitude and V member * @return Long integer-reply the number of elements that were added to the set */ - RedisFuture geoadd(K key, Object... latLonMember); + RedisFuture geoadd(K key, Object... lngLatMember); /** - * Retrieve members selected by distance with the center of {@code latitude} and {@code longitude}. + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. * * @param key - * @param latitude * @param longitude + * @param latitude * @param distance * @param unit * @return bulk reply */ - RedisFuture> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit); + RedisFuture> georadius(K key, double longitude, double latitude, double distance, GeoArgs.Unit unit); /** - * Retrieve members selected by distance with the center of {@code latitude} and {@code longitude}. + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. * * @param key - * @param latitude * @param longitude + * @param latitude * @param distance * @param unit * @return nested multi-bulk reply */ - RedisFuture> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit, + RedisFuture> georadius(K key, double longitude, double latitude, double distance, GeoArgs.Unit unit, GeoArgs geoArgs); /** @@ -83,25 +83,25 @@ RedisFuture> georadius(K key, double latitude, double longitude, do * * Encode latitude and longitude to highest geohash accuracy. * - * @param latitude * @param longitude + * @param latitude * @return nested multi-bulk reply with 1: the 52-bit geohash integer for your latitude longitude, 2: The minimum corner of * your geohash, 3: The maximum corner of your geohash, 4: The averaged center of your geohash. */ - RedisFuture> geoencode(double latitude, double longitude); + RedisFuture> geoencode(double longitude, double latitude); /** * - * Encode latitude and longitude to highest geohash accuracy. + * Encode {@code longitude} and {@code latitude} to highest geohash accuracy. * - * @param latitude * @param longitude + * @param latitude * @param distance * @param unit * @return nested multi-bulk reply with 1: the 52-bit geohash integer for your latitude longitude, 2: The minimum corner of * your geohash, 3: The maximum corner of your geohash, 4: The averaged center of your geohash. */ - RedisFuture> geoencode(double latitude, double longitude, double distance, GeoArgs.Unit unit); + RedisFuture> geoencode(double longitude, double latitude, double distance, GeoArgs.Unit unit); /** * diff --git a/src/main/java/com/lambdaworks/redis/RedisGeoConnection.java b/src/main/java/com/lambdaworks/redis/RedisGeoConnection.java index f2b7a621e1..8ad9701932 100644 --- a/src/main/java/com/lambdaworks/redis/RedisGeoConnection.java +++ b/src/main/java/com/lambdaworks/redis/RedisGeoConnection.java @@ -15,45 +15,45 @@ public interface RedisGeoConnection { * Single geo add. * * @param key - * @param latitude * @param longitude + * @param latitude * @param member * @return Long integer-reply the number of elements that were added to the set */ - Long geoadd(K key, double latitude, double longitude, V member); + Long geoadd(K key, double longitude, double latitude, V member); /** * Multi geo add. * * @param key - * @param latLonMember triplets of double latitude, double longitude and V member + * @param lngLatMember triplets of double longitude, double latitude and V member * @return Long integer-reply the number of elements that were added to the set */ - Long geoadd(K key, Object... latLonMember); + Long geoadd(K key, Object... lngLatMember); /** - * Retrieve members selected by distance with the center of {@code latitude} and {@code longitude}. + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. * * @param key - * @param latitude * @param longitude + * @param latitude * @param distance * @param unit * @return bulk reply */ - Set georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit); + Set georadius(K key, double longitude, double latitude, double distance, GeoArgs.Unit unit); /** - * Retrieve members selected by distance with the center of {@code latitude} and {@code longitude}. + * Retrieve members selected by distance with the center of {@code longitude} and {@code latitude}. * * @param key - * @param latitude * @param longitude + * @param latitude * @param distance * @param unit * @return nested multi-bulk reply */ - List georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit, GeoArgs geoArgs); + List georadius(K key, double longitude, double latitude, double distance, GeoArgs.Unit unit, GeoArgs geoArgs); /** * Retrieve members selected by distance with the center of {@code member}. @@ -80,27 +80,27 @@ public interface RedisGeoConnection { /** * - * Encode latitude and longitude to highest geohash accuracy. + * Encode {@code longitude} and {@code latitude} to highest geohash accuracy. * - * @param latitude * @param longitude + * @param latitude * @return nested multi-bulk reply with 1: the 52-bit geohash integer for your latitude longitude, 2: The minimum corner of * your geohash, 3: The maximum corner of your geohash, 4: The averaged center of your geohash. */ - List geoencode(double latitude, double longitude); + List geoencode(double longitude, double latitude); /** * * Encode latitude and longitude to highest geohash accuracy. * - * @param latitude * @param longitude + * @param latitude * @param distance * @param unit * @return nested multi-bulk reply with 1: the 52-bit geohash integer for your latitude longitude, 2: The minimum corner of * your geohash, 3: The maximum corner of your geohash, 4: The averaged center of your geohash. */ - List geoencode(double latitude, double longitude, double distance, GeoArgs.Unit unit); + List geoencode(double longitude, double latitude, double distance, GeoArgs.Unit unit); /** * diff --git a/src/test/java/com/lambdaworks/redis/GeoCommandTest.java b/src/test/java/com/lambdaworks/redis/GeoCommandTest.java index 7ff9ec5eb4..1f6ba45fe9 100644 --- a/src/test/java/com/lambdaworks/redis/GeoCommandTest.java +++ b/src/test/java/com/lambdaworks/redis/GeoCommandTest.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Set; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -18,19 +17,18 @@ public class GeoCommandTest extends AbstractCommandTest { @Test public void geoadd() throws Exception { - Long result = redis.geoadd(key, 40.747533, -73.9454966, "lic market"); + Long result = redis.geoadd(key, -73.9454966, 40.747533, "lic market"); assertThat(result).isEqualTo(1); - Long readd = redis.geoadd(key, 40.747533, -73.9454966, "lic market"); + Long readd = redis.geoadd(key, -73.9454966, 40.747533, "lic market"); assertThat(readd).isEqualTo(0); } @Test public void geoaddMulti() throws Exception { - Long result = redis.geoadd(key, 49.5282537, 8.6638775, "Weinheim", 48.9978127, 8.3796281, "EFS9", 49.553302, 8.665351, + Long result = redis.geoadd(key, 8.6638775, 49.5282537, "Weinheim", 8.3796281, 48.9978127, "EFS9", 8.665351, 49.553302, "Bahn"); - assertThat(result).isEqualTo(3); } @@ -40,7 +38,7 @@ public void geoaddMultiWrongArgument() throws Exception { } protected void prepareGeo() { - redis.geoadd(key, 49.5282537, 8.6638775, "Weinheim", 48.9978127, 8.3796281, "EFS9", 49.553302, 8.665351, "Bahn"); + redis.geoadd(key, 8.6638775, 49.5282537, "Weinheim", 8.3796281, 48.9978127, "EFS9", 8.665351, 49.553302, "Bahn"); } @Test @@ -48,10 +46,10 @@ public void georadius() throws Exception { prepareGeo(); - Set georadius = redis.georadius(key, 49.5285695, 8.6582861, 1, GeoArgs.Unit.kilometer); + Set georadius = redis.georadius(key, 8.6582861, 49.5285695, 1, GeoArgs.Unit.kilometer); assertThat(georadius).hasSize(1).contains("Weinheim"); - Set largerGeoradius = redis.georadius(key, 49.5285695, 8.6582861, 5, GeoArgs.Unit.kilometer); + Set largerGeoradius = redis.georadius(key, 8.6582861, 49.5285695, 5, GeoArgs.Unit.kilometer); assertThat(largerGeoradius).hasSize(2).contains("Weinheim").contains("Bahn"); } @@ -61,15 +59,15 @@ public void georadiusWithArgs() throws Exception { prepareGeo(); - GeoArgs geoArgs = new GeoArgs().withHash().withCoordinates().withDistance().noProperties().asc(); + GeoArgs geoArgs = new GeoArgs().withHash().withCoordinates().withDistance().withCount(1).asc(); - List result = redis.georadius(key, 49.5285695, 8.6582861, 1, GeoArgs.Unit.kilometer, geoArgs); + List result = redis.georadius(key, 8.6582861, 49.5285695, 1, GeoArgs.Unit.kilometer, geoArgs); assertThat(result).hasSize(1); List response = (List) result.get(0); assertThat(response).hasSize(4); - result = redis.georadius(key, 49.5285695, 8.6582861, 1, GeoArgs.Unit.kilometer, null); + result = redis.georadius(key, 8.6582861, 49.5285695, 1, GeoArgs.Unit.kilometer, null); assertThat(result).hasSize(1); } @@ -105,7 +103,7 @@ public void georadiusbymemberWithArgs() throws Exception { @Test public void geoencode() throws Exception { - List geoencode = redis.geoencode(49.5282537, 8.6638775); + List geoencode = redis.geoencode(8.6638775, 49.5282537); assertThat(geoencode).hasSize(4); assertThat(geoencode.get(0)).isEqualTo(3666615932941099L); @@ -118,7 +116,7 @@ public void geoencode() throws Exception { @Test public void geoencodeWithDistance() throws Exception { - List result = redis.geoencode(49.5282537, 8.6638775, 1, GeoArgs.Unit.kilometer); + List result = redis.geoencode(8.6638775, 49.5282537, 1, GeoArgs.Unit.kilometer); assertThat(result).hasSize(4); assertThat(result.get(0)).isEqualTo(3666615929405440L);