11package io .rejson ;
22
3- import redis .clients .jedis .Jedis ;
4- import redis .clients .jedis .JedisPool ;
5- import redis .clients .jedis .JedisPoolConfig ;
6-
73import com .google .gson .Gson ;
8- import redis .clients .jedis .Pipeline ;
9- import redis .clients .jedis .commands .* ;
4+ import redis .clients .jedis .Jedis ;
5+ import redis .clients .jedis .commands .ProtocolCommand ;
106import redis .clients .util .SafeEncoder ;
117
12- import java .util .*;
8+ import java .util .ArrayList ;
9+ import java .util .List ;
1310
1411/**
1512 * JReJSON is the main ReJSON client class, wrapping connection management and all ReJSON commands
1613 */
17- public class JReJSON extends Jedis implements JedisCommands , MultiKeyCommands , AdvancedJedisCommands , ScriptingCommands , BasicCommands , ClusterCommands , SentinelCommands , ModuleCommands ,IJReJSON {
18-
19- private JedisPool pool ;
20- private Gson gson ;
21-
22- Jedis _conn () {
23- return pool .getResource ();
24- }
14+ public class JReJSON {
2515
26- @ Override
27- public Object JSONGet (String key ) {
28-
29-
30- return null ;
31- }
16+ private static Gson gson = new Gson ();
3217
3318 private enum Command implements ProtocolCommand {
3419 DEL ("JSON.DEL" ),
@@ -67,9 +52,9 @@ public byte[] getRaw() {
6752 /**
6853 * Helper to check for errors and throw them as an exception
6954 * @param str the reply string to "analyze"
70- * @throws Exception
55+ * @throws RuntimeException
7156 */
72- private void assertReplyNotError (final String str ) {
57+ private static void assertReplyNotError (final String str ) {
7358 if (str .startsWith ("-ERR" ))
7459 throw new RuntimeException (str .substring (5 ));
7560 }
@@ -78,7 +63,7 @@ private void assertReplyNotError(final String str) {
7863 * Helper to check for an OK reply
7964 * @param str the reply string to "scrutinize"
8065 */
81- private void assertReplyOK (final String str ) {
66+ private static void assertReplyOK (final String str ) {
8267 if (!str .equals ("OK" ))
8368 throw new RuntimeException (str );
8469 }
@@ -88,61 +73,30 @@ private void assertReplyOK(final String str) {
8873 * @param path a single optional path
8974 * @return the provided path or root if not
9075 */
91- private Path getSingleOptionalPath (Path ... path ) {
76+ private static Path getSingleOptionalPath (Path ... path ) {
9277 // check for 0, 1 or more paths
93- if (1 > path .length ) {
78+ if (1 > path .length )
9479 // default to root
9580 return Path .RootPath ();
96- } else if (1 == path .length ){
81+ else if (1 == path .length )
9782 // take 1
9883 return path [0 ];
99- } else {
84+ else
10085 // throw out the baby with the water
10186 throw new RuntimeException ("Only a single optional path is allowed" );
102- }
103- }
104-
105- /**
106- * Create a new client
107- * @param host the Redis host
108- * @param port the Redis port
109- * @param timeout the timeout
110- * @param poolSize the pool's size
111- */
112- public JReJSON (String host , int port , int timeout , int poolSize ) {
113- JedisPoolConfig conf = new JedisPoolConfig ();
114- conf .setMaxTotal (poolSize );
115- conf .setTestOnBorrow (false );
116- conf .setTestOnReturn (false );
117- conf .setTestOnCreate (false );
118- conf .setTestWhileIdle (false );
119- conf .setMinEvictableIdleTimeMillis (60000 );
120- conf .setTimeBetweenEvictionRunsMillis (30000 );
121- conf .setNumTestsPerEvictionRun (-1 );
122- conf .setFairness (true );
123-
124- pool = new JedisPool (conf , host , port , timeout );
125- gson = new Gson ();
12687
12788 }
12889
129- /**
130- * Create a new client with default timeout and poolSize
131- * @param host the Redis host
132- * @param port the Redis port
133- */
134- public JReJSON (String host , int port ) {
135- this (host , port , 500 , 100 );
136- }
90+
13791
13892 /**
13993 * Deletes a path
14094 * @param key the key name
14195 * @param path optional single path in the object, defaults to root
14296 * @return the number of paths deleted (0 or 1)
14397 */
144- public Long del (String key , Path ... path ) {
145- Jedis conn = _conn ();
98+ public static Long del (Jedis conn , String key , Path ... path ) {
99+
146100 ArrayList <byte []> args = new ArrayList (2 );
147101
148102 args .add (SafeEncoder .encode (key ));
@@ -162,8 +116,8 @@ public Long del(String key, Path... path) {
162116 * @param paths optional one ore more paths in the object, defaults to root
163117 * @return the requested object
164118 */
165- public Object get (String key , Path ... paths ) {
166- Jedis conn = _conn ();
119+ public static Object get (Jedis conn , String key , Path ... paths ) {
120+
167121 ArrayList <byte []> args = new ArrayList (2 );
168122
169123 args .add (SafeEncoder .encode (key ));
@@ -189,8 +143,8 @@ public Object get(String key, Path... paths) {
189143 * @param flag an existential modifier
190144 * @param path optional single path in the object, defaults to root
191145 */
192- public void set (String key , Object object , ExistenceModifier flag , Path ... path ) {
193- Jedis conn = _conn ();
146+ public static void set (Jedis conn , String key , Object object , ExistenceModifier flag , Path ... path ) {
147+
194148 ArrayList <byte []> args = new ArrayList (4 );
195149
196150 args .add (SafeEncoder .encode (key ));
@@ -214,8 +168,8 @@ public void set(String key, Object object, ExistenceModifier flag, Path... path)
214168 * @param object the Java object to store
215169 * @param path optional single path in the object, defaults to root
216170 */
217- public void set (String key , Object object , Path ... path ) {
218- this . set (key , object , ExistenceModifier .DEFAULT , path );
171+ public static void set (Jedis conn , String key , Object object , Path ... path ) {
172+ set (conn , key , object , ExistenceModifier .DEFAULT , path );
219173 }
220174
221175 /**
@@ -224,10 +178,12 @@ public void set(String key, Object object, Path... path) {
224178 * @param path optional single path in the object, defaults to root
225179 * @return the Java class of the requested object
226180 */
227- public Class <? extends Object > type (String key , Path ... path ) {
228- Jedis conn = _conn ();
181+ public static Class <? extends Object > type (Jedis conn , String key , Path ... path ) {
182+
229183 ArrayList <byte []> args = new ArrayList (2 );
230184
185+
186+
231187 args .add (SafeEncoder .encode (key ));
232188 args .add (SafeEncoder .encode (getSingleOptionalPath (path ).toString ()));
233189
0 commit comments