Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
f739c272
Unverified
Commit
f739c272
authored
Nov 24, 2017
by
Salvatore Sanfilippo
Committed by
GitHub
Nov 24, 2017
Browse files
Merge pull request #4344 from soloestoy/fix-module-name-conflict
Fix module name conflict
parents
58ac57f6
6dffc1b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
f739c272
...
@@ -613,7 +613,7 @@ int RM_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc c
...
@@ -613,7 +613,7 @@ int RM_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc c
sds
cmdname
=
sdsnew
(
name
);
sds
cmdname
=
sdsnew
(
name
);
/* Check if the command name is busy. */
/* Check if the command name is busy. */
if
(
lookupCommand
(
(
char
*
)
name
)
!=
NULL
)
{
if
(
lookupCommand
(
cmd
name
)
!=
NULL
)
{
sdsfree
(
cmdname
);
sdsfree
(
cmdname
);
return
REDISMODULE_ERR
;
return
REDISMODULE_ERR
;
}
}
...
@@ -648,7 +648,7 @@ int RM_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc c
...
@@ -648,7 +648,7 @@ int RM_CreateCommand(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc c
*
*
* This is an internal function, Redis modules developers don't need
* This is an internal function, Redis modules developers don't need
* to use it. */
* to use it. */
void
RM_SetModuleAttribs
(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
int
ver
,
int
apiver
){
void
RM_SetModuleAttribs
(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
int
ver
,
int
apiver
)
{
RedisModule
*
module
;
RedisModule
*
module
;
if
(
ctx
->
module
!=
NULL
)
return
;
if
(
ctx
->
module
!=
NULL
)
return
;
...
@@ -660,6 +660,19 @@ void RM_SetModuleAttribs(RedisModuleCtx *ctx, const char *name, int ver, int api
...
@@ -660,6 +660,19 @@ void RM_SetModuleAttribs(RedisModuleCtx *ctx, const char *name, int ver, int api
ctx
->
module
=
module
;
ctx
->
module
=
module
;
}
}
/* Return non-zero if the module name is busy.
* Otherwise zero is returned. */
int
RM_IsModuleNameBusy
(
const
char
*
name
)
{
sds
modulename
=
sdsnew
(
name
);
/* Check if the module name is busy. */
if
(
dictFind
(
modules
,
modulename
)
!=
NULL
)
{
sdsfree
(
modulename
);
return
1
;
}
return
0
;
}
/* Return the current UNIX time in milliseconds. */
/* Return the current UNIX time in milliseconds. */
long
long
RM_Milliseconds
(
void
)
{
long
long
RM_Milliseconds
(
void
)
{
return
mstime
();
return
mstime
();
...
@@ -3736,6 +3749,28 @@ void moduleFreeModuleStructure(struct RedisModule *module) {
...
@@ -3736,6 +3749,28 @@ void moduleFreeModuleStructure(struct RedisModule *module) {
zfree
(
module
);
zfree
(
module
);
}
}
void
moduleUnregisterCommands
(
struct
RedisModule
*
module
)
{
/* Unregister all the commands registered by this module. */
dictIterator
*
di
=
dictGetSafeIterator
(
server
.
commands
);
dictEntry
*
de
;
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
struct
redisCommand
*
cmd
=
dictGetVal
(
de
);
if
(
cmd
->
proc
==
RedisModuleCommandDispatcher
)
{
RedisModuleCommandProxy
*
cp
=
(
void
*
)(
unsigned
long
)
cmd
->
getkeys_proc
;
sds
cmdname
=
cp
->
rediscmd
->
name
;
if
(
cp
->
module
==
module
)
{
dictDelete
(
server
.
commands
,
cmdname
);
dictDelete
(
server
.
orig_commands
,
cmdname
);
sdsfree
(
cmdname
);
zfree
(
cp
->
rediscmd
);
zfree
(
cp
);
}
}
}
dictReleaseIterator
(
di
);
}
/* Load a module and initialize it. On success C_OK is returned, otherwise
/* Load a module and initialize it. On success C_OK is returned, otherwise
* C_ERR is returned. */
* C_ERR is returned. */
int
moduleLoad
(
const
char
*
path
,
void
**
module_argv
,
int
module_argc
)
{
int
moduleLoad
(
const
char
*
path
,
void
**
module_argv
,
int
module_argc
)
{
...
@@ -3756,7 +3791,10 @@ int moduleLoad(const char *path, void **module_argv, int module_argc) {
...
@@ -3756,7 +3791,10 @@ int moduleLoad(const char *path, void **module_argv, int module_argc) {
return
C_ERR
;
return
C_ERR
;
}
}
if
(
onload
((
void
*
)
&
ctx
,
module_argv
,
module_argc
)
==
REDISMODULE_ERR
)
{
if
(
onload
((
void
*
)
&
ctx
,
module_argv
,
module_argc
)
==
REDISMODULE_ERR
)
{
if
(
ctx
.
module
)
moduleFreeModuleStructure
(
ctx
.
module
);
if
(
ctx
.
module
)
{
moduleUnregisterCommands
(
ctx
.
module
);
moduleFreeModuleStructure
(
ctx
.
module
);
}
dlclose
(
handle
);
dlclose
(
handle
);
serverLog
(
LL_WARNING
,
serverLog
(
LL_WARNING
,
"Module %s initialization failed. Module not loaded"
,
path
);
"Module %s initialization failed. Module not loaded"
,
path
);
...
@@ -3790,25 +3828,7 @@ int moduleUnload(sds name) {
...
@@ -3790,25 +3828,7 @@ int moduleUnload(sds name) {
return
REDISMODULE_ERR
;
return
REDISMODULE_ERR
;
}
}
/* Unregister all the commands registered by this module. */
moduleUnregisterCommands
(
module
);
dictIterator
*
di
=
dictGetSafeIterator
(
server
.
commands
);
dictEntry
*
de
;
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
struct
redisCommand
*
cmd
=
dictGetVal
(
de
);
if
(
cmd
->
proc
==
RedisModuleCommandDispatcher
)
{
RedisModuleCommandProxy
*
cp
=
(
void
*
)(
unsigned
long
)
cmd
->
getkeys_proc
;
sds
cmdname
=
cp
->
rediscmd
->
name
;
if
(
cp
->
module
==
module
)
{
dictDelete
(
server
.
commands
,
cmdname
);
dictDelete
(
server
.
orig_commands
,
cmdname
);
sdsfree
(
cmdname
);
zfree
(
cp
->
rediscmd
);
zfree
(
cp
);
}
}
}
dictReleaseIterator
(
di
);
/* Unregister all the hooks. TODO: Yet no hooks support here. */
/* Unregister all the hooks. TODO: Yet no hooks support here. */
...
@@ -3903,6 +3923,7 @@ void moduleRegisterCoreAPI(void) {
...
@@ -3903,6 +3923,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API
(
Strdup
);
REGISTER_API
(
Strdup
);
REGISTER_API
(
CreateCommand
);
REGISTER_API
(
CreateCommand
);
REGISTER_API
(
SetModuleAttribs
);
REGISTER_API
(
SetModuleAttribs
);
REGISTER_API
(
IsModuleNameBusy
);
REGISTER_API
(
WrongArity
);
REGISTER_API
(
WrongArity
);
REGISTER_API
(
ReplyWithLongLong
);
REGISTER_API
(
ReplyWithLongLong
);
REGISTER_API
(
ReplyWithError
);
REGISTER_API
(
ReplyWithError
);
...
...
src/redismodule.h
View file @
f739c272
...
@@ -143,7 +143,8 @@ void *REDISMODULE_API_FUNC(RedisModule_Calloc)(size_t nmemb, size_t size);
...
@@ -143,7 +143,8 @@ void *REDISMODULE_API_FUNC(RedisModule_Calloc)(size_t nmemb, size_t size);
char
*
REDISMODULE_API_FUNC
(
RedisModule_Strdup
)(
const
char
*
str
);
char
*
REDISMODULE_API_FUNC
(
RedisModule_Strdup
)(
const
char
*
str
);
int
REDISMODULE_API_FUNC
(
RedisModule_GetApi
)(
const
char
*
,
void
*
);
int
REDISMODULE_API_FUNC
(
RedisModule_GetApi
)(
const
char
*
,
void
*
);
int
REDISMODULE_API_FUNC
(
RedisModule_CreateCommand
)(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
RedisModuleCmdFunc
cmdfunc
,
const
char
*
strflags
,
int
firstkey
,
int
lastkey
,
int
keystep
);
int
REDISMODULE_API_FUNC
(
RedisModule_CreateCommand
)(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
RedisModuleCmdFunc
cmdfunc
,
const
char
*
strflags
,
int
firstkey
,
int
lastkey
,
int
keystep
);
int
REDISMODULE_API_FUNC
(
RedisModule_SetModuleAttribs
)(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
int
ver
,
int
apiver
);
void
REDISMODULE_API_FUNC
(
RedisModule_SetModuleAttribs
)(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
int
ver
,
int
apiver
);
int
REDISMODULE_API_FUNC
(
RedisModule_IsModuleNameBusy
)(
const
char
*
name
);
int
REDISMODULE_API_FUNC
(
RedisModule_WrongArity
)(
RedisModuleCtx
*
ctx
);
int
REDISMODULE_API_FUNC
(
RedisModule_WrongArity
)(
RedisModuleCtx
*
ctx
);
int
REDISMODULE_API_FUNC
(
RedisModule_ReplyWithLongLong
)(
RedisModuleCtx
*
ctx
,
long
long
ll
);
int
REDISMODULE_API_FUNC
(
RedisModule_ReplyWithLongLong
)(
RedisModuleCtx
*
ctx
,
long
long
ll
);
int
REDISMODULE_API_FUNC
(
RedisModule_GetSelectedDb
)(
RedisModuleCtx
*
ctx
);
int
REDISMODULE_API_FUNC
(
RedisModule_GetSelectedDb
)(
RedisModuleCtx
*
ctx
);
...
@@ -263,6 +264,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
...
@@ -263,6 +264,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API
(
Strdup
);
REDISMODULE_GET_API
(
Strdup
);
REDISMODULE_GET_API
(
CreateCommand
);
REDISMODULE_GET_API
(
CreateCommand
);
REDISMODULE_GET_API
(
SetModuleAttribs
);
REDISMODULE_GET_API
(
SetModuleAttribs
);
REDISMODULE_GET_API
(
IsModuleNameBusy
);
REDISMODULE_GET_API
(
WrongArity
);
REDISMODULE_GET_API
(
WrongArity
);
REDISMODULE_GET_API
(
ReplyWithLongLong
);
REDISMODULE_GET_API
(
ReplyWithLongLong
);
REDISMODULE_GET_API
(
ReplyWithError
);
REDISMODULE_GET_API
(
ReplyWithError
);
...
@@ -370,6 +372,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
...
@@ -370,6 +372,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API
(
AbortBlock
);
REDISMODULE_GET_API
(
AbortBlock
);
#endif
#endif
if
(
RedisModule_IsModuleNameBusy
(
name
))
return
REDISMODULE_ERR
;
RedisModule_SetModuleAttribs
(
ctx
,
name
,
ver
,
apiver
);
RedisModule_SetModuleAttribs
(
ctx
,
name
,
ver
,
apiver
);
return
REDISMODULE_OK
;
return
REDISMODULE_OK
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment