Skip to content

Commit

Permalink
GeoRadius support store and storedist option with params (#2157)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangbodong22011 authored Dec 6, 2020
1 parent 5cda372 commit 5525669
Show file tree
Hide file tree
Showing 16 changed files with 425 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.params.ClientKillParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.MigrateParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.ZAddParams;
Expand Down Expand Up @@ -1270,6 +1271,12 @@ public void georadius(final byte[] key, final double longitude, final double lat
toByteArray(radius), unit.raw));
}

public void georadiusStore(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit,
final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
sendCommand(GEORADIUS, param.getByteParams(key, toByteArray(longitude), toByteArray(latitude),
toByteArray(radius), unit.raw, storeParam.getOption(), storeParam.getKey()));
}

public void georadiusReadonly(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit,
final GeoRadiusParam param) {
sendCommand(GEORADIUS_RO, param.getByteParams(key, toByteArray(longitude), toByteArray(latitude),
Expand All @@ -1289,6 +1296,12 @@ public void georadiusByMember(final byte[] key, final byte[] member, final doubl
sendCommand(GEORADIUSBYMEMBER, param.getByteParams(key, member, toByteArray(radius), unit.raw));
}

public void georadiusByMemberStore(final byte[] key, final byte[] member, final double radius, final GeoUnit unit,
final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
sendCommand(GEORADIUSBYMEMBER, param.getByteParams(key, member, toByteArray(radius), unit.raw,
storeParam.getOption(), storeParam.getKey()));
}

public void georadiusByMemberReadonly(final byte[] key, final byte[] member, final double radius, final GeoUnit unit,
final GeoRadiusParam param) {
sendCommand(GEORADIUSBYMEMBER_RO, param.getByteParams(key, member, toByteArray(radius), unit.raw));
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import redis.clients.jedis.exceptions.JedisException;
import redis.clients.jedis.params.ClientKillParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.MigrateParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.ZAddParams;
Expand Down Expand Up @@ -4030,6 +4031,14 @@ public List<GeoRadiusResponse> georadius(final byte[] key, final double longitud
return BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT.build(client.getObjectMultiBulkReply());
}

@Override
public Long georadiusStore(final byte[] key, final double longitude, final double latitude,
final double radius, final GeoUnit unit, final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
checkIsInMultiOrPipeline();
client.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam);
return client.getIntegerReply();
}

@Override
public List<GeoRadiusResponse> georadiusReadonly(final byte[] key, final double longitude, final double latitude,
final double radius, final GeoUnit unit, final GeoRadiusParam param) {
Expand Down Expand Up @@ -4062,6 +4071,14 @@ public List<GeoRadiusResponse> georadiusByMember(final byte[] key, final byte[]
return BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT.build(client.getObjectMultiBulkReply());
}

@Override
public Long georadiusByMemberStore(final byte[] key, final byte[] member, final double radius,
final GeoUnit unit, final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
checkIsInMultiOrPipeline();
client.georadiusByMemberStore(key, member, radius, unit, param, storeParam);
return client.getIntegerReply();
}

@Override
public List<GeoRadiusResponse> georadiusByMemberReadonly(final byte[] key, final byte[] member, final double radius,
final GeoUnit unit, final GeoRadiusParam param) {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import redis.clients.jedis.commands.MultiKeyBinaryJedisClusterCommands;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.ZAddParams;
import redis.clients.jedis.params.ZIncrByParams;
Expand Down Expand Up @@ -1957,6 +1958,18 @@ public List<GeoRadiusResponse> execute(Jedis connection) {
}.runBinary(key);
}

@Override
public Long georadiusStore(final byte[] key, final double longitude, final double latitude, final double radius,
final GeoUnit unit, final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
byte[][] keys = storeParam.getByteKeys(key);
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
@Override
public Long execute(Jedis connection) {
return connection.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam);
}
}.runBinary(keys.length, keys);
}

@Override
public List<GeoRadiusResponse> georadiusReadonly(final byte[] key, final double longitude,
final double latitude, final double radius, final GeoUnit unit, final GeoRadiusParam param) {
Expand Down Expand Up @@ -2001,6 +2014,18 @@ public List<GeoRadiusResponse> execute(Jedis connection) {
}.runBinary(key);
}

@Override
public Long georadiusByMemberStore(final byte[] key, final byte[] member, final double radius, final GeoUnit unit,
final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
byte[][] keys = storeParam.getByteKeys(key);
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
@Override
public Long execute(Jedis connection) {
return connection.georadiusByMemberStore(key, member, radius, unit, param, storeParam);
}
}.runBinary(keys.length, keys);
}

@Override
public List<GeoRadiusResponse> georadiusByMemberReadonly(final byte[] key, final byte[] member,
final double radius, final GeoUnit unit, final GeoRadiusParam param) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/redis/clients/jedis/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import redis.clients.jedis.commands.Commands;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.MigrateParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.ZAddParams;
Expand Down Expand Up @@ -1162,6 +1163,11 @@ public void georadius(final String key, final double longitude, final double lat
georadius(SafeEncoder.encode(key), longitude, latitude, radius, unit, param);
}

public void georadiusStore(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit,
final GeoRadiusParam param, GeoRadiusStoreParam storeParam) {
georadiusStore(SafeEncoder.encode(key), longitude, latitude, radius, unit, param, storeParam);
}

public void georadiusReadonly(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit,
final GeoRadiusParam param) {
georadiusReadonly(SafeEncoder.encode(key), longitude, latitude, radius, unit, param);
Expand All @@ -1180,6 +1186,11 @@ public void georadiusByMember(final String key, final String member, final doubl
georadiusByMember(SafeEncoder.encode(key), SafeEncoder.encode(member), radius, unit, param);
}

public void georadiusByMemberStore(final String key, final String member, final double radius, final GeoUnit unit,
final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
georadiusByMemberStore(SafeEncoder.encode(key), SafeEncoder.encode(member), radius, unit, param, storeParam);
}

public void georadiusByMemberReadonly(final String key, final String member, final double radius, final GeoUnit unit,
final GeoRadiusParam param) {
georadiusByMemberReadonly(SafeEncoder.encode(key), SafeEncoder.encode(member), radius, unit, param);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import redis.clients.jedis.commands.ScriptingCommands;
import redis.clients.jedis.commands.SentinelCommands;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.MigrateParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.ZAddParams;
Expand Down Expand Up @@ -3689,6 +3690,14 @@ public List<GeoRadiusResponse> georadius(final String key, final double longitud
return BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT.build(client.getObjectMultiBulkReply());
}

@Override
public Long georadiusStore(final String key, double longitude, double latitude, double radius, GeoUnit unit,
GeoRadiusParam param, GeoRadiusStoreParam storeParam) {
checkIsInMultiOrPipeline();
client.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam);
return client.getIntegerReply();
}

@Override
public List<GeoRadiusResponse> georadiusReadonly(final String key, final double longitude, final double latitude,
final double radius, final GeoUnit unit, final GeoRadiusParam param) {
Expand Down Expand Up @@ -3721,6 +3730,14 @@ public List<GeoRadiusResponse> georadiusByMember(final String key, final String
return BuilderFactory.GEORADIUS_WITH_PARAMS_RESULT.build(client.getObjectMultiBulkReply());
}

@Override
public Long georadiusByMemberStore(final String key, String member, double radius, GeoUnit unit,
GeoRadiusParam param, GeoRadiusStoreParam storeParam) {
checkIsInMultiOrPipeline();
client.georadiusByMemberStore(key, member, radius, unit, param, storeParam);
return client.getIntegerReply();
}

@Override
public List<GeoRadiusResponse> georadiusByMemberReadonly(final String key, final String member, final double radius,
final GeoUnit unit, final GeoRadiusParam param) {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.ZAddParams;
import redis.clients.jedis.params.ZIncrByParams;
Expand Down Expand Up @@ -2115,6 +2116,18 @@ public List<GeoRadiusResponse> execute(Jedis connection) {
}.run(key);
}

@Override
public Long georadiusStore(final String key, final double longitude, final double latitude,
final double radius, final GeoUnit unit, final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
String[] keys = storeParam.getStringKeys(key);
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
@Override
public Long execute(Jedis connection) {
return connection.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam);
}
}.run(keys.length, keys);
}

@Override
public List<GeoRadiusResponse> georadiusReadonly(final String key, final double longitude,
final double latitude, final double radius, final GeoUnit unit, final GeoRadiusParam param) {
Expand Down Expand Up @@ -2159,6 +2172,18 @@ public List<GeoRadiusResponse> execute(Jedis connection) {
}.run(key);
}

@Override
public Long georadiusByMemberStore(final String key, final String member, final double radius, final GeoUnit unit,
final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
String[] keys = storeParam.getStringKeys(key);
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
@Override
public Long execute(Jedis connection) {
return connection.georadiusByMemberStore(key, member, radius, unit, param, storeParam);
}
}.run(keys.length, keys);
}

@Override
public List<GeoRadiusResponse> georadiusByMemberReadonly(final String key, final String member,
final double radius, final GeoUnit unit, final GeoRadiusParam param) {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package redis.clients.jedis;

import redis.clients.jedis.commands.*;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.MigrateParams;

import java.util.List;
Expand Down Expand Up @@ -719,4 +721,31 @@ public Response<Object> sendCommand(final ProtocolCommand cmd, final byte[]... a
return getResponse(BuilderFactory.OBJECT);
}

@Override
public Response<Long> georadiusStore(final String key, final double longitude, final double latitude,
final double radius, final GeoUnit unit, final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
client.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam);
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Long> georadiusStore(final byte[] key, final double longitude, final double latitude,
final double radius, final GeoUnit unit, final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
client.georadiusStore(key, longitude, latitude, radius, unit, param, storeParam);
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Long> georadiusByMemberStore(final byte[] key, final byte[] member,
final double radius, final GeoUnit unit, final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
client.georadiusByMemberStore(key, member, radius, unit, param, storeParam);
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Long> georadiusByMemberStore(final String key, final String member,
final double radius, final GeoUnit unit, final GeoRadiusParam param, final GeoRadiusStoreParam storeParam) {
client.georadiusByMemberStore(key, member, radius, unit, param, storeParam);
return getResponse(BuilderFactory.LONG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import redis.clients.jedis.BinaryJedisPubSub;
import redis.clients.jedis.BitOP;
import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -89,4 +92,10 @@ public interface MultiKeyBinaryCommands {
List<byte[]> xread(final int count, final long block, final Map<byte[], byte[]> streams);

List<byte[]> xreadGroup(byte[] groupname, byte[] consumer, int count, long block, boolean noAck, Map<byte[], byte[]> streams);

Long georadiusStore(byte[] key, double longitude, double latitude, double radius,
GeoUnit unit, GeoRadiusParam param, GeoRadiusStoreParam storeParam);

Long georadiusByMemberStore(byte[] key, byte[] member, double radius, GeoUnit unit,
GeoRadiusParam param, GeoRadiusStoreParam storeParam);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import redis.clients.jedis.BinaryJedisPubSub;
import redis.clients.jedis.BitOP;
import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -83,4 +86,10 @@ public interface MultiKeyBinaryJedisClusterCommands {
List<byte[]> xread(final int count, final long block, final Map<byte[], byte[]> streams);

List<byte[]> xreadGroup(byte[] groupname, byte[] consumer, int count, long block, boolean noAck, Map<byte[], byte[]> streams);

Long georadiusStore(byte[] key, double longitude, double latitude, double radius,
GeoUnit unit, GeoRadiusParam param, GeoRadiusStoreParam storeParam);

Long georadiusByMemberStore(byte[] key, byte[] member, double radius, GeoUnit unit,
GeoRadiusParam param, GeoRadiusStoreParam storeParam);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package redis.clients.jedis.commands;

import redis.clients.jedis.BitOP;
import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.Response;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.MigrateParams;

import java.util.List;
Expand Down Expand Up @@ -83,4 +86,10 @@ public interface MultiKeyBinaryRedisPipeline {
Response<Long> touch(byte[]... keys);

Response<String> migrate(String host, int port, int destinationDB, int timeout, MigrateParams params, byte[]... keys);

Response<Long> georadiusStore(byte[] key, double longitude, double latitude,
double radius, GeoUnit unit, GeoRadiusParam param, GeoRadiusStoreParam storeParam);

Response<Long> georadiusByMemberStore(byte[] key, byte[] member, double radius,
GeoUnit unit, GeoRadiusParam param, GeoRadiusStoreParam storeParam);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package redis.clients.jedis.commands;

import redis.clients.jedis.BitOP;
import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.StreamEntryID;
import redis.clients.jedis.JedisPubSub;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -190,4 +193,10 @@ public interface MultiKeyCommands {
* @return
*/
List<Map.Entry<String, List<StreamEntry>>> xreadGroup(String groupname, String consumer, int count, long block, final boolean noAck, Map.Entry<String, StreamEntryID>... streams);

Long georadiusStore(String key, double longitude, double latitude, double radius,
GeoUnit unit, GeoRadiusParam param, GeoRadiusStoreParam storeParam);

Long georadiusByMemberStore(String key, String member, double radius, GeoUnit unit,
GeoRadiusParam param, GeoRadiusStoreParam storeParam);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package redis.clients.jedis.commands;

import redis.clients.jedis.BitOP;
import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.Response;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.MigrateParams;

import java.util.List;
Expand Down Expand Up @@ -82,4 +85,10 @@ public interface MultiKeyCommandsPipeline {
Response<Long> touch(String... keys);

Response<String> migrate(String host, int port, int destinationDB, int timeout, MigrateParams params, String... keys);

Response<Long> georadiusStore(String key, double longitude, double latitude,
double radius, GeoUnit unit, GeoRadiusParam param, GeoRadiusStoreParam storeParam);

Response<Long> georadiusByMemberStore(String key, String member, double radius,
GeoUnit unit, GeoRadiusParam param, GeoRadiusStoreParam storeParam);
}
Loading

0 comments on commit 5525669

Please sign in to comment.