Skip to content

Commit

Permalink
Merge branch 'master' into 5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed May 7, 2024
2 parents 6a1dfc8 + 7aad706 commit 27e1553
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 56 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -49,7 +49,7 @@
<jedis.module.name>redis.clients.jedis</jedis.module.name>
<slf4j.version>1.7.36</slf4j.version>
<resilience4j.version>1.7.1</resilience4j.version>
<jackson.version>2.17.0</jackson.version>
<jackson.version>2.17.1</jackson.version>
<maven.surefire.version>3.2.5</maven.surefire.version>
</properties>

Expand Down
42 changes: 36 additions & 6 deletions src/main/java/redis/clients/jedis/CommandArguments.java
@@ -1,6 +1,7 @@
package redis.clients.jedis;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

Expand Down Expand Up @@ -29,19 +30,50 @@ public ProtocolCommand getCommand() {
return (ProtocolCommand) args.get(0);
}

public CommandArguments add(Rawable arg) {
args.add(arg);
return this;
}

public CommandArguments add(byte[] arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(boolean arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(int arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(long arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(double arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(String arg) {
return add(RawableFactory.from(arg));
}

public CommandArguments add(Object arg) {
if (arg == null) {
throw new IllegalArgumentException("null is not a valid argument.");
} else if (arg instanceof Rawable) {
args.add((Rawable) arg);
} else if (arg instanceof byte[]) {
args.add(RawableFactory.from((byte[]) arg));
} else if (arg instanceof Boolean) {
args.add(RawableFactory.from((Boolean) arg));
} else if (arg instanceof Integer) {
args.add(RawableFactory.from((Integer) arg));
} else if (arg instanceof Long) {
args.add(RawableFactory.from((Long) arg));
} else if (arg instanceof Double) {
args.add(RawableFactory.from((Double) arg));
} else if (arg instanceof Boolean) {
args.add(RawableFactory.from((Boolean) arg ? 1 : 0));
} else if (arg instanceof float[]) {
args.add(RawableFactory.from(RediSearchUtil.toByteArray((float[]) arg)));
} else if (arg instanceof String) {
Expand Down Expand Up @@ -87,14 +119,12 @@ public CommandArguments key(Object key) {
}

public final CommandArguments keys(Object... keys) {
for (Object key : keys) {
key(key);
}
Arrays.stream(keys).forEach(this::key);
return this;
}

public final CommandArguments keys(Collection keys) {
keys.forEach(key -> key(key));
keys.forEach(this::key);
return this;
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/redis/clients/jedis/args/RawableFactory.java
Expand Up @@ -10,6 +10,15 @@
*/
public final class RawableFactory {

/**
* Get a {@link Rawable} from a {@code boolean}.
* @param b boolean value
* @return raw
*/
public static Rawable from(boolean b) {
return from(toByteArray(b));
}

/**
* Get a {@link Rawable} from an {@code int}.
* @param i integer value
Expand All @@ -19,6 +28,15 @@ public static Rawable from(int i) {
return from(toByteArray(i));
}

/**
* Get a {@link Rawable} from a {@code long}.
* @param l long value
* @return raw
*/
public static Rawable from(long l) {
return from(toByteArray(l));
}

/**
* Get a {@link Rawable} from a {@code double}.
* @param d numeric value
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/redis/clients/jedis/params/GeoSearchParam.java
Expand Up @@ -115,18 +115,25 @@ public GeoSearchParam any() {

@Override
public void addParams(CommandArguments args) {
if (this.fromMember) {
args.add(Keyword.FROMMEMBER).add(this.member);
} else if (this.fromLonLat) {
if (fromMember && fromLonLat) {
throw new IllegalArgumentException("Both FROMMEMBER and FROMLONLAT cannot be used.");
} else if (fromMember) {
args.add(Keyword.FROMMEMBER).add(member);
} else if (fromLonLat) {
args.add(Keyword.FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude());
} else {
throw new IllegalArgumentException("Either FROMMEMBER or FROMLONLAT must be used.");
}

if (this.byRadius) {
args.add(Keyword.BYRADIUS).add(this.radius);
} else if (this.byBox) {
args.add(Keyword.BYBOX).add(this.width).add(this.height);
if (byRadius && byBox) {
throw new IllegalArgumentException("Both BYRADIUS and BYBOX cannot be used.");
} else if (byRadius) {
args.add(Keyword.BYRADIUS).add(radius).add(unit);
} else if (byBox) {
args.add(Keyword.BYBOX).add(width).add(height).add(unit);
} else {
throw new IllegalArgumentException("Either BYRADIUS or BYBOX must be used.");
}
args.add(this.unit);

if (withCoord) {
args.add(Keyword.WITHCOORD);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/redis/clients/jedis/search/FTSearchParams.java
Expand Up @@ -6,6 +6,7 @@

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.annots.Internal;
import redis.clients.jedis.args.GeoUnit;
import redis.clients.jedis.args.SortingOrder;
import redis.clients.jedis.params.IParams;
Expand Down Expand Up @@ -427,6 +428,7 @@ public FTSearchParams dialect(int dialect) {
* @param dialect dialect
* @return this
*/
@Internal
public FTSearchParams dialectOptional(int dialect) {
if (dialect != 0 && this.dialect == null) {
this.dialect = dialect;
Expand Down
Expand Up @@ -540,30 +540,30 @@ public void geosearchNegative() {
// combine byradius and bybox
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
.byRadius(3000, GeoUnit.M)
.byBox(300, 300, GeoUnit.M));
fail();
} catch (Exception ignored) { }
} catch (IllegalArgumentException ignored) { }

// without byradius and without bybox
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.fromMember("foobar"));
jedis.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
fail();
} catch (Exception ignored) { }
} catch (IllegalArgumentException ignored) { }

// combine frommember and fromlonlat
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.fromMember("foobar").fromLonLat(10,10));
.fromMember("foobar")
.fromLonLat(10,10));
fail();
} catch (Exception ignored) { }
} catch (IllegalArgumentException ignored) { }

// without frommember and without fromlonlat
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.byRadius(10, GeoUnit.MI));
jedis.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
fail();
} catch (Exception ignored) { }
} catch (IllegalArgumentException ignored) { }
}

@Test
Expand Down
Expand Up @@ -537,30 +537,30 @@ public void geosearchNegative() {
// combine byradius and bybox
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
.byRadius(3000, GeoUnit.M)
.byBox(300, 300, GeoUnit.M));
fail();
} catch (redis.clients.jedis.exceptions.JedisDataException ignored) { }
} catch (IllegalArgumentException ignored) { }

// without byradius and without bybox
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.fromMember("foobar"));
jedis.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
fail();
} catch (java.lang.IllegalArgumentException ignored) { }
} catch (IllegalArgumentException ignored) { }

// combine frommember and fromlonlat
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.fromMember("foobar").fromLonLat(10,10));
.fromMember("foobar")
.fromLonLat(10,10));
fail();
} catch (java.lang.IllegalArgumentException ignored) { }
} catch (IllegalArgumentException ignored) { }

// without frommember and without fromlonlat
try {
jedis.geosearch("barcelona", new GeoSearchParam()
.byRadius(10, GeoUnit.MI));
jedis.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
fail();
} catch (redis.clients.jedis.exceptions.JedisDataException ignored) { }
} catch (IllegalArgumentException ignored) { }
}

@Test
Expand Down
Expand Up @@ -84,13 +84,13 @@ public void georadiusByMemberStore() {
public void georadiusByMemberStoreBinary() {
}

@Test
@Ignore
@Override
public void geosearchstore() {
}

@Test
@Ignore
@Override
public void geosearchstoreWithdist() {
}
}
@@ -0,0 +1,27 @@
package redis.clients.jedis.commands.unified.cluster;

import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import redis.clients.jedis.RedisProtocol;
import redis.clients.jedis.commands.unified.HashesCommandsTestBase;

@RunWith(Parameterized.class)
public class ClusterHashesCommandsTest extends HashesCommandsTestBase {

public ClusterHashesCommandsTest(RedisProtocol protocol) {
super(protocol);
}

@Before
public void setUp() {
jedis = ClusterCommandsTestHelper.getCleanCluster(protocol);
}

@After
public void tearDown() {
jedis.close();
ClusterCommandsTestHelper.clearClusterData();
}
}
Expand Up @@ -798,32 +798,24 @@ public void geosearch() {
contains(0L));
}

@Test
public void geosearchNegative() {
// combine byradius and bybox
pipe.geosearch("barcelona",
new GeoSearchParam().byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));

// without frommember and without fromlonlat
pipe.geosearch("barcelona",
new GeoSearchParam().byRadius(10, GeoUnit.MI));
@Test(expected = IllegalArgumentException.class)
public void geosearchSearchParamCombineFromMemberAndFromLonLat() {
pipe.geosearch("barcelona", new GeoSearchParam().fromMember("foobar").fromLonLat(10, 10));
}

assertThat(pipe.syncAndReturnAll(), contains(
instanceOf(JedisDataException.class),
instanceOf(JedisDataException.class)
));
@Test(expected = IllegalArgumentException.class)
public void geosearchSearchParamWithoutFromMemberAndFromLonLat() {
pipe.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
}

@Test(expected = IllegalArgumentException.class)
public void geosearchSearchParamWithoutRadiousAndWithoutBox() {
pipe.geosearch("barcelona",
new GeoSearchParam().fromMember("foobar"));
public void geosearchSearchParamCombineByRadiousAndByBox() {
pipe.geosearch("barcelona", new GeoSearchParam().byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
}

@Test(expected = IllegalArgumentException.class)
public void geosearchSearchParamCombineMemberAndLonLat() {
pipe.geosearch("barcelona",
new GeoSearchParam().fromMember("foobar").fromLonLat(10, 10));
public void geosearchSearchParamWithoutByRadiousAndByBox() {
pipe.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
}

@Test
Expand Down

0 comments on commit 27e1553

Please sign in to comment.