File tree Expand file tree Collapse file tree 2 files changed +59
-9
lines changed
Expand file tree Collapse file tree 2 files changed +59
-9
lines changed Original file line number Diff line number Diff line change 11# JReJSON
22
3- A Java Client Library for [ ReJSON] ( https://https:// github.com/redislabsmodules/rejson )
3+ A Java Client Library for [ ReJSON] ( https://github.com/redislabsmodules/rejson )
44
55## Overview
66
7+ This client provides access to ReJSON's Redis API, and provides back-and-forth serialization between Java's and its objects.
78
89## Usage example
910
10- Initializing the client:
11+ Firstly, the client's initialization :
1112
1213``` java
14+ Client c = new Client (" localhost" , 6379 );
15+ ```
1316
14- import io.rejson.Client ;
15-
16- ...
17+ Setting a Redis key name _ foo_ to the string _ "bar"_ , and reading it back:
18+ ``` java
19+ c. set(" foo" , " bar" );
20+ String s0 = (String ) c. get(" foo" );
21+ ```
1722
18- Client client = new Client ( " localhost " , 6379 );
23+ Omitting the path (usually) defaults to the root path, so the call above to ` get() ` and the following ones are basically interchangeable:
1924
25+ ``` java
26+ String s1 = (String ) c. get(" foo" , new Path (" ." ));
27+ String s2 = (String ) c. get(" foo" , Path . RootPath());
2028```
2129
22- Setting a value:
23-
24- ...
30+ Any Gson-able object can be set and updated:
31+ ``` java
32+ c. set(" obj" , new Object ()); // just an empty object
33+ c. set(" obj" , null , new Path (" .zilch" ));
34+ Path p = new Path (" .whatevs" );
35+ c. set(" obj" , true , p);
36+ c. set(" obj" , 42 , p);
37+ c. del(" obj" , p); // back to almost nothing
38+ ```
Original file line number Diff line number Diff line change 1+ package io .rejson ;
2+
3+ import org .junit .Before ;
4+ import org .junit .Test ;
5+
6+
7+ public class UsageExampleTest {
8+ @ Before
9+ public void initialize () {
10+ Client c = new Client ("localhost" , 6379 );
11+ c ._conn ().flushDB ();
12+ }
13+
14+ @ Test
15+ public void exampleShouldWork () throws Exception {
16+ // Firstly, the client's initialization
17+ Client c = new Client ("localhost" , 6379 );
18+
19+ // Setting a Redis key name _foo_ to the string _"bar"_, and reading it back
20+ c .set ("foo" , "bar" );
21+ String s0 = (String ) c .get ("foo" );
22+
23+ // Omitting the path (usually) defaults to the root path, so the call above to `get()` and the following ones
24+ // are basically interchangeable
25+ String s1 = (String ) c .get ("foo" , new Path ("." ));
26+ String s2 = (String ) c .get ("foo" , Path .RootPath ());
27+
28+ // Any Gson-able object can be set and updated
29+ c .set ("obj" , new Object ()); // just an empty object
30+ c .set ("obj" , null , new Path (".zilch" ));
31+ Path p = new Path (".whatevs" );
32+ c .set ("obj" , true , p );
33+ c .set ("obj" , 42 , p );
34+ c .del ("obj" , p ); // back to almost nothing
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments