Skip to content

Commit 19556cc

Browse files
DOC-5838 updated Jedis landing example
1 parent 5422c13 commit 19556cc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// EXAMPLE: landing
2+
// BINDER_ID jedis-landing
3+
// STEP_START import
4+
import redis.clients.jedis.UnifiedJedis;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
// STEP_END
8+
9+
public class LandingExample {
10+
11+
@Test
12+
public void run() {
13+
// STEP_START connect
14+
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
15+
// STEP_END
16+
17+
// STEP_START set_get_string
18+
String res1 = jedis.set("bike:1", "Deimos");
19+
System.out.println(res1); // >>> OK
20+
21+
String res2 = jedis.get("bike:1");
22+
System.out.println(res2); // >>> Deimos
23+
// STEP_END
24+
25+
// STEP_START set_get_hash
26+
Map<String, String> hash = new HashMap<>();
27+
hash.put("name", "John");
28+
hash.put("surname", "Smith");
29+
hash.put("company", "Redis");
30+
hash.put("age", "29");
31+
32+
Long res3 = jedis.hset("user-session:123", hash);
33+
System.out.println(res3); // >>> 4
34+
35+
Map<String, String> res4 = jedis.hgetAll("user-session:123");
36+
System.out.println(res4);
37+
// >>> {name=John, surname=Smith, company=Redis, age=29}
38+
// STEP_END
39+
40+
// STEP_START close
41+
jedis.close();
42+
// STEP_END
43+
}
44+
}

0 commit comments

Comments
 (0)