2
2
3
3
import redis .clients .jedis .Builder ;
4
4
5
+ import java .util .HashMap ;
5
6
import java .util .List ;
7
+ import java .util .Map ;
6
8
7
- import static redis .clients .jedis .BuilderFactory .STRING_LIST ;
8
9
import static redis .clients .jedis .BuilderFactory .LONG ;
10
+ import static redis .clients .jedis .BuilderFactory .STRING ;
11
+ import static redis .clients .jedis .BuilderFactory .STRING_LIST ;
9
12
10
13
public class CommandInfo {
14
+
15
+ private final String name ;
11
16
private final long arity ;
12
17
private final List <String > flags ;
13
18
private final long firstKey ;
14
19
private final long lastKey ;
15
20
private final long step ;
16
21
private final List <String > aclCategories ;
17
22
private final List <String > tips ;
18
- private final List <String > subcommands ;
23
+ private final Map <String , CommandInfo > subcommands ;
19
24
25
+ /**
26
+ * THIS IGNORES 'subcommands' parameter.
27
+ * @param subcommands WILL BE IGNORED
28
+ * @deprecated
29
+ */
30
+ @ Deprecated
20
31
public CommandInfo (long arity , List <String > flags , long firstKey , long lastKey , long step ,
21
32
List <String > aclCategories , List <String > tips , List <String > subcommands ) {
33
+ this ((String ) null , arity , flags , firstKey , lastKey , step , aclCategories , tips , (Map ) null );
34
+ }
35
+
36
+ private CommandInfo (String name , long arity , List <String > flags , long firstKey , long lastKey , long step ,
37
+ List <String > aclCategories , List <String > tips , Map <String , CommandInfo > subcommands ) {
38
+ this .name = name ;
22
39
this .arity = arity ;
23
40
this .flags = flags ;
24
41
this .firstKey = firstKey ;
@@ -29,6 +46,13 @@ public CommandInfo(long arity, List<String> flags, long firstKey, long lastKey,
29
46
this .subcommands = subcommands ;
30
47
}
31
48
49
+ /**
50
+ * Command name
51
+ */
52
+ public String getName () {
53
+ return name ;
54
+ }
55
+
32
56
/**
33
57
* Arity is the number of arguments a command expects. It follows a simple pattern:
34
58
* A positive integer means a fixed number of arguments.
@@ -89,25 +113,55 @@ public List<String> getTips() {
89
113
/**
90
114
* All the command's subcommands, if any
91
115
*/
92
- public List <String > getSubcommands () {
116
+ public Map <String , CommandInfo > getSubcommands () {
93
117
return subcommands ;
94
118
}
95
119
96
120
public static final Builder <CommandInfo > COMMAND_INFO_BUILDER = new Builder <CommandInfo >() {
97
121
@ Override
98
122
public CommandInfo build (Object data ) {
123
+ if (data == null ) {
124
+ return null ;
125
+ }
126
+
99
127
List <Object > commandData = (List <Object >) data ;
128
+ if (commandData .isEmpty ()) {
129
+ return null ;
130
+ }
100
131
132
+ String name = STRING .build (commandData .get (0 ));
101
133
long arity = LONG .build (commandData .get (1 ));
102
134
List <String > flags = STRING_LIST .build (commandData .get (2 ));
103
135
long firstKey = LONG .build (commandData .get (3 ));
104
136
long lastKey = LONG .build (commandData .get (4 ));
105
137
long step = LONG .build (commandData .get (5 ));
106
138
List <String > aclCategories = STRING_LIST .build (commandData .get (6 ));
107
139
List <String > tips = STRING_LIST .build (commandData .get (7 ));
108
- List <String > subcommands = STRING_LIST .build (commandData .get (9 ));
140
+ Map <String , CommandInfo > subcommands = COMMAND_INFO_RESPONSE .build (commandData .get (9 ));
141
+
142
+ return new CommandInfo (name , arity , flags , firstKey , lastKey , step , aclCategories , tips , subcommands );
143
+ }
144
+ };
109
145
110
- return new CommandInfo (arity , flags , firstKey , lastKey , step , aclCategories , tips , subcommands );
146
+ public static final Builder <Map <String , CommandInfo >> COMMAND_INFO_RESPONSE = new Builder <Map <String , CommandInfo >>() {
147
+ @ Override
148
+ public Map <String , CommandInfo > build (Object data ) {
149
+ if (data == null ) {
150
+ return null ;
151
+ }
152
+
153
+ List <Object > rawList = (List <Object >) data ;
154
+ Map <String , CommandInfo > map = new HashMap <>(rawList .size ());
155
+
156
+ for (Object rawCommandInfo : rawList ) {
157
+ CommandInfo info = CommandInfo .COMMAND_INFO_BUILDER .build (rawCommandInfo );
158
+ if (info != null ) {
159
+ map .put (info .getName (), info );
160
+ }
161
+ }
162
+
163
+ return map ;
111
164
}
112
165
};
166
+
113
167
}
0 commit comments