Skip to content

Commit a50568a

Browse files
authored
Merge branch 'redis:master' into MultiNodePipelineExecutor
2 parents c196d7a + 3e537f9 commit a50568a

File tree

6 files changed

+446
-16
lines changed

6 files changed

+446
-16
lines changed

Diff for: .github/workflows/test-on-docker.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ jobs:
4141
- "7.2.6"
4242
# - "6.2.16"
4343
steps:
44-
- uses: actions/checkout@v2
44+
- uses: actions/checkout@v4
4545
- name: Set up publishing to maven central
46-
uses: actions/setup-java@v2
46+
uses: actions/setup-java@v4
4747
with:
4848
java-version: '8'
4949
distribution: 'temurin'
@@ -53,7 +53,7 @@ jobs:
5353
sudo apt install -y make
5454
make compile-module
5555
- name: Cache dependencies
56-
uses: actions/cache@v2
56+
uses: actions/cache@v4
5757
with:
5858
path: |
5959
~/.m2/repository
@@ -124,7 +124,7 @@ jobs:
124124
continue-on-error: true
125125
# Upload code coverage
126126
- name: Upload coverage to Codecov
127-
uses: codecov/codecov-action@v4
127+
uses: codecov/codecov-action@v5
128128
with:
129129
fail_ci_if_error: false
130130
token: ${{ secrets.CODECOV_TOKEN }}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// EXAMPLE: cmds_cnxmgmt
2+
// REMOVE_START
3+
package io.redis.examples;
4+
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
// REMOVE_END
8+
9+
import redis.clients.jedis.Jedis;
10+
11+
// HIDE_START
12+
public class CmdsCnxmgmtExample {
13+
@Test
14+
public void run() {
15+
// HIDE_END
16+
Jedis jedis = new Jedis("redis://localhost:6379");
17+
18+
// STEP_START auth1
19+
// REMOVE_START
20+
jedis.configSet("requirepass", "temp_pass");
21+
// REMOVE_END
22+
// Note: you must use the `Jedis` class rather than `UnifiedJedis`
23+
// to access the `auth` commands.
24+
String authResult1 = jedis.auth("default", "temp_pass");
25+
System.out.println(authResult1); // >>> OK
26+
// REMOVE_START
27+
Assert.assertEquals("OK", authResult1);
28+
jedis.configSet("requirepass", "");
29+
// REMOVE_END
30+
// STEP_END
31+
32+
// STEP_START auth2
33+
// REMOVE_START
34+
jedis.aclSetUser("test-user", "on", ">strong_password", "+acl");
35+
// REMOVE_END
36+
// Note: you must use the `Jedis` class rather than `UnifiedJedis`
37+
// to access the `auth` commands.
38+
String authResult2 = jedis.auth("test-user", "strong_password");
39+
System.out.println(authResult2); // >>> OK
40+
// REMOVE_START
41+
Assert.assertEquals("OK", authResult2);
42+
jedis.aclDelUser("test-user");
43+
// REMOVE_END
44+
// STEP_END
45+
46+
// HIDE_START
47+
}
48+
}
49+
// HIDE_END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// EXAMPLE: cmds_servermgmt
2+
// REMOVE_START
3+
package io.redis.examples;
4+
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
// REMOVE_END
8+
import java.util.Set;
9+
10+
import redis.clients.jedis.Jedis;
11+
// HIDE_START
12+
import redis.clients.jedis.UnifiedJedis;
13+
14+
public class CmdsServerMgmtExample {
15+
@Test
16+
public void run() {
17+
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
18+
// HIDE_END
19+
20+
// STEP_START flushall
21+
// REMOVE_START
22+
jedis.set("testkey1", "1");
23+
jedis.set("testkey2", "2");
24+
jedis.set("testkey3", "3");
25+
// REMOVE_END
26+
String flushAllResult1 = jedis.flushAll();
27+
System.out.println(flushAllResult1); // >>> OK
28+
29+
Set<String> flushAllResult2 = jedis.keys("*");
30+
System.out.println(flushAllResult2); // >>> []
31+
// STEP_END
32+
// REMOVE_START
33+
Assert.assertEquals("OK", flushAllResult1);
34+
Assert.assertEquals("[]", flushAllResult2.toString());
35+
// REMOVE_END
36+
37+
// STEP_START info
38+
// Note: you must use the `Jedis` class to access the `info`
39+
// command rather than `UnifiedJedis`.
40+
Jedis jedis2 = new Jedis("redis://localhost:6379");
41+
42+
String infoResult = jedis2.info();
43+
44+
// Check the first 8 characters of the result (the full `info` string
45+
// is much longer than this).
46+
System.out.println(infoResult.substring(0, 8)); // >>> # Server
47+
48+
jedis2.close();
49+
// STEP_END
50+
// REMOVE_START
51+
Assert.assertEquals("# Server", infoResult.substring(0, 8));
52+
// REMOVE_END
53+
54+
// HIDE_START
55+
jedis.close();
56+
}
57+
}
58+
// HIDE_END

Diff for: src/test/java/io/redis/examples/GeoIndexExample.java

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// EXAMPLE: geoindex
2+
// REMOVE_START
3+
package io.redis.examples;
4+
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
// REMOVE_END
8+
9+
// HIDE_START
10+
import org.json.JSONObject;
11+
12+
import redis.clients.jedis.UnifiedJedis;
13+
import redis.clients.jedis.json.Path2;
14+
import redis.clients.jedis.search.Document;
15+
import redis.clients.jedis.search.FTCreateParams;
16+
import redis.clients.jedis.search.FTSearchParams;
17+
import redis.clients.jedis.search.IndexDataType;
18+
import redis.clients.jedis.search.schemafields.*;
19+
import redis.clients.jedis.search.schemafields.GeoShapeField.CoordinateSystem;
20+
import redis.clients.jedis.search.SearchResult;
21+
import redis.clients.jedis.exceptions.JedisDataException;
22+
// HIDE_END
23+
24+
// HIDE_START
25+
public class GeoIndexExample {
26+
27+
@Test
28+
public void run() {
29+
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
30+
//REMOVE_START
31+
// Clear any keys here before using them in tests.
32+
try {
33+
jedis.ftDropIndex("productidx");
34+
} catch (JedisDataException j) {}
35+
36+
try {
37+
jedis.ftDropIndex("geomidx");
38+
} catch (JedisDataException j) {}
39+
40+
jedis.del("product:46885", "product:46886", "shape:1", "shape:2", "shape:3", "shape:4");
41+
//REMOVE_END
42+
// HIDE_END
43+
44+
// STEP_START create_geo_idx
45+
SchemaField[] geoSchema = {
46+
GeoField.of("$.location").as("location")
47+
};
48+
49+
String geoIdxCreateResult = jedis.ftCreate("productidx",
50+
FTCreateParams.createParams()
51+
.on(IndexDataType.JSON)
52+
.addPrefix("product:"),
53+
geoSchema
54+
);
55+
// STEP_END
56+
// REMOVE_START
57+
Assert.assertEquals("OK", geoIdxCreateResult);
58+
// REMOVE_END
59+
60+
// STEP_START add_geo_json
61+
JSONObject prd46885 = new JSONObject()
62+
.put("description", "Navy Blue Slippers")
63+
.put("price", 45.99)
64+
.put("city", "Denver")
65+
.put("location", "-104.991531, 39.742043");
66+
67+
String jsonAddResult1 = jedis.jsonSet("product:46885", new Path2("$"), prd46885);
68+
System.out.println(jsonAddResult1); // >>> OK
69+
70+
JSONObject prd46886 = new JSONObject()
71+
.put("description", "Bright Green Socks")
72+
.put("price", 25.50)
73+
.put("city", "Fort Collins")
74+
.put("location", "-105.0618814,40.5150098");
75+
76+
String jsonAddResult2 = jedis.jsonSet("product:46886", new Path2("$"), prd46886);
77+
System.out.println(jsonAddResult2); // >>> OK
78+
// STEP_END
79+
// REMOVE_START
80+
Assert.assertEquals("OK", jsonAddResult1);
81+
Assert.assertEquals("OK", jsonAddResult2);
82+
// REMOVE_END
83+
84+
// STEP_START geo_query
85+
SearchResult geoResult = jedis.ftSearch("productidx",
86+
"@location:[-104.800644 38.846127 100 mi]"
87+
);
88+
89+
System.out.println(geoResult.getTotalResults()); // >>> 1
90+
91+
for (Document doc: geoResult.getDocuments()) {
92+
System.out.println(doc.getId());
93+
}
94+
// >>> product:46885
95+
// STEP_END
96+
// REMOVE_START
97+
Assert.assertEquals("OK", jsonAddResult1);
98+
Assert.assertEquals("OK", jsonAddResult2);
99+
Assert.assertEquals("product:46885", geoResult.getDocuments().get(0).getId());
100+
// REMOVE_END
101+
102+
// STEP_START create_gshape_idx
103+
SchemaField[] geomSchema = {
104+
TextField.of("$.name").as("name"),
105+
GeoShapeField.of("$.geom", CoordinateSystem.FLAT).as("geom")
106+
};
107+
108+
String geomIndexCreateResult = jedis.ftCreate("geomidx",
109+
FTCreateParams.createParams()
110+
.on(IndexDataType.JSON)
111+
.addPrefix("shape"),
112+
geomSchema
113+
);
114+
System.out.println(geomIndexCreateResult); // >>> OK
115+
// STEP_END
116+
// REMOVE_START
117+
Assert.assertEquals("OK", geomIndexCreateResult);
118+
// REMOVE_END
119+
120+
// STEP_START add_gshape_json
121+
JSONObject shape1 = new JSONObject()
122+
.put("name", "Green Square")
123+
.put("geom", "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))");
124+
125+
String gmJsonRes1 = jedis.jsonSet("shape:1", new Path2("$"), shape1);
126+
System.out.println(gmJsonRes1); // >>> OK
127+
128+
JSONObject shape2 = new JSONObject()
129+
.put("name", "Red Rectangle")
130+
.put("geom", "POLYGON ((2 2.5, 2 3.5, 3.5 3.5, 3.5 2.5, 2 2.5))");
131+
132+
String gmJsonRes2 = jedis.jsonSet("shape:2", new Path2("$"), shape2);
133+
System.out.println(gmJsonRes2); // >>> OK
134+
135+
JSONObject shape3 = new JSONObject()
136+
.put("name", "Blue Triangle")
137+
.put("geom", "POLYGON ((3.5 1, 3.75 2, 4 1, 3.5 1))");
138+
139+
String gmJsonRes3 = jedis.jsonSet("shape:3", new Path2("$"), shape3);
140+
System.out.println(gmJsonRes3); // >>> OK
141+
142+
JSONObject shape4 = new JSONObject()
143+
.put("name", "Purple Point")
144+
.put("geom", "POINT (2 2)");
145+
146+
String gmJsonRes4 = jedis.jsonSet("shape:4", new Path2("$"), shape4);
147+
System.out.println(gmJsonRes4); // >>> OK
148+
// STEP_END
149+
// REMOVE_START
150+
Assert.assertEquals("OK", gmJsonRes1);
151+
Assert.assertEquals("OK", gmJsonRes2);
152+
Assert.assertEquals("OK", gmJsonRes3);
153+
Assert.assertEquals("OK", gmJsonRes4);
154+
// REMOVE_END
155+
156+
// STEP_START gshape_query
157+
SearchResult geomResult = jedis.ftSearch("geomidx",
158+
"(-@name:(Green Square) @geom:[WITHIN $qshape])",
159+
FTSearchParams.searchParams()
160+
.addParam("qshape", "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))")
161+
.dialect(4)
162+
.limit(0, 1)
163+
);
164+
System.out.println(geomResult.getTotalResults()); // >>> 1
165+
166+
for (Document doc: geomResult.getDocuments()) {
167+
System.out.println(doc.getId());
168+
}
169+
// shape:4
170+
// STEP_END
171+
// REMOVE_START
172+
Assert.assertEquals(1, geomResult.getTotalResults());
173+
Assert.assertEquals("shape:4", geomResult.getDocuments().get(0).getId());
174+
// REMOVE_END
175+
// HIDE_START
176+
177+
jedis.close();
178+
}
179+
}
180+
// HIDE_END

0 commit comments

Comments
 (0)