Skip to content

Commit 27e1553

Browse files
authored
Merge branch 'master' into 5.2.0
2 parents 6a1dfc8 + 7aad706 commit 27e1553

File tree

10 files changed

+132
-56
lines changed

10 files changed

+132
-56
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<jedis.module.name>redis.clients.jedis</jedis.module.name>
5050
<slf4j.version>1.7.36</slf4j.version>
5151
<resilience4j.version>1.7.1</resilience4j.version>
52-
<jackson.version>2.17.0</jackson.version>
52+
<jackson.version>2.17.1</jackson.version>
5353
<maven.surefire.version>3.2.5</maven.surefire.version>
5454
</properties>
5555

src/main/java/redis/clients/jedis/CommandArguments.java

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package redis.clients.jedis;
22

33
import java.util.ArrayList;
4+
import java.util.Arrays;
45
import java.util.Collection;
56
import java.util.Iterator;
67

@@ -29,19 +30,50 @@ public ProtocolCommand getCommand() {
2930
return (ProtocolCommand) args.get(0);
3031
}
3132

33+
public CommandArguments add(Rawable arg) {
34+
args.add(arg);
35+
return this;
36+
}
37+
38+
public CommandArguments add(byte[] arg) {
39+
return add(RawableFactory.from(arg));
40+
}
41+
42+
public CommandArguments add(boolean arg) {
43+
return add(RawableFactory.from(arg));
44+
}
45+
46+
public CommandArguments add(int arg) {
47+
return add(RawableFactory.from(arg));
48+
}
49+
50+
public CommandArguments add(long arg) {
51+
return add(RawableFactory.from(arg));
52+
}
53+
54+
public CommandArguments add(double arg) {
55+
return add(RawableFactory.from(arg));
56+
}
57+
58+
public CommandArguments add(String arg) {
59+
return add(RawableFactory.from(arg));
60+
}
61+
3262
public CommandArguments add(Object arg) {
3363
if (arg == null) {
3464
throw new IllegalArgumentException("null is not a valid argument.");
3565
} else if (arg instanceof Rawable) {
3666
args.add((Rawable) arg);
3767
} else if (arg instanceof byte[]) {
3868
args.add(RawableFactory.from((byte[]) arg));
69+
} else if (arg instanceof Boolean) {
70+
args.add(RawableFactory.from((Boolean) arg));
3971
} else if (arg instanceof Integer) {
4072
args.add(RawableFactory.from((Integer) arg));
73+
} else if (arg instanceof Long) {
74+
args.add(RawableFactory.from((Long) arg));
4175
} else if (arg instanceof Double) {
4276
args.add(RawableFactory.from((Double) arg));
43-
} else if (arg instanceof Boolean) {
44-
args.add(RawableFactory.from((Boolean) arg ? 1 : 0));
4577
} else if (arg instanceof float[]) {
4678
args.add(RawableFactory.from(RediSearchUtil.toByteArray((float[]) arg)));
4779
} else if (arg instanceof String) {
@@ -87,14 +119,12 @@ public CommandArguments key(Object key) {
87119
}
88120

89121
public final CommandArguments keys(Object... keys) {
90-
for (Object key : keys) {
91-
key(key);
92-
}
122+
Arrays.stream(keys).forEach(this::key);
93123
return this;
94124
}
95125

96126
public final CommandArguments keys(Collection keys) {
97-
keys.forEach(key -> key(key));
127+
keys.forEach(this::key);
98128
return this;
99129
}
100130

src/main/java/redis/clients/jedis/args/RawableFactory.java

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
*/
1111
public final class RawableFactory {
1212

13+
/**
14+
* Get a {@link Rawable} from a {@code boolean}.
15+
* @param b boolean value
16+
* @return raw
17+
*/
18+
public static Rawable from(boolean b) {
19+
return from(toByteArray(b));
20+
}
21+
1322
/**
1423
* Get a {@link Rawable} from an {@code int}.
1524
* @param i integer value
@@ -19,6 +28,15 @@ public static Rawable from(int i) {
1928
return from(toByteArray(i));
2029
}
2130

31+
/**
32+
* Get a {@link Rawable} from a {@code long}.
33+
* @param l long value
34+
* @return raw
35+
*/
36+
public static Rawable from(long l) {
37+
return from(toByteArray(l));
38+
}
39+
2240
/**
2341
* Get a {@link Rawable} from a {@code double}.
2442
* @param d numeric value

src/main/java/redis/clients/jedis/params/GeoSearchParam.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,25 @@ public GeoSearchParam any() {
115115

116116
@Override
117117
public void addParams(CommandArguments args) {
118-
if (this.fromMember) {
119-
args.add(Keyword.FROMMEMBER).add(this.member);
120-
} else if (this.fromLonLat) {
118+
if (fromMember && fromLonLat) {
119+
throw new IllegalArgumentException("Both FROMMEMBER and FROMLONLAT cannot be used.");
120+
} else if (fromMember) {
121+
args.add(Keyword.FROMMEMBER).add(member);
122+
} else if (fromLonLat) {
121123
args.add(Keyword.FROMLONLAT).add(coord.getLongitude()).add(coord.getLatitude());
124+
} else {
125+
throw new IllegalArgumentException("Either FROMMEMBER or FROMLONLAT must be used.");
122126
}
123127

124-
if (this.byRadius) {
125-
args.add(Keyword.BYRADIUS).add(this.radius);
126-
} else if (this.byBox) {
127-
args.add(Keyword.BYBOX).add(this.width).add(this.height);
128+
if (byRadius && byBox) {
129+
throw new IllegalArgumentException("Both BYRADIUS and BYBOX cannot be used.");
130+
} else if (byRadius) {
131+
args.add(Keyword.BYRADIUS).add(radius).add(unit);
132+
} else if (byBox) {
133+
args.add(Keyword.BYBOX).add(width).add(height).add(unit);
134+
} else {
135+
throw new IllegalArgumentException("Either BYRADIUS or BYBOX must be used.");
128136
}
129-
args.add(this.unit);
130137

131138
if (withCoord) {
132139
args.add(Keyword.WITHCOORD);

src/main/java/redis/clients/jedis/search/FTSearchParams.java

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import redis.clients.jedis.CommandArguments;
88
import redis.clients.jedis.Protocol;
9+
import redis.clients.jedis.annots.Internal;
910
import redis.clients.jedis.args.GeoUnit;
1011
import redis.clients.jedis.args.SortingOrder;
1112
import redis.clients.jedis.params.IParams;
@@ -427,6 +428,7 @@ public FTSearchParams dialect(int dialect) {
427428
* @param dialect dialect
428429
* @return this
429430
*/
431+
@Internal
430432
public FTSearchParams dialectOptional(int dialect) {
431433
if (dialect != 0 && this.dialect == null) {
432434
this.dialect = dialect;

src/test/java/redis/clients/jedis/commands/jedis/GeoCommandsTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -540,30 +540,30 @@ public void geosearchNegative() {
540540
// combine byradius and bybox
541541
try {
542542
jedis.geosearch("barcelona", new GeoSearchParam()
543-
.byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
543+
.byRadius(3000, GeoUnit.M)
544+
.byBox(300, 300, GeoUnit.M));
544545
fail();
545-
} catch (Exception ignored) { }
546+
} catch (IllegalArgumentException ignored) { }
546547

547548
// without byradius and without bybox
548549
try {
549-
jedis.geosearch("barcelona", new GeoSearchParam()
550-
.fromMember("foobar"));
550+
jedis.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
551551
fail();
552-
} catch (Exception ignored) { }
552+
} catch (IllegalArgumentException ignored) { }
553553

554554
// combine frommember and fromlonlat
555555
try {
556556
jedis.geosearch("barcelona", new GeoSearchParam()
557-
.fromMember("foobar").fromLonLat(10,10));
557+
.fromMember("foobar")
558+
.fromLonLat(10,10));
558559
fail();
559-
} catch (Exception ignored) { }
560+
} catch (IllegalArgumentException ignored) { }
560561

561562
// without frommember and without fromlonlat
562563
try {
563-
jedis.geosearch("barcelona", new GeoSearchParam()
564-
.byRadius(10, GeoUnit.MI));
564+
jedis.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
565565
fail();
566-
} catch (Exception ignored) { }
566+
} catch (IllegalArgumentException ignored) { }
567567
}
568568

569569
@Test

src/test/java/redis/clients/jedis/commands/unified/GeoCommandsTestBase.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -537,30 +537,30 @@ public void geosearchNegative() {
537537
// combine byradius and bybox
538538
try {
539539
jedis.geosearch("barcelona", new GeoSearchParam()
540-
.byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
540+
.byRadius(3000, GeoUnit.M)
541+
.byBox(300, 300, GeoUnit.M));
541542
fail();
542-
} catch (redis.clients.jedis.exceptions.JedisDataException ignored) { }
543+
} catch (IllegalArgumentException ignored) { }
543544

544545
// without byradius and without bybox
545546
try {
546-
jedis.geosearch("barcelona", new GeoSearchParam()
547-
.fromMember("foobar"));
547+
jedis.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
548548
fail();
549-
} catch (java.lang.IllegalArgumentException ignored) { }
549+
} catch (IllegalArgumentException ignored) { }
550550

551551
// combine frommember and fromlonlat
552552
try {
553553
jedis.geosearch("barcelona", new GeoSearchParam()
554-
.fromMember("foobar").fromLonLat(10,10));
554+
.fromMember("foobar")
555+
.fromLonLat(10,10));
555556
fail();
556-
} catch (java.lang.IllegalArgumentException ignored) { }
557+
} catch (IllegalArgumentException ignored) { }
557558

558559
// without frommember and without fromlonlat
559560
try {
560-
jedis.geosearch("barcelona", new GeoSearchParam()
561-
.byRadius(10, GeoUnit.MI));
561+
jedis.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
562562
fail();
563-
} catch (redis.clients.jedis.exceptions.JedisDataException ignored) { }
563+
} catch (IllegalArgumentException ignored) { }
564564
}
565565

566566
@Test

src/test/java/redis/clients/jedis/commands/unified/cluster/ClusterGeoCommandsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ public void georadiusByMemberStore() {
8484
public void georadiusByMemberStoreBinary() {
8585
}
8686

87-
@Test
8887
@Ignore
88+
@Override
8989
public void geosearchstore() {
9090
}
9191

92-
@Test
9392
@Ignore
93+
@Override
9494
public void geosearchstoreWithdist() {
9595
}
9696
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package redis.clients.jedis.commands.unified.cluster;
2+
3+
import org.junit.After;
4+
import org.junit.Before;
5+
import org.junit.runner.RunWith;
6+
import org.junit.runners.Parameterized;
7+
import redis.clients.jedis.RedisProtocol;
8+
import redis.clients.jedis.commands.unified.HashesCommandsTestBase;
9+
10+
@RunWith(Parameterized.class)
11+
public class ClusterHashesCommandsTest extends HashesCommandsTestBase {
12+
13+
public ClusterHashesCommandsTest(RedisProtocol protocol) {
14+
super(protocol);
15+
}
16+
17+
@Before
18+
public void setUp() {
19+
jedis = ClusterCommandsTestHelper.getCleanCluster(protocol);
20+
}
21+
22+
@After
23+
public void tearDown() {
24+
jedis.close();
25+
ClusterCommandsTestHelper.clearClusterData();
26+
}
27+
}

src/test/java/redis/clients/jedis/commands/unified/pipeline/GeoPipelineCommandsTest.java

+11-19
Original file line numberDiff line numberDiff line change
@@ -798,32 +798,24 @@ public void geosearch() {
798798
contains(0L));
799799
}
800800

801-
@Test
802-
public void geosearchNegative() {
803-
// combine byradius and bybox
804-
pipe.geosearch("barcelona",
805-
new GeoSearchParam().byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
806-
807-
// without frommember and without fromlonlat
808-
pipe.geosearch("barcelona",
809-
new GeoSearchParam().byRadius(10, GeoUnit.MI));
801+
@Test(expected = IllegalArgumentException.class)
802+
public void geosearchSearchParamCombineFromMemberAndFromLonLat() {
803+
pipe.geosearch("barcelona", new GeoSearchParam().fromMember("foobar").fromLonLat(10, 10));
804+
}
810805

811-
assertThat(pipe.syncAndReturnAll(), contains(
812-
instanceOf(JedisDataException.class),
813-
instanceOf(JedisDataException.class)
814-
));
806+
@Test(expected = IllegalArgumentException.class)
807+
public void geosearchSearchParamWithoutFromMemberAndFromLonLat() {
808+
pipe.geosearch("barcelona", new GeoSearchParam().byRadius(10, GeoUnit.MI));
815809
}
816810

817811
@Test(expected = IllegalArgumentException.class)
818-
public void geosearchSearchParamWithoutRadiousAndWithoutBox() {
819-
pipe.geosearch("barcelona",
820-
new GeoSearchParam().fromMember("foobar"));
812+
public void geosearchSearchParamCombineByRadiousAndByBox() {
813+
pipe.geosearch("barcelona", new GeoSearchParam().byRadius(3000, GeoUnit.M).byBox(300, 300, GeoUnit.M));
821814
}
822815

823816
@Test(expected = IllegalArgumentException.class)
824-
public void geosearchSearchParamCombineMemberAndLonLat() {
825-
pipe.geosearch("barcelona",
826-
new GeoSearchParam().fromMember("foobar").fromLonLat(10, 10));
817+
public void geosearchSearchParamWithoutByRadiousAndByBox() {
818+
pipe.geosearch("barcelona", new GeoSearchParam().fromMember("foobar"));
827819
}
828820

829821
@Test

0 commit comments

Comments
 (0)