mirror of https://github.com/redis/redis.git
Merge 92d7e87872
into 3c1a759954
This commit is contained in:
commit
93638d6bd6
|
@ -354,6 +354,9 @@ void resetServerSaveParams(void) {
|
|||
server.saveparamslen = 0;
|
||||
}
|
||||
|
||||
/* support detecting include vs main config file */
|
||||
static int reading_include_file = 0;
|
||||
|
||||
void queueLoadModule(sds path, sds *argv, int argc) {
|
||||
int i;
|
||||
struct moduleLoadQueueEntry *loadmod;
|
||||
|
@ -362,6 +365,7 @@ void queueLoadModule(sds path, sds *argv, int argc) {
|
|||
loadmod->argv = argc ? zmalloc(sizeof(robj*)*argc) : NULL;
|
||||
loadmod->path = sdsnew(path);
|
||||
loadmod->argc = argc;
|
||||
loadmod->from_include = reading_include_file;;
|
||||
for (i = 0; i < argc; i++) {
|
||||
loadmod->argv[i] = createRawStringObject(argv[i],sdslen(argv[i]));
|
||||
}
|
||||
|
@ -521,7 +525,9 @@ void loadServerConfigFromString(char *config) {
|
|||
|
||||
/* Execute config directives */
|
||||
if (!strcasecmp(argv[0],"include") && argc == 2) {
|
||||
reading_include_file = 1;
|
||||
loadServerConfig(argv[1], 0, NULL);
|
||||
reading_include_file = 0;
|
||||
} else if (!strcasecmp(argv[0],"rename-command") && argc == 3) {
|
||||
struct redisCommand *cmd = lookupCommandBySds(argv[1]);
|
||||
int retval;
|
||||
|
@ -1570,6 +1576,8 @@ void rewriteConfigLoadmoduleOption(struct rewriteConfigState *state) {
|
|||
struct RedisModule *module = dictGetVal(de);
|
||||
/* Internal modules doesn't have path and are not part of the configuration file */
|
||||
if (sdslen(module->loadmod->path) == 0) continue;
|
||||
/* ignore when loaded from config */
|
||||
if (module->loadmod->from_include) continue;
|
||||
|
||||
line = sdsnew("loadmodule ");
|
||||
line = sdscatsds(line, module->loadmod->path);
|
||||
|
|
16
src/module.c
16
src/module.c
|
@ -12333,7 +12333,7 @@ int VectorSets_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
|
|||
/* Load internal data types that bundled as modules */
|
||||
void moduleLoadInternalModules(void) {
|
||||
#ifdef INCLUDE_VEC_SETS
|
||||
int retval = moduleOnLoad((int (*)(void *, void **, int)) VectorSets_OnLoad, NULL, NULL, NULL, 0, 0);
|
||||
int retval = moduleOnLoad((int (*)(void *, void **, int)) VectorSets_OnLoad, NULL, NULL, NULL, 0, 0, 1);
|
||||
serverAssert(retval == C_OK);
|
||||
#endif
|
||||
}
|
||||
|
@ -12354,7 +12354,7 @@ void moduleLoadFromQueue(void) {
|
|||
listRewind(server.loadmodule_queue,&li);
|
||||
while((ln = listNext(&li))) {
|
||||
struct moduleLoadQueueEntry *loadmod = ln->value;
|
||||
if (moduleLoad(loadmod->path,(void **)loadmod->argv,loadmod->argc, 0)
|
||||
if (moduleLoad(loadmod->path,(void **)loadmod->argv, loadmod->argc, 0, loadmod->from_include)
|
||||
== C_ERR)
|
||||
{
|
||||
serverLog(LL_WARNING,
|
||||
|
@ -12543,7 +12543,7 @@ void moduleUnregisterCleanup(RedisModule *module) {
|
|||
|
||||
/* Load a module by path and initialize it. On success C_OK is returned, otherwise
|
||||
* C_ERR is returned. */
|
||||
int moduleLoad(const char *path, void **module_argv, int module_argc, int is_loadex) {
|
||||
int moduleLoad(const char *path, void **module_argv, int module_argc, int is_loadex, int from_include) {
|
||||
int (*onload)(void *, void **, int);
|
||||
void *handle;
|
||||
|
||||
|
@ -12570,12 +12570,12 @@ int moduleLoad(const char *path, void **module_argv, int module_argc, int is_loa
|
|||
return C_ERR;
|
||||
}
|
||||
|
||||
return moduleOnLoad(onload, path, handle, module_argv, module_argc, is_loadex);
|
||||
return moduleOnLoad(onload, path, handle, module_argv, module_argc, is_loadex, from_include);
|
||||
}
|
||||
|
||||
/* Load a module by its 'onload' callback and initialize it. On success C_OK is returned, otherwise
|
||||
* C_ERR is returned. */
|
||||
int moduleOnLoad(int (*onload)(void *, void **, int), const char *path, void *handle, void **module_argv, int module_argc, int is_loadex) {
|
||||
int moduleOnLoad(int (*onload)(void *, void **, int), const char *path, void *handle, void **module_argv, int module_argc, int is_loadex, int from_include) {
|
||||
RedisModuleCtx ctx;
|
||||
moduleCreateContext(&ctx, NULL, REDISMODULE_CTX_TEMP_CLIENT); /* We pass NULL since we don't have a module yet. */
|
||||
if (onload((void*)&ctx,module_argv,module_argc) == REDISMODULE_ERR) {
|
||||
|
@ -12599,6 +12599,8 @@ int moduleOnLoad(int (*onload)(void *, void **, int), const char *path, void *ha
|
|||
ctx.module->loadmod->path = sdsnew(path);
|
||||
ctx.module->loadmod->argv = module_argc ? zmalloc(sizeof(robj*)*module_argc) : NULL;
|
||||
ctx.module->loadmod->argc = module_argc;
|
||||
ctx.module->loadmod->from_include = from_include;
|
||||
|
||||
for (int i = 0; i < module_argc; i++) {
|
||||
ctx.module->loadmod->argv[i] = module_argv[i];
|
||||
incrRefCount(ctx.module->loadmod->argv[i]);
|
||||
|
@ -13910,7 +13912,7 @@ NULL
|
|||
argv = &c->argv[3];
|
||||
}
|
||||
|
||||
if (moduleLoad(c->argv[2]->ptr,(void **)argv,argc, 0) == C_OK)
|
||||
if (moduleLoad(c->argv[2]->ptr,(void **)argv,argc, 0, 0) == C_OK)
|
||||
addReply(c,shared.ok);
|
||||
else
|
||||
addReplyError(c,
|
||||
|
@ -13926,7 +13928,7 @@ NULL
|
|||
/* If this is a loadex command we want to populate server.module_configs_queue with
|
||||
* sds NAME VALUE pairs. We also want to increment argv to just after ARGS, if supplied. */
|
||||
if (parseLoadexArguments((RedisModuleString ***) &argv, &argc) == REDISMODULE_OK &&
|
||||
moduleLoad(c->argv[2]->ptr, (void **)argv, argc, 1) == C_OK)
|
||||
moduleLoad(c->argv[2]->ptr, (void **)argv, argc, 1, 0) == C_OK)
|
||||
addReply(c,shared.ok);
|
||||
else {
|
||||
dictEmpty(server.module_configs_queue, NULL);
|
||||
|
|
|
@ -1500,6 +1500,7 @@ struct saveparam {
|
|||
|
||||
struct moduleLoadQueueEntry {
|
||||
sds path;
|
||||
int from_include;
|
||||
int argc;
|
||||
robj **argv;
|
||||
};
|
||||
|
@ -2747,8 +2748,8 @@ void populateCommandLegacyRangeSpec(struct redisCommand *c);
|
|||
void moduleInitModulesSystem(void);
|
||||
void moduleInitModulesSystemLast(void);
|
||||
void modulesCron(void);
|
||||
int moduleOnLoad(int (*onload)(void *, void **, int), const char *path, void *handle, void **module_argv, int module_argc, int is_loadex);
|
||||
int moduleLoad(const char *path, void **argv, int argc, int is_loadex);
|
||||
int moduleOnLoad(int (*onload)(void *, void **, int), const char *path, void *handle, void **module_argv, int module_argc, int is_loadex, int from_include);
|
||||
int moduleLoad(const char *path, void **argv, int argc, int is_loadex, int from_include);
|
||||
int moduleUnload(sds name, const char **errmsg, int forced_unload);
|
||||
void moduleLoadInternalModules(void);
|
||||
void moduleLoadFromQueue(void);
|
||||
|
|
Loading…
Reference in New Issue