4
4
import java .nio .charset .Charset ;
5
5
import java .nio .charset .StandardCharsets ;
6
6
import java .util .ArrayList ;
7
+ import java .util .Collections ;
7
8
import java .util .List ;
8
9
import java .util .Locale ;
9
10
@@ -49,6 +50,8 @@ public final class Protocol {
49
50
public static final byte [] POSITIVE_INFINITY_BYTES = "+inf" .getBytes ();
50
51
public static final byte [] NEGATIVE_INFINITY_BYTES = "-inf" .getBytes ();
51
52
53
+ static final List <KeyValue > PROTOCOL_EMPTY_MAP = Collections .unmodifiableList (new ArrayList <>(0 ));
54
+
52
55
private static final String ASK_PREFIX = "ASK " ;
53
56
private static final String MOVED_PREFIX = "MOVED " ;
54
57
private static final String CLUSTERDOWN_PREFIX = "CLUSTERDOWN " ;
@@ -192,7 +195,6 @@ private static byte[] processBulkReply(final RedisInputStream is) {
192
195
}
193
196
194
197
private static List <Object > processMultiBulkReply (final RedisInputStream is ) {
195
- // private static List<Object> processMultiBulkReply(final int num, final RedisInputStream is) {
196
198
final int num = is .readIntCrLf ();
197
199
if (num == -1 ) return null ;
198
200
final List <Object > ret = new ArrayList <>(num );
@@ -206,16 +208,20 @@ private static List<Object> processMultiBulkReply(final RedisInputStream is) {
206
208
return ret ;
207
209
}
208
210
209
- // private static List<Object> processMultiBulkReply(final RedisInputStream is) {
210
- // private static List<Object> processMultiBulkReply(final int num, final RedisInputStream is) {
211
211
private static List <KeyValue > processMapKeyValueReply (final RedisInputStream is ) {
212
212
final int num = is .readIntCrLf ();
213
- if (num == -1 ) return null ;
214
- final List <KeyValue > ret = new ArrayList <>(num );
215
- for (int i = 0 ; i < num ; i ++) {
216
- ret .add (new KeyValue (process (is ), process (is )));
213
+ switch (num ) {
214
+ case -1 :
215
+ return null ;
216
+ case 0 :
217
+ return PROTOCOL_EMPTY_MAP ;
218
+ default :
219
+ final List <KeyValue > ret = new ArrayList <>(num );
220
+ for (int i = 0 ; i < num ; i ++) {
221
+ ret .add (new KeyValue (process (is ), process (is )));
222
+ }
223
+ return ret ;
217
224
}
218
- return ret ;
219
225
}
220
226
221
227
public static Object read (final RedisInputStream is ) {
0 commit comments