Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
8066d2a1
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8066d2a1
编写于
10月 02, 2019
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modules: handle propagation when ctx is freed. Flag modules commands ctx.
上级
d3f4dec4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
19 deletion
+23
-19
src/module.c
src/module.c
+23
-19
未找到文件。
src/module.c
浏览文件 @
8066d2a1
...
...
@@ -144,6 +144,7 @@ typedef struct RedisModuleCtx RedisModuleCtx;
#define REDISMODULE_CTX_BLOCKED_TIMEOUT (1<<4)
#define REDISMODULE_CTX_THREAD_SAFE (1<<5)
#define REDISMODULE_CTX_BLOCKED_DISCONNECTED (1<<6)
#define REDISMODULE_CTX_MODULE_COMMAND_CALL (1<<7)
/* This represents a Redis key opened with RM_OpenKey(). */
struct
RedisModuleKey
{
...
...
@@ -497,8 +498,29 @@ int RM_GetApi(const char *funcname, void **targetPtrPtr) {
return
REDISMODULE_OK
;
}
/* Helper function for when a command callback is called, in order to handle
* details needed to correctly replicate commands. */
void
moduleHandlePropagationAfterCommandCallback
(
RedisModuleCtx
*
ctx
)
{
client
*
c
=
ctx
->
client
;
/* We don't need to do anything here if the context was never used
* in order to propagate commands. */
if
(
!
(
ctx
->
flags
&
REDISMODULE_CTX_MULTI_EMITTED
))
return
;
if
(
c
->
flags
&
CLIENT_LUA
)
return
;
/* Handle the replication of the final EXEC, since whatever a command
* emits is always wrapped around MULTI/EXEC. */
robj
*
propargv
[
1
];
propargv
[
0
]
=
createStringObject
(
"EXEC"
,
4
);
alsoPropagate
(
server
.
execCommand
,
c
->
db
->
id
,
propargv
,
1
,
PROPAGATE_AOF
|
PROPAGATE_REPL
);
decrRefCount
(
propargv
[
0
]);
}
/* Free the context after the user function was called. */
void
moduleFreeContext
(
RedisModuleCtx
*
ctx
)
{
moduleHandlePropagationAfterCommandCallback
(
ctx
);
autoMemoryCollect
(
ctx
);
poolAllocRelease
(
ctx
);
if
(
ctx
->
postponed_arrays
)
{
...
...
@@ -514,34 +536,16 @@ void moduleFreeContext(RedisModuleCtx *ctx) {
if
(
ctx
->
flags
&
REDISMODULE_CTX_THREAD_SAFE
)
freeClient
(
ctx
->
client
);
}
/* Helper function for when a command callback is called, in order to handle
* details needed to correctly replicate commands. */
void
moduleHandlePropagationAfterCommandCallback
(
RedisModuleCtx
*
ctx
)
{
client
*
c
=
ctx
->
client
;
if
(
c
->
flags
&
CLIENT_LUA
)
return
;
/* Handle the replication of the final EXEC, since whatever a command
* emits is always wrapped around MULTI/EXEC. */
if
(
ctx
->
flags
&
REDISMODULE_CTX_MULTI_EMITTED
)
{
robj
*
propargv
[
1
];
propargv
[
0
]
=
createStringObject
(
"EXEC"
,
4
);
alsoPropagate
(
server
.
execCommand
,
c
->
db
->
id
,
propargv
,
1
,
PROPAGATE_AOF
|
PROPAGATE_REPL
);
decrRefCount
(
propargv
[
0
]);
}
}
/* This Redis command binds the normal Redis command invocation with commands
* exported by modules. */
void
RedisModuleCommandDispatcher
(
client
*
c
)
{
RedisModuleCommandProxy
*
cp
=
(
void
*
)(
unsigned
long
)
c
->
cmd
->
getkeys_proc
;
RedisModuleCtx
ctx
=
REDISMODULE_CTX_INIT
;
ctx
.
flags
|=
REDISMODULE_CTX_MODULE_COMMAND_CALL
;
ctx
.
module
=
cp
->
module
;
ctx
.
client
=
c
;
cp
->
func
(
&
ctx
,(
void
**
)
c
->
argv
,
c
->
argc
);
moduleHandlePropagationAfterCommandCallback
(
&
ctx
);
moduleFreeContext
(
&
ctx
);
/* In some cases processMultibulkBuffer uses sdsMakeRoomFor to
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录