Skip to content

Commit 2325e21

Browse files
andy-stark-redisggivouglide
authored
DOC-5842 modified index/query example to support runnable notebook (#4335)
Co-authored-by: Ivo Gaydazhiev <ivo.gaydazhiev@redis.com> Co-authored-by: Igor Malinovskiy <u.glide@gmail.com>
1 parent a017ce0 commit 2325e21

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/test/java/io/redis/examples/HomeJsonExample.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// EXAMPLE: java_home_json
2+
// BINDER_ID jedis-java_home_json
23
// REMOVE_START
34
package io.redis.examples;
45

@@ -20,22 +21,10 @@
2021
import java.util.Map;
2122
// STEP_END
2223

23-
// HIDE_START
2424
public class HomeJsonExample {
2525

2626
@Test
2727
public void run() {
28-
// HIDE_END
29-
// STEP_START connect
30-
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
31-
// STEP_END
32-
33-
//REMOVE_START
34-
// Clear the indexes and keys here before using them in tests.
35-
try {jedis.ftDropIndex("idx:users");} catch (JedisDataException j){}
36-
try {jedis.ftDropIndex("hash-idx:users");} catch (JedisDataException j){}
37-
jedis.del("user:1", "user:2", "user:3", "huser:1", "huser:2", "huser:3");
38-
//REMOVE_END
3928

4029
// STEP_START create_data
4130
JSONObject user1 = new JSONObject()
@@ -57,6 +46,15 @@ public void run() {
5746
.put("city", "Tel Aviv");
5847
// STEP_END
5948

49+
// STEP_START connect
50+
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
51+
// STEP_END
52+
53+
// STEP_START cleanup_json
54+
try {jedis.ftDropIndex("idx:users");} catch (JedisDataException j){}
55+
jedis.del("user:1", "user:2", "user:3");
56+
// STEP_END
57+
6058
// STEP_START make_index
6159
SchemaField[] schema = {
6260
TextField.of("$.name").as("name"),
@@ -151,6 +149,11 @@ public void run() {
151149
.sorted().toArray());
152150
// REMOVE_END
153151

152+
// STEP_START cleanup_hash
153+
try {jedis.ftDropIndex("hash-idx:users");} catch (JedisDataException j){}
154+
jedis.del("huser:1", "huser:2", "huser:3");
155+
// STEP_END
156+
154157
// STEP_START make_hash_index
155158
SchemaField[] hashSchema = {
156159
TextField.of("name"),
@@ -223,9 +226,9 @@ public void run() {
223226
assertEquals("huser:3", paulHashDocs.get(0).getId());
224227
// REMOVE_END
225228

226-
// HIDE_START
229+
// STEP_START close
227230
jedis.close();
231+
// STEP_END
228232
}
229233
}
230-
// HIDE_END
231234

0 commit comments

Comments
 (0)