Redis MODULE command. * * MODULE LIST * MODULE LOAD [args...] * MODULE UNLOAD */
| 8752 | * MODULE UNLOAD <name> |
| 8753 | */ |
| 8754 | void moduleCommand(client *c) { |
| 8755 | char *subcmd = c->argv[1]->ptr; |
| 8756 | |
| 8757 | if (c->argc == 2 && !strcasecmp(subcmd,"help")) { |
| 8758 | const char *help[] = { |
| 8759 | "LIST", |
| 8760 | " Return a list of loaded modules.", |
| 8761 | "LOAD <path> [<arg> ...]", |
| 8762 | " Load a module library from <path>, passing to it any optional arguments.", |
| 8763 | "UNLOAD <name>", |
| 8764 | " Unload a module.", |
| 8765 | NULL |
| 8766 | }; |
| 8767 | addReplyHelp(c, help); |
| 8768 | } else |
| 8769 | if (!strcasecmp(subcmd,"load") && c->argc >= 3) { |
| 8770 | robj **argv = NULL; |
| 8771 | int argc = 0; |
| 8772 | |
| 8773 | if (c->argc > 3) { |
| 8774 | argc = c->argc - 3; |
| 8775 | argv = &c->argv[3]; |
| 8776 | } |
| 8777 | |
| 8778 | if (moduleLoad(c->argv[2]->ptr,(void **)argv,argc) == C_OK) |
| 8779 | addReply(c,shared.ok); |
| 8780 | else |
| 8781 | addReplyError(c, |
| 8782 | "Error loading the extension. Please check the server logs."); |
| 8783 | } else if (!strcasecmp(subcmd,"unload") && c->argc == 3) { |
| 8784 | if (moduleUnload(c->argv[2]->ptr) == C_OK) |
| 8785 | addReply(c,shared.ok); |
| 8786 | else { |
| 8787 | char *errmsg; |
| 8788 | switch(errno) { |
| 8789 | case ENOENT: |
| 8790 | errmsg = "no such module with that name"; |
| 8791 | break; |
| 8792 | case EBUSY: |
| 8793 | errmsg = "the module exports one or more module-side data " |
| 8794 | "types, can't unload"; |
| 8795 | break; |
| 8796 | case EPERM: |
| 8797 | errmsg = "the module exports APIs used by other modules. " |
| 8798 | "Please unload them first and try again"; |
| 8799 | break; |
| 8800 | case EAGAIN: |
| 8801 | errmsg = "the module has blocked clients. " |
| 8802 | "Please wait them unblocked and try again"; |
| 8803 | break; |
| 8804 | default: |
| 8805 | errmsg = "operation not possible."; |
| 8806 | break; |
| 8807 | } |
| 8808 | addReplyErrorFormat(c,"Error unloading module: %s",errmsg); |
| 8809 | } |
| 8810 | } else if (!strcasecmp(subcmd,"list") && c->argc == 2) { |
| 8811 | addReplyLoadedModules(c); |
nothing calls this directly
no test coverage detected