Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions src/test/java/io/redis/examples/HomeJsonExample.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// EXAMPLE: java_home_json
// BINDER_ID jedis-java_home_json
// REMOVE_START
package io.redis.examples;

Expand All @@ -20,22 +21,10 @@
import java.util.Map;
// STEP_END

// HIDE_START
public class HomeJsonExample {

@Test
public void run() {
// HIDE_END
// STEP_START connect
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
// STEP_END

//REMOVE_START
// Clear the indexes and keys here before using them in tests.
try {jedis.ftDropIndex("idx:users");} catch (JedisDataException j){}
try {jedis.ftDropIndex("hash-idx:users");} catch (JedisDataException j){}
jedis.del("user:1", "user:2", "user:3", "huser:1", "huser:2", "huser:3");
//REMOVE_END

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

// STEP_START connect
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
// STEP_END

// STEP_START cleanup_json
try {jedis.ftDropIndex("idx:users");} catch (JedisDataException j){}
jedis.del("user:1", "user:2", "user:3");
// STEP_END

// STEP_START make_index
SchemaField[] schema = {
TextField.of("$.name").as("name"),
Expand Down Expand Up @@ -151,6 +149,11 @@ public void run() {
.sorted().toArray());
// REMOVE_END

// STEP_START cleanup_hash
try {jedis.ftDropIndex("hash-idx:users");} catch (JedisDataException j){}
jedis.del("huser:1", "huser:2", "huser:3");
// STEP_END

// STEP_START make_hash_index
SchemaField[] hashSchema = {
TextField.of("name"),
Expand Down Expand Up @@ -223,9 +226,9 @@ public void run() {
assertEquals("huser:3", paulHashDocs.get(0).getId());
// REMOVE_END

// HIDE_START
// STEP_START close
jedis.close();
// STEP_END
}
}
// HIDE_END

Loading