Redis MODULE command. * * MODULE LIST * MODULE LOAD [args...] * MODULE UNLOAD */
| 8952 | * MODULE UNLOAD <name> |
| 8953 | */ |
| 8954 | void moduleCommand(client *c) { |
| 8955 | char *subcmd = szFromObj(c->argv[1]); |
| 8956 | |
| 8957 | if (c->argc == 2 && !strcasecmp(subcmd,"help")) { |
| 8958 | const char *help[] = { |
| 8959 | "LIST", |
| 8960 | " Return a list of loaded modules.", |
| 8961 | "LOAD <path> [<arg> ...]", |
| 8962 | " Load a module library from <path>, passing to it any optional arguments.", |
| 8963 | "UNLOAD <name>", |
| 8964 | " Unload a module.", |
| 8965 | NULL |
| 8966 | }; |
| 8967 | addReplyHelp(c, help); |
| 8968 | } else |
| 8969 | if (!strcasecmp(subcmd,"load") && c->argc >= 3) { |
| 8970 | robj **argv = NULL; |
| 8971 | int argc = 0; |
| 8972 | |
| 8973 | if (c->argc > 3) { |
| 8974 | argc = c->argc - 3; |
| 8975 | argv = &c->argv[3]; |
| 8976 | } |
| 8977 | |
| 8978 | if (moduleLoad(szFromObj(c->argv[2]),(void **)argv,argc) == C_OK) |
| 8979 | addReply(c,shared.ok); |
| 8980 | else |
| 8981 | addReplyError(c, |
| 8982 | "Error loading the extension. Please check the server logs."); |
| 8983 | } else if (!strcasecmp(subcmd,"unload") && c->argc == 3) { |
| 8984 | if (moduleUnload(szFromObj(c->argv[2])) == C_OK) |
| 8985 | addReply(c,shared.ok); |
| 8986 | else { |
| 8987 | const char *errmsg; |
| 8988 | switch(errno) { |
| 8989 | case ENOENT: |
| 8990 | errmsg = "no such module with that name"; |
| 8991 | break; |
| 8992 | case EBUSY: |
| 8993 | errmsg = "the module exports one or more module-side data " |
| 8994 | "types, can't unload"; |
| 8995 | break; |
| 8996 | case EPERM: |
| 8997 | errmsg = "the module exports APIs used by other modules. " |
| 8998 | "Please unload them first and try again"; |
| 8999 | break; |
| 9000 | case EAGAIN: |
| 9001 | errmsg = "the module has blocked clients. " |
| 9002 | "Please wait them unblocked and try again"; |
| 9003 | break; |
| 9004 | default: |
| 9005 | errmsg = "operation not possible."; |
| 9006 | break; |
| 9007 | } |
| 9008 | addReplyErrorFormat(c,"Error unloading module: %s",errmsg); |
| 9009 | } |
| 9010 | } else if (!strcasecmp(subcmd,"list") && c->argc == 2) { |
| 9011 | addReplyLoadedModules(c); |
nothing calls this directly
no test coverage detected