Skip to content

Add support for GEOSEARCH and GEOSEARCHSTORE #2113

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

Closed
wants to merge 8 commits into from
Closed
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
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.6.0-SNAPSHOT</version>
<version>2.6.0-2043-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
8 changes: 8 additions & 0 deletions src/main/asciidoc/appendix/appendix-command-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
|EXPIREAT |X
|FLUSHALL |X
|FLUSHDB |X
|GEOADD |X
|GEODIST |X
|GEOHASH |X
|GEOPOS |X
|GEORADIUS |X
|GEORADIUSBYMEMBER |X
|GEOSEARCH |X
|GEOSEARCHSTORE |X
|GET |X
|GETBIT |X
|GETRANGE |X
Expand Down
2 changes: 1 addition & 1 deletion src/main/asciidoc/new-features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This section briefly covers items that are new and noteworthy in the latest rele
== New in Spring Data Redis 2.6

* Support for `SubscriptionListener` when using `MessageListener` for subscription confirmation callbacks. `ReactiveRedisMessageListenerContainer` and `ReactiveRedisOperations` provide `receiveLater(…)` and `listenToLater(…)` methods to await until Redis acknowledges the subscription.
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `LMOVE`/`BLMOVE`, `COPY`, `GETEX`, `GETDEL`, `ZPOPMIN`, `BZPOPMIN`, `ZPOPMAX`, `BZPOPMAX`, `ZMSCORE`, `ZDIFF`, `ZDIFFSTORE`, `ZINTER`, `ZUNION`, `HRANDFIELD`, `ZRANDMEMBER`, `SMISMEMBER`).
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `LMOVE`/`BLMOVE`, `COPY`, `GETEX`, `GETDEL`, `GEOSEARCH`, `GEOSEARCHSTORE`, `ZPOPMIN`, `BZPOPMIN`, `ZPOPMAX`, `BZPOPMAX`, `ZMSCORE`, `ZDIFF`, `ZDIFFSTORE`, `ZINTER`, `ZUNION`, `HRANDFIELD`, `ZRANDMEMBER`, `SMISMEMBER`).

[[new-in-2.5.0]]
== New in Spring Data Redis 2.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.data.redis.domain.geo.GeoShape;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -2120,6 +2121,14 @@ private byte[] serialize(String data) {
return serializer.serialize(data);
}

@SuppressWarnings("unchecked")
private GeoReference<byte[]> serialize(GeoReference<String> data) {
return data instanceof GeoReference.GeoSearchMemberReference
? GeoReference
.fromMember(serializer.serialize(((GeoReference.GeoSearchMemberReference<String>) data).getMember()))
: (GeoReference) data;
}

@SuppressWarnings("unchecked")
private StreamOffset<byte[]>[] serialize(StreamOffset<String>[] offsets) {

Expand Down Expand Up @@ -3886,6 +3895,50 @@ public Long geoRemove(String key, String... members) {
return geoRemove(serialize(key), serializeMulti(members));
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoSearch(byte[], byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchCommandArgs)
*/
@Override
public GeoResults<GeoLocation<byte[]>> geoSearch(byte[] key, GeoReference<byte[]> reference, GeoShape predicate,
GeoSearchCommandArgs args) {
return convertAndReturn(delegate.geoSearch(key, reference, predicate, args), Converters.identityConverter());
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisGeoCommands#geoSearchStore(byte[], byte[], byte[], org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchStoreCommandArgs)
*/
@Override
public Long geoSearchStore(byte[] destKey, byte[] key, GeoReference<byte[]> reference, GeoShape predicate,
GeoSearchStoreCommandArgs args) {
return convertAndReturn(delegate.geoSearchStore(destKey, key, reference, predicate, args),
Converters.identityConverter());
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#geoSearch(java.lang.String, java.lang.String, org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchCommandArgs)
*/
@Override
public GeoResults<GeoLocation<String>> geoSearch(String key, GeoReference<String> reference, GeoShape predicate,
GeoSearchCommandArgs args) {
return convertAndReturn(delegate.geoSearch(serialize(key), serialize(reference), predicate, args),
byteGeoResultsToStringGeoResults);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#geoSearchStore(java.lang.String, java.lang.String, java.lang.String, org.springframework.data.redis.connection.RedisGeoCommands.GeoShape, org.springframework.data.redis.connection.RedisGeoCommands.GeoSearchStoreCommandArgs)
*/
@Override
public Long geoSearchStore(String destKey, String key, GeoReference<String> reference, GeoShape predicate,
GeoSearchStoreCommandArgs args) {
return convertAndReturn(
delegate.geoSearchStore(serialize(destKey), serialize(key), serialize(reference), predicate, args),
Converters.identityConverter());
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisConnection#closePipeline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.data.redis.domain.geo.GeoShape;
import org.springframework.lang.Nullable;

/**
Expand Down Expand Up @@ -1540,6 +1541,22 @@ default Long geoRemove(byte[] key, byte[]... members) {
return geoCommands().geoRemove(key, members);
}

/** @deprecated in favor of {@link RedisConnection#geoCommands()}}. */
@Override
@Deprecated
default GeoResults<GeoLocation<byte[]>> geoSearch(byte[] key, GeoReference<byte[]> reference, GeoShape predicate,
GeoSearchCommandArgs args) {
return geoCommands().geoSearch(key, reference, predicate, args);
}

/** @deprecated in favor of {@link RedisConnection#geoCommands()}}. */
@Override
@Deprecated
default Long geoSearchStore(byte[] destKey, byte[] key, GeoReference<byte[]> reference, GeoShape predicate,
GeoSearchStoreCommandArgs args) {
return geoCommands().geoSearchStore(destKey, key, reference, predicate, args);
}

// HLL COMMANDS

/** @deprecated in favor of {@link RedisConnection#hyperLogLogCommands()}. */
Expand Down
Loading