Skip to content

Commit

Permalink
Adopt API change of lat/long to long/lat #86
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Jun 28, 2015
1 parent bd66695 commit 173ffbb
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 82 deletions.
21 changes: 11 additions & 10 deletions src/main/java/com/lambdaworks/redis/GeoArgs.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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() {
Expand All @@ -30,8 +31,8 @@ public GeoArgs withHash() {
return this;
}

public GeoArgs noProperties() {
noproperties = true;
public GeoArgs withCount(long count) {
this.count = count;
return this;
}

Expand Down Expand Up @@ -80,24 +81,24 @@ public enum Unit {

public <K, V> void build(CommandArgs<K, V> 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);
}

}
}
24 changes: 12 additions & 12 deletions src/main/java/com/lambdaworks/redis/RedisAsyncConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1601,24 +1601,24 @@ public RedisFuture<List<V>> zrangebylex(K key, String min, String max, long offs
}

@Override
public RedisFuture<Long> geoadd(K key, double latitude, double longitude, V member) {
return dispatch(commandBuilder.geoadd(key, latitude, longitude, member));
public RedisFuture<Long> geoadd(K key, double longitude, double latitude, V member) {
return dispatch(commandBuilder.geoadd(key, longitude, latitude, member));
}

@Override
public RedisFuture<Long> geoadd(K key, Object... latLongMember) {
return dispatch(commandBuilder.geoadd(key, latLongMember));
public RedisFuture<Long> geoadd(K key, Object... lngLatMember) {
return dispatch(commandBuilder.geoadd(key, lngLatMember));
}

@Override
public RedisFuture<Set<V>> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit) {
return dispatch(commandBuilder.georadius(key, latitude, longitude, distance, unit.name()));
public RedisFuture<Set<V>> 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<List<Object>> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit,
public RedisFuture<List<Object>> 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
Expand All @@ -1632,13 +1632,13 @@ public RedisFuture<List<Object>> georadiusbymember(K key, V member, double dista
}

@Override
public RedisFuture<List<Object>> geoencode(double latitude, double longitude) {
return dispatch(commandBuilder.geoencode(latitude, longitude, null, null));
public RedisFuture<List<Object>> geoencode(double longitude, double latitude) {
return dispatch(commandBuilder.geoencode(longitude, latitude, null, null));
}

@Override
public RedisFuture<List<Object>> geoencode(double latitude, double longitude, double distance, GeoArgs.Unit unit) {
return dispatch(commandBuilder.geoencode(latitude, longitude, distance, unit.name()));
public RedisFuture<List<Object>> geoencode(double longitude, double latitude, double distance, GeoArgs.Unit unit) {
return dispatch(commandBuilder.geoencode(longitude, latitude, distance, unit.name()));
}

@Override
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/com/lambdaworks/redis/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1720,40 +1720,40 @@ public Command<K, V, String> clusterReset(boolean hard) {
return createCommand(CLUSTER, new StatusOutput<K, V>(codec), args);
}

public Command<K, V, Long> geoadd(K key, double latitude, double longitude, V member) {
public Command<K, V, Long> geoadd(K key, double longitude, double latitude, V member) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(latitude).add(longitude).addValue(member);
return createCommand(GEOADD, new IntegerOutput<K, V>(codec), args);
}

public Command<K, V, Long> geoadd(K key, Object[] latLongMember) {
public Command<K, V, Long> 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<K, V> args = new CommandArgs<K, V>(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<K, V>(codec), args);
}

public Command<K, V, Set<V>> georadius(K key, double latitude, double longitude, double distance, String unit) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(latitude).add(longitude).add(distance).add(unit);
public Command<K, V, Set<V>> georadius(K key, double longitude, double latitude, double distance, String unit) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(longitude).add(latitude).add(distance).add(unit);
return createCommand(GEORADIUS, new ValueSetOutput<K, V>(codec), args);
}

public Command<K, V, List<Object>> georadius(K key, double latitude, double longitude, double distance, String unit,
public Command<K, V, List<Object>> georadius(K key, double longitude, double latitude, double distance, String unit,
GeoArgs geoArgs) {

CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(latitude).add(longitude).add(distance).add(unit);
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(longitude).add(latitude).add(distance).add(unit);

if (geoArgs != null) {
geoArgs.build(args);
Expand All @@ -1777,8 +1777,8 @@ public Command<K, V, List<Object>> georadiusbymember(K key, V member, double dis
return createCommand(GEORADIUSBYMEMBER, new NestedMultiOutput<K, V>(codec), args);
}

public Command<K, V, List<Object>> geoencode(double latitude, double longitude, Double distance, String unit) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(latitude).add(longitude);
public Command<K, V, List<Object>> geoencode(double longitude, double latitude, Double distance, String unit) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).add(longitude).add(latitude);

if (distance != null && unit != null) {
args.add(distance).add(unit);
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/lambdaworks/redis/RedisGeoAsyncConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,45 @@ public interface RedisGeoAsyncConnection<K, V> {
* 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<Long> geoadd(K key, double latitude, double longitude, V member);
RedisFuture<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
*/
RedisFuture<Long> geoadd(K key, Object... latLonMember);
RedisFuture<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
*/
RedisFuture<Set<V>> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit);
RedisFuture<Set<V>> 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<List<Object>> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit,
RedisFuture<List<Object>> georadius(K key, double longitude, double latitude, double distance, GeoArgs.Unit unit,
GeoArgs geoArgs);

/**
Expand Down Expand Up @@ -83,25 +83,25 @@ RedisFuture<List<Object>> 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<List<Object>> geoencode(double latitude, double longitude);
RedisFuture<List<Object>> 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<List<Object>> geoencode(double latitude, double longitude, double distance, GeoArgs.Unit unit);
RedisFuture<List<Object>> geoencode(double longitude, double latitude, double distance, GeoArgs.Unit unit);

/**
*
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/lambdaworks/redis/RedisGeoConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,45 @@ public interface RedisGeoConnection<K, V> {
* 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<V> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit);
Set<V> 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<Object> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit, GeoArgs geoArgs);
List<Object> 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}.
Expand All @@ -80,27 +80,27 @@ public interface RedisGeoConnection<K, V> {

/**
*
* 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<Object> geoencode(double latitude, double longitude);
List<Object> 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<Object> geoencode(double latitude, double longitude, double distance, GeoArgs.Unit unit);
List<Object> geoencode(double longitude, double latitude, double distance, GeoArgs.Unit unit);

/**
*
Expand Down
Loading

0 comments on commit 173ffbb

Please sign in to comment.