Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.params.ClientKillParams;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.GetExParams;
Expand Down Expand Up @@ -1312,14 +1313,17 @@ public void geoadd(final byte[] key, final double longitude, final double latitu
}

public void geoadd(final byte[] key, final Map<byte[], GeoCoordinate> memberCoordinateMap) {
List<byte[]> args = new ArrayList<>(memberCoordinateMap.size() * 3 + 1);
args.add(key);
geoadd(key, GeoAddParams.geoAddParams(), memberCoordinateMap);
}

public void geoadd(final byte[] key, final GeoAddParams params, final Map<byte[], GeoCoordinate> memberCoordinateMap) {
List<byte[]> args = new ArrayList<>(memberCoordinateMap.size() * 3);
args.addAll(convertGeoCoordinateMapToByteArrays(memberCoordinateMap));

byte[][] argsArray = new byte[args.size()][];
args.toArray(argsArray);

sendCommand(GEOADD, argsArray);
sendCommand(GEOADD, params.getByteParams(key, argsArray));
}

public void geodist(final byte[] key, final byte[] member1, final byte[] member2) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisException;
import redis.clients.jedis.params.ClientKillParams;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.GetExParams;
Expand Down Expand Up @@ -4170,6 +4171,13 @@ public Long geoadd(final byte[] key, final Map<byte[], GeoCoordinate> memberCoor
return client.getIntegerReply();
}

@Override
public Long geoadd(final byte[] key, final GeoAddParams params, final Map<byte[], GeoCoordinate> memberCoordinateMap) {
checkIsInMultiOrPipeline();
client.geoadd(key, params, memberCoordinateMap);
return client.getIntegerReply();
}

@Override
public Double geodist(final byte[] key, final byte[] member1, final byte[] member2) {
checkIsInMultiOrPipeline();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import redis.clients.jedis.commands.JedisClusterBinaryScriptingCommands;
import redis.clients.jedis.commands.MultiKeyBinaryJedisClusterCommands;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.GetExParams;
Expand Down Expand Up @@ -1988,6 +1989,16 @@ public Long execute(Jedis connection) {
}.runBinary(key);
}

@Override
public Long geoadd(byte[] key, GeoAddParams params, Map<byte[], GeoCoordinate> memberCoordinateMap) {
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
@Override
public Long execute(Jedis connection) {
return connection.geoadd(key, params, memberCoordinateMap);
}
}.runBinary(key);
}

@Override
public Double geodist(final byte[] key, final byte[] member1, final byte[] member2) {
return new JedisClusterCommand<Double>(connectionHandler, maxAttempts) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import redis.clients.jedis.commands.BinaryJedisCommands;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -946,6 +947,12 @@ public Long geoadd(final byte[] key, final Map<byte[], GeoCoordinate> memberCoor
return j.geoadd(key, memberCoordinateMap);
}

@Override
public Long geoadd(byte[] key, GeoAddParams params, Map<byte[], GeoCoordinate> memberCoordinateMap) {
Jedis j = getShard(key);
return j.geoadd(key, params, memberCoordinateMap);
}

@Override
public Double geodist(final byte[] key, final byte[] member1, final byte[] member2) {
Jedis j = getShard(key);
Expand Down
5 changes: 5 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 javax.net.ssl.SSLSocketFactory;

import redis.clients.jedis.commands.Commands;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.GetExParams;
Expand Down Expand Up @@ -1181,6 +1182,10 @@ public void geoadd(final String key, final Map<String, GeoCoordinate> memberCoor
geoadd(SafeEncoder.encode(key), convertMemberCoordinateMapToBinary(memberCoordinateMap));
}

public void geoadd(final String key, final GeoAddParams params, final Map<String, GeoCoordinate> memberCoordinateMap) {
geoadd(SafeEncoder.encode(key), params, convertMemberCoordinateMapToBinary(memberCoordinateMap));
}

public void geodist(final String key, final String member1, final String member2) {
geodist(SafeEncoder.encode(key), SafeEncoder.encode(member1), SafeEncoder.encode(member2));
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.commands.ScriptingCommands;
import redis.clients.jedis.commands.SentinelCommands;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.GetExParams;
Expand Down Expand Up @@ -3709,6 +3710,13 @@ public Long geoadd(final String key, final Map<String, GeoCoordinate> memberCoor
return client.getIntegerReply();
}

@Override
public Long geoadd(final String key, final GeoAddParams params, final Map<String, GeoCoordinate> memberCoordinateMap) {
checkIsInMultiOrPipeline();
client.geoadd(key, params, memberCoordinateMap);
return client.getIntegerReply();
}

@Override
public Double geodist(final String key, final String member1, final String member2) {
checkIsInMultiOrPipeline();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis.clients.jedis;

import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.GetExParams;
Expand Down Expand Up @@ -2178,6 +2179,16 @@ public Long execute(Jedis connection) {
}.run(key);
}

@Override
public Long geoadd(String key, GeoAddParams params, Map<String, GeoCoordinate> memberCoordinateMap) {
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
@Override
public Long execute(Jedis connection) {
return connection.geoadd(key, params, memberCoordinateMap);
}
}.run(key);
}

@Override
public Double geodist(final String key, final String member1, final String member2) {
return new JedisClusterCommand<Double>(connectionHandler, maxAttempts) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/redis/clients/jedis/PipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import redis.clients.jedis.commands.BinaryRedisPipeline;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.commands.RedisPipeline;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -1814,6 +1815,18 @@ public Response<Long> geoadd(final String key,
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Long> geoadd(String key, GeoAddParams params, Map<String, GeoCoordinate> memberCoordinateMap) {
getClient(key).geoadd(key, params, memberCoordinateMap);
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Long> geoadd(byte[] key, GeoAddParams params, Map<byte[], GeoCoordinate> memberCoordinateMap) {
getClient(key).geoadd(key, params, memberCoordinateMap);
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Double> geodist(final byte[] key, final byte[] member1, final byte[] member2) {
getClient(key).geodist(key, member1, member2);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/ShardedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import redis.clients.jedis.commands.JedisCommands;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -973,6 +974,12 @@ public Long geoadd(final String key, final Map<String, GeoCoordinate> memberCoor
return j.geoadd(key, memberCoordinateMap);
}

@Override
public Long geoadd(String key, GeoAddParams params, Map<String, GeoCoordinate> memberCoordinateMap) {
Jedis j = getShard(key);
return j.geoadd(key, params, memberCoordinateMap);
}

@Override
public Double geodist(final String key, final String member1, final String member2) {
Jedis j = getShard(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -308,6 +309,8 @@ default String setex(byte[] key, int seconds, byte[] value) {

Long geoadd(byte[] key, Map<byte[], GeoCoordinate> memberCoordinateMap);

Long geoadd(byte[] key, GeoAddParams params, Map<byte[], GeoCoordinate> memberCoordinateMap);

Double geodist(byte[] key, byte[] member1, byte[] member2);

Double geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import redis.clients.jedis.StreamGroupInfo;
import redis.clients.jedis.StreamInfo;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -334,6 +335,8 @@ default String setex(byte[] key, int seconds, byte[] value) {

Long geoadd(byte[] key, Map<byte[], GeoCoordinate> memberCoordinateMap);

Long geoadd(byte[] key, GeoAddParams params, Map<byte[], GeoCoordinate> memberCoordinateMap);

Double geodist(byte[] key, byte[] member1, byte[] member2);

Double geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import redis.clients.jedis.Response;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -325,6 +326,8 @@ default Response<String> restoreReplace(byte[] key, int ttl, byte[] serializedVa

Response<Long> geoadd(byte[] key, Map<byte[], GeoCoordinate> memberCoordinateMap);

Response<Long> geoadd(byte[] key, GeoAddParams params, Map<byte[], GeoCoordinate> memberCoordinateMap);

Response<Double> geodist(byte[] key, byte[] member1, byte[] member2);

Response<Double> geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.StreamPendingSummary;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -330,6 +331,8 @@ default String setex(String key, int seconds, String value) {

Long geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap);

Long geoadd(String key, GeoAddParams params, Map<String, GeoCoordinate> memberCoordinateMap);

Double geodist(String key, String member1, String member2);

Double geodist(String key, String member1, String member2, GeoUnit unit);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/redis/clients/jedis/commands/JedisCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.StreamPendingSummary;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -360,6 +361,8 @@ default String setex(String key, int seconds, String value) {

Long geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap);

Long geoadd(String key, GeoAddParams params, Map<String, GeoCoordinate> memberCoordinateMap);

Double geodist(String key, String member1, String member2);

Double geodist(String key, String member1, String member2, GeoUnit unit);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/redis/clients/jedis/commands/RedisPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.StreamPendingSummary;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
Expand Down Expand Up @@ -328,6 +329,8 @@ default Response<String> restoreReplace(String key, int ttl, byte[] serializedVa

Response<Long> geoadd(String key, Map<String, GeoCoordinate> memberCoordinateMap);

Response<Long> geoadd(String key, GeoAddParams params, Map<String, GeoCoordinate> memberCoordinateMap);

Response<Double> geodist(String key, String member1, String member2);

Response<Double> geodist(String key, String member1, String member2, GeoUnit unit);
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/redis/clients/jedis/params/GeoAddParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package redis.clients.jedis.params;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import redis.clients.jedis.util.SafeEncoder;

public class GeoAddParams extends Params {

private static final String NX = "nx";
private static final String XX = "xx";
private static final String CH = "ch";

public GeoAddParams() {
}

public static GeoAddParams geoAddParams() {
return new GeoAddParams();
}

/**
* Don't update already existing elements. Always add new elements.
* @return GetExParams
*/
public GeoAddParams nx() {
addParam(NX);
return this;
}

/**
* Only update elements that already exist. Never add elements.
* @return GetExParams
*/
public GeoAddParams xx() {
addParam(XX);
return this;
}

/**
* Modify the return value from the number of new elements added, to the total number of elements
* changed
* @return GetExParams
*/
public GeoAddParams ch() {
addParam(CH);
return this;
}

public byte[][] getByteParams(byte[] key, byte[]... args) {
List<byte[]> byteParams = new ArrayList<>();
byteParams.add(key);

if (contains(NX)) {
byteParams.add(SafeEncoder.encode(NX));
} else if (contains(XX)) {
byteParams.add(SafeEncoder.encode(XX));
}

if (contains(CH)) {
byteParams.add(SafeEncoder.encode(CH));
}

Collections.addAll(byteParams, args);

return byteParams.toArray(new byte[byteParams.size()][]);
}

}
Loading