Skip to content

Commit d969716

Browse files
committed
added extedned and implements
1 parent 54072c9 commit d969716

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package io.rejson;
2+
3+
/**
4+
* Created by guylubovitch on 4/30/17.
5+
*/
6+
public interface IJReJSON {
7+
8+
public Object JSONGet(String key);
9+
10+
}
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
import redis.clients.jedis.JedisPoolConfig;
66

77
import com.google.gson.Gson;
8-
import redis.clients.jedis.commands.ProtocolCommand;
8+
import redis.clients.jedis.Pipeline;
9+
import redis.clients.jedis.commands.*;
910
import redis.clients.util.SafeEncoder;
1011

1112
import java.util.*;
1213

1314
/**
14-
* Client is the main ReJSON client class, wrapping connection management and all ReJSON commands
15+
* JReJSON is the main ReJSON client class, wrapping connection management and all ReJSON commands
1516
*/
16-
public class Client {
17+
public class JReJSON extends Jedis implements JedisCommands, MultiKeyCommands, AdvancedJedisCommands, ScriptingCommands, BasicCommands, ClusterCommands, SentinelCommands, ModuleCommands,IJReJSON {
1718

1819
private JedisPool pool;
1920
private Gson gson;
@@ -22,6 +23,13 @@ Jedis _conn() {
2223
return pool.getResource();
2324
}
2425

26+
@Override
27+
public Object JSONGet(String key) {
28+
29+
30+
return null;
31+
}
32+
2533
private enum Command implements ProtocolCommand {
2634
DEL("JSON.DEL"),
2735
GET("JSON.GET"),
@@ -101,7 +109,7 @@ private Path getSingleOptionalPath(Path... path) {
101109
* @param timeout the timeout
102110
* @param poolSize the pool's size
103111
*/
104-
public Client(String host, int port, int timeout, int poolSize) {
112+
public JReJSON(String host, int port, int timeout, int poolSize) {
105113
JedisPoolConfig conf = new JedisPoolConfig();
106114
conf.setMaxTotal(poolSize);
107115
conf.setTestOnBorrow(false);
@@ -123,7 +131,7 @@ public Client(String host, int port, int timeout, int poolSize) {
123131
* @param host the Redis host
124132
* @param port the Redis port
125133
*/
126-
public Client(String host, int port) {
134+
public JReJSON(String host, int port) {
127135
this(host, port, 500, 100);
128136
}
129137

@@ -249,4 +257,9 @@ public Class<? extends Object> type(String key, Path... path) {
249257
throw new java.lang.RuntimeException(rep);
250258
}
251259
}
260+
@Override
261+
public Pipeline pipelined()
262+
{
263+
264+
}
252265
}

src/test/java/io/rejson/ClientTest.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import org.junit.Before;
66
import org.junit.Test;
7+
import redis.clients.jedis.JedisPool;
8+
import redis.clients.jedis.JedisPoolConfig;
9+
import redis.clients.jedis.Pipeline;
710

811
import static junit.framework.TestCase.*;
912

@@ -28,13 +31,13 @@ public IRLObject() {
2831

2932
public class ClientTest {
3033

31-
private Client c;
34+
private JReJSON c;
3235
private Gson g;
3336

3437
@Before
3538
public void initialize() {
3639
g = new Gson();
37-
c = new Client("localhost", 6379);
40+
c = new JReJSON("localhost", 6379);
3841
}
3942

4043
@Test
@@ -67,7 +70,7 @@ public void setExistingPathOnlyIfExistsShouldSucceed() throws Exception {
6770

6871
c.set("obj", new IRLObject());
6972
Path p = new Path(".str");
70-
c.set("obj", "strangle", Client.ExistenceModifier.MUST_EXIST, p);
73+
c.set("obj", "strangle", JReJSON.ExistenceModifier.MUST_EXIST, p);
7174
assertEquals("strangle", c.get("obj", p));
7275
}
7376

@@ -77,7 +80,7 @@ public void setNonExistingOnlyIfNotExistsShouldSucceed() throws Exception {
7780

7881
c.set("obj", new IRLObject());
7982
Path p = new Path(".none");
80-
c.set("obj", "strangle", Client.ExistenceModifier.NOT_EXISTS, p);
83+
c.set("obj", "strangle", JReJSON.ExistenceModifier.NOT_EXISTS, p);
8184
assertEquals("strangle", c.get("obj", p));
8285
}
8386

@@ -87,7 +90,7 @@ public void setExistingPathOnlyIfNotExistsShouldFail() throws Exception {
8790

8891
c.set("obj", new IRLObject());
8992
Path p = new Path(".str");
90-
c.set("obj", "strangle", Client.ExistenceModifier.NOT_EXISTS, p);
93+
c.set("obj", "strangle", JReJSON.ExistenceModifier.NOT_EXISTS, p);
9194
}
9295

9396
@Test(expected = Exception.class)
@@ -96,7 +99,7 @@ public void setNonExistingPathOnlyIfExistsShouldFail() throws Exception {
9699

97100
c.set("obj", new IRLObject());
98101
Path p = new Path(".none");
99-
c.set("obj", "strangle", Client.ExistenceModifier.MUST_EXIST, p);
102+
c.set("obj", "strangle", JReJSON.ExistenceModifier.MUST_EXIST, p);
100103
}
101104

102105
@Test(expected = Exception.class)
@@ -175,4 +178,33 @@ public void typeException() throws Exception {
175178
c.type("foobar", new Path(".foo[1]"));
176179
}
177180

181+
@Test(expected = Exception.class)
182+
public void type1Exception() throws Exception {
183+
c._conn().flushDB();
184+
c.set("foobar", new FooBarObject(), Path.RootPath());
185+
c.type("foobar", new Path(".foo[1]"));
186+
187+
JedisPoolConfig conf = new JedisPoolConfig();
188+
conf.setMaxTotal(poolSize);
189+
conf.setTestOnBorrow(false);
190+
conf.setTestOnReturn(false);
191+
conf.setTestOnCreate(false);
192+
conf.setTestWhileIdle(false);
193+
conf.setMinEvictableIdleTimeMillis(60000);
194+
conf.setTimeBetweenEvictionRunsMillis(30000);
195+
conf.setNumTestsPerEvictionRun(-1);
196+
conf.setFairness(true);
197+
198+
JedisPool pool = new JedisPool(conf, "localhost", 6379,1000);
199+
200+
JReJSON jReJSON = (JReJSON) pool.getResource();
201+
202+
203+
204+
//Pipeline pipe = jReJSON.pipelined();
205+
206+
207+
}
208+
209+
178210
}

src/test/java/io/rejson/UsageExampleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
public class UsageExampleTest {
88
@Before
99
public void initialize() {
10-
Client c = new Client("localhost", 6379);
10+
JReJSON c = new JReJSON("localhost", 6379);
1111
c._conn().flushDB();
1212
}
1313

1414
@Test
1515
public void exampleShouldWork() throws Exception {
1616
// Firstly, the client's initialization
17-
Client c = new Client("localhost", 6379);
17+
JReJSON c = new JReJSON("localhost", 6379);
1818

1919
// Setting a Redis key name _foo_ to the string _"bar"_, and reading it back
2020
c.set("foo", "bar");

0 commit comments

Comments
 (0)