Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#2120) GeoRadius support store and storedist option with params #2157

Merged
merged 3 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -25,6 +25,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 @@ -1213,6 +1214,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 @@ -1232,6 +1239,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 @@ -3814,6 +3815,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 @@ -3846,6 +3855,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 @@ -1896,6 +1897,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 @@ -1940,6 +1953,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 @@ -14,6 +14,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 @@ -1120,6 +1121,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 @@ -1138,6 +1144,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 @@ -3619,6 +3620,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 @@ -3651,6 +3660,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 @@ -2017,6 +2018,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 @@ -2061,6 +2074,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