Skip to content

Commit ec5e417

Browse files
committed
Use simple version of HSET (#3587)
for easier readability
1 parent 4a84608 commit ec5e417

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

src/test/java/redis/clients/jedis/examples/GeoShapeFieldsUsageInRediSearch.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package redis.clients.jedis.examples;
22

3+
import java.util.Collections;
4+
import org.junit.Assert;
5+
36
import org.locationtech.jts.geom.Coordinate;
47
import org.locationtech.jts.geom.Geometry;
58
import org.locationtech.jts.geom.GeometryFactory;
@@ -11,13 +14,10 @@
1114
import redis.clients.jedis.JedisPooled;
1215
import redis.clients.jedis.UnifiedJedis;
1316
import redis.clients.jedis.search.FTSearchParams;
17+
import redis.clients.jedis.search.RediSearchUtil;
1418
import redis.clients.jedis.search.SearchResult;
1519
import redis.clients.jedis.search.schemafields.GeoShapeField;
1620

17-
import static java.util.Collections.singletonMap;
18-
import static org.junit.Assert.assertEquals;
19-
import static redis.clients.jedis.search.RediSearchUtil.toStringMap;
20-
2121
/**
2222
* As of RediSearch 2.8.4, advanced GEO querying with GEOSHAPE fields is supported.
2323
*
@@ -64,15 +64,17 @@ public static void main(String[] args) {
6464
new Coordinate(34.9100, 29.7001), new Coordinate(34.9001, 29.7001)}
6565
);
6666

67-
client.hset("small", toStringMap(singletonMap("geometry", small))); // setting data
67+
// client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geometry", small))); // setting data
68+
client.hset("small", "geometry", small.toString()); // simplified setting data
6869

6970
final Polygon large = factory.createPolygon(
7071
new Coordinate[]{new Coordinate(34.9001, 29.7001),
7172
new Coordinate(34.9001, 29.7200), new Coordinate(34.9200, 29.7200),
7273
new Coordinate(34.9200, 29.7001), new Coordinate(34.9001, 29.7001)}
7374
);
7475

75-
client.hset("large", toStringMap(singletonMap("geometry", large))); // setting data
76+
// client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geometry", large))); // setting data
77+
client.hset("large", "geometry", large.toString()); // simplified setting data
7678

7779
// searching
7880
final Polygon within = factory.createPolygon(
@@ -88,14 +90,14 @@ public static void main(String[] args) {
8890
.addParam("poly", within)
8991
.dialect(3) // DIALECT '3' is required for this query
9092
);
91-
assertEquals(1, res.getTotalResults());
92-
assertEquals(1, res.getDocuments().size());
93+
Assert.assertEquals(1, res.getTotalResults());
94+
Assert.assertEquals(1, res.getDocuments().size());
9395

9496
// We can parse geometry objects with WKTReader
9597
try {
9698
final WKTReader reader = new WKTReader();
9799
Geometry object = reader.read(res.getDocuments().get(0).getString("geometry"));
98-
assertEquals(small, object);
100+
Assert.assertEquals(small, object);
99101
} catch (ParseException ex) {
100102
ex.printStackTrace(System.err);
101103
}

src/test/java/redis/clients/jedis/modules/search/SearchWithParamsTest.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,12 @@ public void geoShapeFilterSpherical() throws ParseException {
355355
final Polygon small = factory.createPolygon(new Coordinate[]{new Coordinate(34.9001, 29.7001),
356356
new Coordinate(34.9001, 29.7100), new Coordinate(34.9100, 29.7100),
357357
new Coordinate(34.9100, 29.7001), new Coordinate(34.9001, 29.7001)});
358-
client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geom", small)));
358+
client.hset("small", "geom", small.toString());
359359

360360
final Polygon large = factory.createPolygon(new Coordinate[]{new Coordinate(34.9001, 29.7001),
361361
new Coordinate(34.9001, 29.7200), new Coordinate(34.9200, 29.7200),
362362
new Coordinate(34.9200, 29.7001), new Coordinate(34.9001, 29.7001)});
363-
client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geom", large)));
363+
client.hset("large", "geom", large.toString());
364364

365365
// within condition
366366
final Polygon within = factory.createPolygon(new Coordinate[]{new Coordinate(34.9000, 29.7000),
@@ -385,7 +385,7 @@ public void geoShapeFilterSpherical() throws ParseException {
385385

386386
// point type
387387
final Point point = factory.createPoint(new Coordinate(34.9010, 29.7010));
388-
client.hset("point", RediSearchUtil.toStringMap(Collections.singletonMap("geom", point)));
388+
client.hset("point", "geom", point.toString());
389389

390390
res = client.ftSearch(index, "@geom:[within $poly]",
391391
FTSearchParams.searchParams().addParam("poly", within).dialect(3));
@@ -403,11 +403,11 @@ public void geoShapeFilterFlat() throws ParseException {
403403
// polygon type
404404
final Polygon small = factory.createPolygon(new Coordinate[]{new Coordinate(1, 1),
405405
new Coordinate(1, 100), new Coordinate(100, 100), new Coordinate(100, 1), new Coordinate(1, 1)});
406-
client.hset("small", RediSearchUtil.toStringMap(Collections.singletonMap("geom", small)));
406+
client.hset("small", "geom", small.toString());
407407

408408
final Polygon large = factory.createPolygon(new Coordinate[]{new Coordinate(1, 1),
409409
new Coordinate(1, 200), new Coordinate(200, 200), new Coordinate(200, 1), new Coordinate(1, 1)});
410-
client.hset("large", RediSearchUtil.toStringMap(Collections.singletonMap("geom", large)));
410+
client.hset("large", "geom", large.toString());
411411

412412
// within condition
413413
final Polygon within = factory.createPolygon(new Coordinate[]{new Coordinate(0, 0),
@@ -430,7 +430,7 @@ public void geoShapeFilterFlat() throws ParseException {
430430

431431
// point type
432432
final Point point = factory.createPoint(new Coordinate(10, 10));
433-
client.hset("point", RediSearchUtil.toStringMap(Collections.singletonMap("geom", point)));
433+
client.hset("point", "geom", point.toString());
434434

435435
res = client.ftSearch(index, "@geom:[within $poly]",
436436
FTSearchParams.searchParams().addParam("poly", within).dialect(3));
@@ -1100,9 +1100,9 @@ public void maxPrefixExpansionSearchProfile() {
11001100
client.ftConfigSet(configParam, "2");
11011101

11021102
assertOK(client.ftCreate(index, TextField.of("t")));
1103-
client.hset("1", Collections.singletonMap("t", "foo1"));
1104-
client.hset("2", Collections.singletonMap("t", "foo2"));
1105-
client.hset("3", Collections.singletonMap("t", "foo3"));
1103+
client.hset("1", "t", "foo1");
1104+
client.hset("2", "t", "foo2");
1105+
client.hset("3", "t", "foo3");
11061106

11071107
Map.Entry<SearchResult, Map<String, Object>> profile = client.ftProfileSearch(index,
11081108
FTProfileParams.profileParams(), "foo*", FTSearchParams.searchParams().limit(0, 0));
@@ -1116,8 +1116,8 @@ public void maxPrefixExpansionSearchProfile() {
11161116
@Test
11171117
public void notIteratorSearchProfile() {
11181118
assertOK(client.ftCreate(index, TextField.of("t")));
1119-
client.hset("1", Collections.singletonMap("t", "foo"));
1120-
client.hset("2", Collections.singletonMap("t", "bar"));
1119+
client.hset("1", "t", "foo");
1120+
client.hset("2", "t", "bar");
11211121

11221122
Map.Entry<SearchResult, Map<String, Object>> profile = client.ftProfileSearch(index,
11231123
FTProfileParams.profileParams(), "foo -@t:baz", FTSearchParams.searchParams().noContent());
@@ -1136,8 +1136,8 @@ public void notIteratorSearchProfile() {
11361136
@Test
11371137
public void deepReplySearchProfile() {
11381138
assertOK(client.ftCreate(index, TextField.of("t")));
1139-
client.hset("1", Collections.singletonMap("t", "hello"));
1140-
client.hset("2", Collections.singletonMap("t", "world"));
1139+
client.hset("1", "t", "hello");
1140+
client.hset("2", "t", "world");
11411141

11421142
Map.Entry<SearchResult, Map<String, Object>> profile
11431143
= client.ftProfileSearch(index, FTProfileParams.profileParams(),
@@ -1171,10 +1171,10 @@ public void deepReplySearchProfile() {
11711171
@Test
11721172
public void limitedSearchProfile() {
11731173
assertOK(client.ftCreate(index, TextField.of("t")));
1174-
client.hset("1", Collections.singletonMap("t", "hello"));
1175-
client.hset("2", Collections.singletonMap("t", "hell"));
1176-
client.hset("3", Collections.singletonMap("t", "help"));
1177-
client.hset("4", Collections.singletonMap("t", "helowa"));
1174+
client.hset("1", "t", "hello");
1175+
client.hset("2", "t", "hell");
1176+
client.hset("3", "t", "help");
1177+
client.hset("4", "t", "helowa");
11781178

11791179
Map.Entry<SearchResult, Map<String, Object>> profile = client.ftProfileSearch(index,
11801180
FTProfileParams.profileParams().limited(), "%hell% hel*", FTSearchParams.searchParams().noContent());

0 commit comments

Comments
 (0)