@@ -64,12 +64,14 @@ private enum Command implements ProtocolCommand {
6464 ARRLEN ("JSON.ARRLEN" ),
6565 ARRPOP ("JSON.ARRPOP" ),
6666 ARRTRIM ("JSON.ARRTRIM" );
67+
6768 private final byte [] raw ;
6869
6970 Command (String alt ) {
7071 raw = SafeEncoder .encode (alt );
7172 }
7273
74+ @ Override
7375 public byte [] getRaw () {
7476 return raw ;
7577 }
@@ -82,12 +84,14 @@ public enum ExistenceModifier implements ProtocolCommand {
8284 DEFAULT ("" ),
8385 NOT_EXISTS ("NX" ),
8486 MUST_EXIST ("XX" );
87+
8588 private final byte [] raw ;
8689
8790 ExistenceModifier (String alt ) {
8891 raw = SafeEncoder .encode (alt );
8992 }
9093
94+ @ Override
9195 public byte [] getRaw () {
9296 return raw ;
9397 }
@@ -121,23 +125,14 @@ public JReJSON(Pool<Jedis> jedis) {
121125 this .client = jedis ;
122126 }
123127
124- /**
125- * Helper to check for errors and throw them as an exception
126- * @param str the reply string to "analyze"
127- * @throws RuntimeException
128- */
129- private static void assertReplyNotError (final String str ) {
130- if (str .startsWith ("-ERR" ))
131- throw new RuntimeException (str .substring (5 ));
132- }
133-
134128 /**
135129 * Helper to check for an OK reply
136130 * @param str the reply string to "scrutinize"
137131 */
138132 private static void assertReplyOK (final String str ) {
139- if (!str .equals ("OK" ))
140- throw new RuntimeException (str );
133+ if (str == null ) {
134+ throw new NullPointerException ("Null response received." );
135+ }
141136 }
142137
143138 /**
@@ -227,7 +222,7 @@ public <T> T get(String key, Class<T> clazz, Path... paths) {
227222 conn .getClient ().sendCommand (Command .GET , args );
228223 rep = conn .getClient ().getBulkReply ();
229224 }
230- assertReplyNotError ( rep );
225+
231226 return gson .fromJson (rep , clazz );
232227 }
233228
@@ -356,8 +351,6 @@ public Class<?> type(String key, Path path) {
356351 rep = conn .getClient ().getBulkReply ();
357352 }
358353
359- assertReplyNotError (rep );
360-
361354 switch (rep ) {
362355 case "null" :
363356 return null ;
@@ -374,7 +367,7 @@ public Class<?> type(String key, Path path) {
374367 case "array" :
375368 return List .class ;
376369 default :
377- throw new java . lang . RuntimeException (rep );
370+ throw new RuntimeException (rep );
378371 }
379372 }
380373
@@ -425,7 +418,6 @@ public static Object get(Jedis conn, String key, Path... paths) {
425418 String rep = conn .getClient ().getBulkReply ();
426419 conn .close ();
427420
428- assertReplyNotError (rep );
429421 return gson .fromJson (rep , Object .class );
430422 }
431423
@@ -492,8 +484,6 @@ public static Class<?> type(Jedis conn, String key, Path... path) {
492484 String rep = conn .getClient ().getBulkReply ();
493485 conn .close ();
494486
495- assertReplyNotError (rep );
496-
497487 switch (rep ) {
498488 case "null" :
499489 return null ;
@@ -510,7 +500,7 @@ public static Class<?> type(Jedis conn, String key, Path... path) {
510500 case "array" :
511501 return List .class ;
512502 default :
513- throw new java . lang . RuntimeException (rep );
503+ throw new RuntimeException (rep );
514504 }
515505 }
516506
@@ -533,7 +523,7 @@ private Jedis getConnection() {
533523 public Long strAppend (String key , Path path , Object ... objects ) {
534524 List <byte []> args = new ArrayList <>();
535525 args .add (SafeEncoder .encode (key ));
536- args .add (SafeEncoder .encode (getSingleOptionalPath ( path ) .toString ()));
526+ args .add (SafeEncoder .encode (path .toString ()));
537527
538528 args .addAll (Arrays .stream (objects ) //
539529 .map (object -> SafeEncoder .encode (gson .toJson (object ))) //
@@ -698,7 +688,7 @@ public <T> T arrPop(String key, Class<T> clazz, Path path, Long index) {
698688 conn .getClient ().sendCommand (Command .ARRPOP , args .toArray (new byte [args .size ()][]));
699689 rep = conn .getClient ().getBulkReply ();
700690 }
701- assertReplyNotError ( rep );
691+
702692 return gson .fromJson (rep , clazz );
703693 }
704694
0 commit comments