2 // Auto-generated, do not edit.
12 G(UNKNOWN, "unknown") \
16 G(GENERIC, "generic") \
20 G(CONNECTION, "connection") \
21 G(TRANSACTIONS, "transactions") \
22 G(SORTED_SET, "sorted_set")
25 * Command group types.
29 #define G(GROUP, _) COMMAND_GROUP_##GROUP,
33 } command_group_type_t
;
36 * Command group type names.
39 static char *command_group_type_names
[] = {
40 #define G(_, STR) STR,
46 * Command help struct.
53 command_group_type_t group
;
58 "Append a value to a key",
63 "Authenticate to the server",
64 COMMAND_GROUP_CONNECTION
,
68 "Asynchronously rewrite the append-only file",
73 "Asynchronously save the dataset to disk",
77 "key [key ...] timeout",
78 "Remove and get the first element in a list, or block until one is available",
82 "key [key ...] timeout",
83 "Remove and get the last element in a list, or block until one is available",
88 "Get the value of a configuration parameter",
93 "Set a configuration parameter to the given value",
98 "Return the number of keys in the selected database",
103 "Get debugging information about a key",
104 COMMAND_GROUP_SERVER
,
106 , { "DEBUG SEGFAULT",
108 "Make the server crash",
109 COMMAND_GROUP_SERVER
,
113 "Decrement the integer value of a key by one",
114 COMMAND_GROUP_STRING
,
118 "Decrement the integer value of a key by the given number",
119 COMMAND_GROUP_STRING
,
124 COMMAND_GROUP_GENERIC
,
128 "Discard all commands issued after MULTI",
129 COMMAND_GROUP_TRANSACTIONS
,
133 "Echo the given string",
134 COMMAND_GROUP_CONNECTION
,
138 "Execute all commands issued after MULTI",
139 COMMAND_GROUP_TRANSACTIONS
,
143 "Determine if a key exists",
144 COMMAND_GROUP_SERVER
,
148 "Set a key's time to live in seconds",
149 COMMAND_GROUP_GENERIC
,
153 "Set the expiration for a key as a UNIX timestamp",
154 COMMAND_GROUP_GENERIC
,
158 "Remove all keys from all databases",
159 COMMAND_GROUP_SERVER
,
163 "Remove all keys from the current database",
164 COMMAND_GROUP_SERVER
,
168 "Get the value of a key",
169 COMMAND_GROUP_STRING
,
173 "Set the string value of a key and return its old value",
174 COMMAND_GROUP_STRING
,
178 "Delete a hash field",
183 "Determine if a hash field exists",
188 "Get the value of a hash field",
193 "Get all the fields and values in a hash",
197 "key field increment",
198 "Increment the integer value of a hash field by the given number",
203 "Get all the fields in a hash",
208 "Get the number of fields in a hash",
212 "key field [field ...]",
213 "Get the values of all the given hash fields",
217 "key field value [field value ...]",
218 "Set multiple hash fields to multiple values",
223 "Set the string value of a hash field",
228 "Set the value of a hash field, only if the field does not exist",
233 "Get all the values in a hash",
238 "Increment the integer value of a key by one",
239 COMMAND_GROUP_STRING
,
243 "Increment the integer value of a key by the given number",
244 COMMAND_GROUP_STRING
,
248 "Get information and statistics about the server",
249 COMMAND_GROUP_SERVER
,
253 "Find all keys matching the given pattern",
254 COMMAND_GROUP_GENERIC
,
258 "Get the UNIX time stamp of the last successful save to disk",
259 COMMAND_GROUP_SERVER
,
263 "Get an element from a list by its index",
267 "key BEFORE|AFTER pivot value",
268 "Insert an element before or after another element in a list",
273 "Get the length of a list",
278 "Remove and get the first element in a list",
283 "Prepend a value to a list",
288 "Prepend a value to a list, only if the list exists",
293 "Get a range of elements from a list",
298 "Remove elements from a list",
303 "Set the value of an element in a list by its index",
308 "Trim a list to the specified range",
313 "Get the values of all the given keys",
314 COMMAND_GROUP_STRING
,
318 "Listen for all requests received by the server in real time",
319 COMMAND_GROUP_SERVER
,
323 "Move a key to another database",
324 COMMAND_GROUP_GENERIC
,
327 "key value [key value ...]",
328 "Set multiple keys to multiple values",
329 COMMAND_GROUP_STRING
,
332 "key value [key value ...]",
333 "Set multiple keys to multiple values, only if none of the keys exist",
334 COMMAND_GROUP_STRING
,
338 "Mark the start of a transaction block",
339 COMMAND_GROUP_TRANSACTIONS
,
343 "Remove the expiration from a key",
344 COMMAND_GROUP_GENERIC
,
349 COMMAND_GROUP_CONNECTION
,
353 "Listen for messages published to channels matching the given patterns",
354 COMMAND_GROUP_PUBSUB
,
358 "Post a message to a channel",
359 COMMAND_GROUP_PUBSUB
,
362 "[pattern [pattern ...]]",
363 "Stop listening for messages posted to channels matching the given patterns",
364 COMMAND_GROUP_PUBSUB
,
368 "Close the connection",
369 COMMAND_GROUP_CONNECTION
,
373 "Return a random key from the keyspace",
374 COMMAND_GROUP_GENERIC
,
379 COMMAND_GROUP_GENERIC
,
383 "Rename a key, only if the new key does not exist",
384 COMMAND_GROUP_GENERIC
,
388 "Remove and get the last element in a list",
392 "source destination",
393 "Remove the last element in a list, append it to another list and return it",
398 "Append a value to a list",
403 "Append a value to a list, only if the list exists",
408 "Add a member to a set",
413 "Synchronously save the dataset to disk",
414 COMMAND_GROUP_SERVER
,
418 "Get the number of members in a set",
423 "Subtract multiple sets",
427 "destination key [key ...]",
428 "Subtract multiple sets and store the resulting set in a key",
433 "Change the selected database for the current connection",
434 COMMAND_GROUP_CONNECTION
,
438 "Set the string value of a key",
439 COMMAND_GROUP_STRING
,
442 "key timestamp value",
443 "Set the value and expiration of a key",
444 COMMAND_GROUP_STRING
,
448 "Set the value of a key, only if the key does not exist",
449 COMMAND_GROUP_STRING
,
453 "Synchronously save the dataset to disk and then shut down the server",
454 COMMAND_GROUP_SERVER
,
458 "Intersect multiple sets",
462 "destination key [key ...]",
463 "Intersect multiple sets and store the resulting set in a key",
468 "Determine if a given value is a member of a set",
473 "Make the server a slave of another instance, or promote it as master",
474 COMMAND_GROUP_SERVER
,
478 "Get all the members in a set",
482 "source destination member",
483 "Move a member from one set to another",
487 "key [BY pattern] [LIMIT start count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]",
488 "Sort the elements in a list, set or sorted set",
489 COMMAND_GROUP_GENERIC
,
493 "Remove and return a random member from a set",
498 "Get a random member from a set",
503 "Remove a member from a set",
508 "Get the length of the value stored in a key",
509 COMMAND_GROUP_STRING
,
513 "Listen for messages published to the given channels",
514 COMMAND_GROUP_PUBSUB
,
518 "Get a substring of the string stored at a key",
519 COMMAND_GROUP_STRING
,
527 "destination key [key ...]",
528 "Add multiple sets and store the resulting set in a key",
533 "Internal command used for replication",
534 COMMAND_GROUP_SERVER
,
538 "Get the time to live for a key",
539 COMMAND_GROUP_GENERIC
,
543 "Determine the type stored at key",
544 COMMAND_GROUP_GENERIC
,
547 "[channel [channel ...]]",
548 "Stop listening for messages posted to the given channels",
549 COMMAND_GROUP_PUBSUB
,
553 "Forget about all watched keys",
554 COMMAND_GROUP_TRANSACTIONS
,
558 "Watch the given keys to determine execution of the MULTI/EXEC block",
559 COMMAND_GROUP_TRANSACTIONS
,
563 "Add a member to a sorted set, or update its score if it already exists",
564 COMMAND_GROUP_SORTED_SET
,
568 "Get the number of members in a sorted set",
569 COMMAND_GROUP_SORTED_SET
,
573 "Count the members in a sorted set with scores within the given values",
574 COMMAND_GROUP_SORTED_SET
,
577 "key increment member",
578 "Increment the score of a member in a sorted set",
579 COMMAND_GROUP_SORTED_SET
,
582 "destination key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]",
583 "Intersect multiple sorted sets and store the resulting sorted set in a new key",
584 COMMAND_GROUP_SORTED_SET
,
588 "Return a range of members in a sorted set, by index",
589 COMMAND_GROUP_SORTED_SET
,
593 "Return a range of members in a sorted set, by score",
594 COMMAND_GROUP_SORTED_SET
,
598 "Determine the index of a member in a sorted set",
599 COMMAND_GROUP_SORTED_SET
,
603 "Remove a member from a sorted set",
604 COMMAND_GROUP_SORTED_SET
,
606 , { "ZREMRANGEBYRANK",
608 "Remove all members in a sorted set within the given indexes",
609 COMMAND_GROUP_SORTED_SET
,
611 , { "ZREMRANGEBYSCORE",
613 "Remove all members in a sorted set within the given scores",
614 COMMAND_GROUP_SORTED_SET
,
618 "Return a range of members in a sorted set, by index, with scores ordered from high to low",
619 COMMAND_GROUP_SORTED_SET
,
623 "Determine the index of a member in a sorted set, with scores ordered from high to low",
624 COMMAND_GROUP_SORTED_SET
,
628 "Get the score associated with the given member in a sorted set",
629 COMMAND_GROUP_SORTED_SET
,
632 "destination key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]",
633 "Add multiple sorted sets and store the resulting sorted set in a new key",
634 COMMAND_GROUP_SORTED_SET
,
640 * Output command help to stdout.
644 output_command_help(struct command_help
*help
) {
645 printf("\n \x1b[1m%s\x1b[0m \x1b[90m%s\x1b[0m\n", help
->name
, help
->params
);
646 printf(" \x1b[33msummary:\x1b[0m %s\n", help
->summary
);
647 printf(" \x1b[33msince:\x1b[0m %s\n", help
->since
);
648 printf(" \x1b[33mgroup:\x1b[0m %s\n", command_group_type_names
[help
->group
]);
652 * Return command group type by name string.
655 static command_group_type_t
656 command_group_type_by_name(const char *name
) {
657 for (int i
= 0; i
< COMMAND_GROUP_LENGTH
; ++i
) {
658 const char *group
= command_group_type_names
[i
];
659 if (0 == strcasecmp(name
, group
)) return i
;
665 * Output group names.
669 output_group_help() {
670 for (int i
= 0; i
< COMMAND_GROUP_LENGTH
; ++i
) {
671 if (COMMAND_GROUP_UNKNOWN
== i
) continue;
672 const char *group
= command_group_type_names
[i
];
673 printf(" \x1b[90m-\x1b[0m %s\n", group
);
678 * Output all command help, filtering by group or command name.
682 output_help(int argc
, const char **argv
) {
683 int len
= sizeof(command_help
) / sizeof(struct command_help
);
685 if (argc
&& 0 == strcasecmp("groups", argv
[0])) {
690 command_group_type_t group
= argc
691 ? command_group_type_by_name(argv
[0])
692 : COMMAND_GROUP_UNKNOWN
;
694 for (int i
= 0; i
< len
; ++i
) {
695 struct command_help help
= command_help
[i
];
696 if (argc
&& !group
&& 0 != strcasecmp(help
.name
, argv
[0])) continue;
697 if (group
&& group
!= help
.group
) continue;
698 output_command_help(&help
);