Skip to content

Commit

Permalink
Support geo commands in lettuce 3.3 #86
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Jun 23, 2015
1 parent ae26471 commit 8e71ec0
Show file tree
Hide file tree
Showing 12 changed files with 686 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ endif
endif

endif
[ ! -e work/redis-git ] && git clone https://github.com/antirez/redis.git --branch 3.0 --single-branch work/redis-git && cd work/redis-git|| true
[ -e work/redis-git ] && cd work/redis-git && git reset --hard && git pull && git checkout 3.0 || true
[ ! -e work/redis-git ] && git clone https://github.com/antirez/redis.git --branch geo --single-branch work/redis-git && cd work/redis-git|| true
[ -e work/redis-git ] && cd work/redis-git && git reset --hard && git pull && git checkout geo || true
make -C work/redis-git clean
make -C work/redis-git -j4

Expand Down
79 changes: 79 additions & 0 deletions src/main/java/com/lambdaworks/redis/GeoArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.lambdaworks.redis;

import com.lambdaworks.redis.protocol.CommandArgs;

/**
* @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a>
*/
public class GeoArgs {

private boolean withdistance;
private boolean withcoordinates;
private boolean withhash;
private boolean noproperties;
private Sort sort = Sort.none;

public GeoArgs withDistance() {
withdistance = true;
return this;
}

public GeoArgs withCoordinates() {
withcoordinates = true;
return this;
}

public GeoArgs withHash() {
withhash = true;
return this;
}

public GeoArgs noProperties() {
noproperties = true;
return this;
}

public GeoArgs asc() {
return sort(Sort.asc);
}

public GeoArgs desc() {
return sort(Sort.desc);
}

public GeoArgs sort(Sort sort) {
this.sort = sort;
return this;
}

public enum Sort {
asc, desc, none;
}

public enum Unit {
meter, kilometer, feet, mile;
}

public <K, V> void build(CommandArgs<K, V> args) {
if (withdistance) {
args.add("withdistance");
}

if (withcoordinates) {
args.add("withcoordinates");
}

if (withhash) {
args.add("withhash");
}

if (noproperties) {
args.add("noproperties");
}

if (sort != null && sort != Sort.none) {
args.add(sort.name());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
public interface RedisAsyncConnection<K, V> extends RedisHashesAsyncConnection<K, V>, RedisKeysAsyncConnection<K, V>,
RedisStringsAsyncConnection<K, V>, RedisListsAsyncConnection<K, V>, RedisSetsAsyncConnection<K, V>,
RedisSortedSetsAsyncConnection<K, V>, RedisScriptingAsyncConnection<K, V>, RedisServerAsyncConnection<K, V>,
RedisHLLAsyncConnection<K, V>, BaseRedisAsyncConnection<K, V>, RedisClusterAsyncConnection<K, V> {
RedisHLLAsyncConnection<K, V>, RedisGeoAsyncConnection<K, V>, BaseRedisAsyncConnection<K, V>,
RedisClusterAsyncConnection<K, V> {

/**
* Set the default timeout for operations.
Expand Down
62 changes: 59 additions & 3 deletions src/main/java/com/lambdaworks/redis/RedisAsyncConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package com.lambdaworks.redis;

import static com.lambdaworks.redis.protocol.CommandType.*;
import static com.lambdaworks.redis.protocol.CommandType.EXEC;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -14,8 +14,18 @@

import com.lambdaworks.codec.Base16;
import com.lambdaworks.redis.codec.RedisCodec;
import com.lambdaworks.redis.output.*;
import com.lambdaworks.redis.protocol.*;
import com.lambdaworks.redis.output.KeyStreamingChannel;
import com.lambdaworks.redis.output.KeyValueStreamingChannel;
import com.lambdaworks.redis.output.MultiOutput;
import com.lambdaworks.redis.output.ScoredValueStreamingChannel;
import com.lambdaworks.redis.output.ValueStreamingChannel;
import com.lambdaworks.redis.protocol.Command;
import com.lambdaworks.redis.protocol.CommandArgs;
import com.lambdaworks.redis.protocol.CommandOutput;
import com.lambdaworks.redis.protocol.CommandType;
import com.lambdaworks.redis.protocol.ConnectionWatchdog;
import com.lambdaworks.redis.protocol.RedisCommand;
import com.lambdaworks.redis.protocol.SetArgs;
import io.netty.channel.ChannelHandler;

/**
Expand Down Expand Up @@ -1590,6 +1600,52 @@ public RedisFuture<List<V>> zrangebylex(K key, String min, String max, long offs
return dispatch(commandBuilder.zrangebylex(key, min, max, offset, count));
}

@Override
public RedisFuture<Long> geoadd(K key, double latitude, double longitude, V member) {
return dispatch(commandBuilder.geoadd(key, latitude, longitude, member));
}

@Override
public RedisFuture<Long> geoadd(K key, Object... latLongMember) {
return dispatch(commandBuilder.geoadd(key, latLongMember));
}

@Override
public RedisFuture<Set<V>> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit) {
return dispatch(commandBuilder.georadius(key, latitude, longitude, distance, unit.name()));
}

@Override
public RedisFuture<List<Object>> georadius(K key, double latitude, double longitude, double distance, GeoArgs.Unit unit,
GeoArgs geoArgs) {
return dispatch(commandBuilder.georadius(key, latitude, longitude, distance, unit.name(), geoArgs));
}

@Override
public RedisFuture<Set<V>> georadiusbymember(K key, V member, double distance, GeoArgs.Unit unit) {
return dispatch(commandBuilder.georadiusbymember(key, member, distance, unit.name()));
}

@Override
public RedisFuture<List<Object>> georadiusbymember(K key, V member, double distance, GeoArgs.Unit unit, GeoArgs geoArgs) {
return dispatch(commandBuilder.georadiusbymember(key, member, distance, unit.name(), geoArgs));
}

@Override
public RedisFuture<List<Object>> geoencode(double latitude, double longitude) {
return dispatch(commandBuilder.geoencode(latitude, longitude, null, null));
}

@Override
public RedisFuture<List<Object>> geoencode(double latitude, double longitude, double distance, GeoArgs.Unit unit) {
return dispatch(commandBuilder.geoencode(latitude, longitude, distance, unit.name()));
}

@Override
public RedisFuture<List<Object>> geodecode(long geohash) {
return dispatch(commandBuilder.geodecode(geohash));
}

protected <T> RedisCommand<K, V, T> dispatch(CommandType type, CommandOutput<K, V, T> output) {
return dispatch(type, output, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface RedisClusterAsyncConnection<K, V> extends RedisHashesAsyncConnection<K, V>, RedisKeysAsyncConnection<K, V>,
RedisStringsAsyncConnection<K, V>, RedisListsAsyncConnection<K, V>, RedisSetsAsyncConnection<K, V>,
RedisSortedSetsAsyncConnection<K, V>, RedisScriptingAsyncConnection<K, V>, RedisServerAsyncConnection<K, V>,
RedisHLLAsyncConnection<K, V>, BaseRedisAsyncConnection<K, V> {
RedisHLLAsyncConnection<K, V>, RedisGeoAsyncConnection<K, V>, BaseRedisAsyncConnection<K, V> {

/**
* Close the connection. The connection will become not usable anymore as soon as this method was called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public interface RedisClusterConnection<K, V> extends RedisHashesConnection<K, V>, RedisKeysConnection<K, V>,
RedisStringsConnection<K, V>, RedisListsConnection<K, V>, RedisSetsConnection<K, V>, RedisSortedSetsConnection<K, V>,
RedisScriptingConnection<K, V>, RedisServerConnection<K, V>, RedisHLLConnection<K, V> {
RedisScriptingConnection<K, V>, RedisServerConnection<K, V>, RedisHLLConnection<K, V>, RedisGeoConnection<K, V> {

/**
* Close the connection. The connection will become not usable anymore as soon as this method was called.
Expand Down
Loading

0 comments on commit 8e71ec0

Please sign in to comment.