Feature - add addIfExists() method to RGeo object #3380

pull/3384/head
Nikita Koksharov 4 years ago
parent 4b8230fe22
commit 697cc0402a

@ -100,8 +100,15 @@ public class RedissonGeo<V> extends RedissonScoredSortedSet<V> implements RGeo<V
@Override
public RFuture<Long> addAsync(GeoEntry... entries) {
List<Object> params = new ArrayList<Object>(entries.length + 1);
return addAsync("", entries);
}
private RFuture<Long> addAsync(String subCommand, GeoEntry... entries) {
List<Object> params = new ArrayList<Object>(entries.length + 2);
params.add(getName());
if (!subCommand.isEmpty()) {
params.add(subCommand);
}
for (GeoEntry entry : entries) {
params.add(entry.getLongitude());
params.add(entry.getLatitude());
@ -110,6 +117,27 @@ public class RedissonGeo<V> extends RedissonScoredSortedSet<V> implements RGeo<V
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.GEOADD, params.toArray());
}
@Override
public long addIfExists(double longitude, double latitude, V member) {
return get(addIfExistsAsync(longitude, latitude, member));
}
@Override
public long addIfExists(GeoEntry... entries) {
return get(addIfExistsAsync(entries));
}
@Override
public RFuture<Long> addIfExistsAsync(double longitude, double latitude, V member) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.GEOADD, getName(), "XX", convert(longitude),
convert(latitude), encode(member));
}
@Override
public RFuture<Long> addIfExistsAsync(GeoEntry... entries) {
return addAsync("XX", entries);
}
@Override
public Double dist(V firstMember, V secondMember, GeoUnit geoUnit) {
return get(distAsync(firstMember, secondMember, geoUnit));

@ -48,7 +48,29 @@ public interface RGeo<V> extends RScoredSortedSet<V>, RGeoAsync<V> {
* the score was updated
*/
long add(GeoEntry... entries);
/**
* Adds geospatial member only if it's already exists.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param longitude - longitude of object
* @param latitude - latitude of object
* @param member - object itself
* @return number of elements added to the sorted set
*/
long addIfExists(double longitude, double latitude, V member);
/**
* Adds geospatial members only if it's already exists.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param entries - objects
* @return number of elements added to the sorted set
*/
long addIfExists(GeoEntry... entries);
/**
* Returns distance between members in <code>GeoUnit</code> units.
*

@ -49,6 +49,28 @@ public interface RGeoAsync<V> extends RScoredSortedSetAsync<V> {
*/
RFuture<Long> addAsync(GeoEntry... entries);
/**
* Adds geospatial member only if it's already exists.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param longitude - longitude of object
* @param latitude - latitude of object
* @param member - object itself
* @return number of elements added to the sorted set
*/
RFuture<Long> addIfExistsAsync(double longitude, double latitude, V member);
/**
* Adds geospatial members only if it's already exists.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param entries - objects
* @return number of elements added to the sorted set
*/
RFuture<Long> addIfExistsAsync(GeoEntry... entries);
/**
* Returns distance between members in <code>GeoUnit</code> units.
*

@ -51,6 +51,28 @@ public interface RGeoReactive<V> extends RScoredSortedSetReactive<V> {
*/
Mono<Long> add(GeoEntry... entries);
/**
* Adds geospatial member only if it's already exists.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param longitude - longitude of object
* @param latitude - latitude of object
* @param member - object itself
* @return number of elements added to the sorted set
*/
Mono<Long> addIfExists(double longitude, double latitude, V member);
/**
* Adds geospatial members only if it's already exists.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param entries - objects
* @return number of elements added to the sorted set
*/
Mono<Long> addIfExists(GeoEntry... entries);
/**
* Returns distance between members in <code>GeoUnit</code> units.
*

@ -51,6 +51,28 @@ public interface RGeoRx<V> extends RScoredSortedSetRx<V> {
*/
Single<Long> add(GeoEntry... entries);
/**
* Adds geospatial member only if it's already exists.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param longitude - longitude of object
* @param latitude - latitude of object
* @param member - object itself
* @return number of elements added to the sorted set
*/
Single<Long> addIfExists(double longitude, double latitude, V member);
/**
* Adds geospatial members only if it's already exists.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param entries - objects
* @return number of elements added to the sorted set
*/
Single<Long> addIfExists(GeoEntry... entries);
/**
* Returns distance between members in <code>GeoUnit</code> units.
*

Loading…
Cancel
Save