Skip to content

Commit

Permalink
Support GEOSEARCH and GEOSEARCHSTORE commands (#2771)
Browse files Browse the repository at this point in the history
* support geosearch and geosearchstore commands

* tests

* Format

* Format Protocol Keywords

* Support binary commands and pipeline

* Fix test

* format import in GeoSearchParam

* Pipeline

* Add the new tests in ...unified... package

* fix indent

* change func names

* format CommandObjects

* use camel case

* change func names

* use desc

* revert GeoRadiusParam changes

* stam

* Update src/main/java/redis/clients/jedis/params/GeoSearchParam.java

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>

* Update GeoSearchParam.java

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
  • Loading branch information
AvitalFineRedis and sazzad16 committed Dec 31, 2021
1 parent e122faa commit b150515
Show file tree
Hide file tree
Showing 14 changed files with 1,238 additions and 12 deletions.
129 changes: 129 additions & 0 deletions src/main/java/redis/clients/jedis/CommandObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,135 @@ public final CommandObject<Long> georadiusByMemberStore(byte[] key, byte[] membe
return new CommandObject<>(commandArguments(GEORADIUSBYMEMBER).key(key).add(member)
.add(radius).add(unit).addParams(param).addParams(storeParam), BuilderFactory.LONG);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(String key, String member,
double radius, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key).add(FROMMEMBER).add(member)
.add(BYRADIUS).add(radius).add(unit), BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(String key, GeoCoordinate coord,
double radius, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key)
.add(FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude())
.add(BYRADIUS).add(radius).add(unit), BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(String key, String member,
double width, double height, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key).add(FROMMEMBER).add(member)
.add(BYBOX).add(width).add(height).add(unit), BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(String key, GeoCoordinate coord,
double width, double height, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key)
.add(FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude())
.add(BYBOX).add(width).add(height).add(unit), BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(String key, GeoSearchParam params) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key).addParams(params),
BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<Long> geosearchStore(String dest, String src, String member,
double radius, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).add(FROMMEMBER).add(member)
.add(BYRADIUS).add(radius).add(unit), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStore(String dest, String src, GeoCoordinate coord,
double radius, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).add(FROMLONLAT).add(coord.getLongitude())
.add(coord.getLatitude()).add(BYRADIUS).add(radius).add(unit), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStore(String dest, String src, String member,
double width, double height, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).add(FROMMEMBER).add(member)
.add(BYBOX).add(width).add(height).add(unit), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStore(String dest, String src, GeoCoordinate coord,
double width, double height, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src)
.add(FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude())
.add(BYBOX).add(width).add(height).add(unit), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStore(String dest, String src, GeoSearchParam params) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).addParams(params), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStoreStoreDist(String dest, String src, GeoSearchParam params) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).addParams(params).add(STOREDIST), BuilderFactory.LONG);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(byte[] key, byte[] member,
double radius, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key).add(FROMMEMBER).add(member)
.add(BYRADIUS).add(radius).add(unit), BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(byte[] key, GeoCoordinate coord,
double radius, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key)
.add(FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude())
.add(BYRADIUS).add(radius).add(unit), BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(byte[] key, byte[] member,
double width, double height, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key).add(FROMMEMBER).add(member)
.add(BYBOX).add(width).add(height).add(unit), BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(byte[] key, GeoCoordinate coord,
double width, double height, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key)
.add(FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude())
.add(BYBOX).add(width).add(height).add(unit), BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<List<GeoRadiusResponse>> geosearch(byte[] key, GeoSearchParam params) {
return new CommandObject<>(commandArguments(GEOSEARCH).key(key).addParams(params),
BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT);
}

public final CommandObject<Long> geosearchStore(byte[] dest, byte[] src, byte[] member,
double radius, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).add(FROMMEMBER).add(member)
.add(BYRADIUS).add(radius).add(unit), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStore(byte[] dest, byte[] src, GeoCoordinate coord,
double radius, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src)
.add(FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude())
.add(BYRADIUS).add(radius).add(unit), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStore(byte[] dest, byte[] src, byte[] member,
double width, double height, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).add(FROMMEMBER).add(member)
.add(BYBOX).add(width).add(height).add(unit), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStore(byte[] dest, byte[] src, GeoCoordinate coord,
double width, double height, GeoUnit unit) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src)
.add(FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude())
.add(BYBOX).add(width).add(height).add(unit), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStore(byte[] dest, byte[] src, GeoSearchParam params) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).addParams(params), BuilderFactory.LONG);
}

public final CommandObject<Long> geosearchStoreStoreDist(byte[] dest, byte[] src, GeoSearchParam params) {
return new CommandObject<>(commandArguments(GEOSEARCHSTORE).key(dest).add(src).addParams(params).add(STOREDIST), BuilderFactory.LONG);
}
// Geo commands

// Hyper Log Log commands
Expand Down
132 changes: 132 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -4291,6 +4291,72 @@ public long georadiusByMemberStore(final byte[] key, final byte[] member, final
return connection.executeCommand(commandObjects.georadiusByMemberStore(key, member, radius, unit, param, storeParam));
}

@Override
public List<GeoRadiusResponse> geosearch(byte[] key, byte[] member, double radius, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, member, radius, unit));
}

@Override
public List<GeoRadiusResponse> geosearch(byte[] key, GeoCoordinate coord, double radius, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, coord, radius, unit));
}

@Override
public List<GeoRadiusResponse> geosearch(byte[] key, byte[] member, double width, double height, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, member, width, height, unit));
}

@Override
public List<GeoRadiusResponse> geosearch(byte[] key, GeoCoordinate coord, double width, double height, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, coord, width, height, unit));
}

@Override
public List<GeoRadiusResponse> geosearch(byte[] key, GeoSearchParam params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, params));
}

@Override
public long geosearchStore(byte[] dest, byte[] src, byte[] member, double radius, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, member, radius, unit));
}

@Override
public long geosearchStore(byte[] dest, byte[] src, GeoCoordinate coord, double radius, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, coord, radius, unit));
}

@Override
public long geosearchStore(byte[] dest, byte[] src, byte[] member, double width, double height, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, member, width, height, unit));
}

@Override
public long geosearchStore(byte[] dest, byte[] src, GeoCoordinate coord, double width, double height, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, coord, width, height, unit));
}

@Override
public long geosearchStore(byte[] dest, byte[] src, GeoSearchParam params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, params));
}

@Override
public long geosearchStoreStoreDist(byte[] dest, byte[] src, GeoSearchParam params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStoreStoreDist(dest, src, params));
}

@Override
public List<GeoRadiusResponse> georadiusByMemberReadonly(final byte[] key, final byte[] member,
final double radius, final GeoUnit unit, final GeoRadiusParam param) {
Expand Down Expand Up @@ -8282,6 +8348,72 @@ public List<GeoRadiusResponse> georadiusByMemberReadonly(final String key, final
return connection.executeCommand(commandObjects.georadiusByMemberReadonly(key, member, radius, unit, param));
}

@Override
public List<GeoRadiusResponse> geosearch(String key, String member, double radius, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, member, radius, unit));
}

@Override
public List<GeoRadiusResponse> geosearch(String key, GeoCoordinate coord, double radius, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, coord, radius, unit));
}

@Override
public List<GeoRadiusResponse> geosearch(String key, String member, double width, double height, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, member, width, height, unit));
}

@Override
public List<GeoRadiusResponse> geosearch(String key, GeoCoordinate coord, double width, double height, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, coord, width, height, unit));
}

@Override
public List<GeoRadiusResponse> geosearch(String key, GeoSearchParam params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearch(key, params));
}

@Override
public long geosearchStore(String dest, String src, String member, double radius, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, member, radius, unit));
}

@Override
public long geosearchStore(String dest, String src, GeoCoordinate coord, double radius, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, coord, radius, unit));
}

@Override
public long geosearchStore(String dest, String src, String member, double width, double height, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, member, width, height, unit));
}

@Override
public long geosearchStore(String dest, String src, GeoCoordinate coord, double width, double height, GeoUnit unit) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, coord, width, height, unit));
}

@Override
public long geosearchStore(String dest, String src, GeoSearchParam params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStore(dest, src, params));
}

@Override
public long geosearchStoreStoreDist(String dest, String src, GeoSearchParam params) {
checkIsInMultiOrPipeline();
return connection.executeCommand(commandObjects.geosearchStoreStoreDist(dest, src, params));
}

@Override
public String moduleLoad(final String path) {
checkIsInMultiOrPipeline();
Expand Down

0 comments on commit b150515

Please sign in to comment.