Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
a3e8de04
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,发现更多精彩内容 >>
提交
a3e8de04
编写于
10月 29, 2015
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Lua script selective replication WIP.
上级
fc382356
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
3 deletion
+58
-3
src/scripting.c
src/scripting.c
+56
-2
src/server.h
src/server.h
+2
-1
未找到文件。
src/scripting.c
浏览文件 @
a3e8de04
...
...
@@ -375,7 +375,8 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
* a Lua script in the context of AOF and slaves. */
if
(
server
.
lua_replicate_commands
&&
!
server
.
lua_multi_emitted
&&
server
.
lua_write_dirty
)
server
.
lua_write_dirty
&&
server
.
lua_repl
!=
PROPAGATE_NONE
)
{
execCommandPropagateMulti
(
server
.
lua_caller
);
server
.
lua_multi_emitted
=
1
;
...
...
@@ -383,7 +384,13 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
/* Run the command */
int
call_flags
=
CMD_CALL_SLOWLOG
|
CMD_CALL_STATS
;
if
(
server
.
lua_replicate_commands
)
call_flags
|=
CMD_CALL_PROPAGATE
;
if
(
server
.
lua_replicate_commands
)
{
call_flags
|=
CMD_CALL_PROPAGATE
;
/* Don't propagate AOf / replication stream if a redis.set_repl()
* call changed the default replication policy. */
if
(
!
(
server
.
lua_repl
&
PROPAGATE_AOF
))
preventCommandAOF
(
c
);
if
(
!
(
server
.
lua_repl
&
PROPAGATE_REPL
))
preventCommandReplication
(
c
);
}
call
(
c
,
call_flags
);
/* Convert the result of the Redis command into a suitable Lua type.
...
...
@@ -540,6 +547,31 @@ int luaRedisReplicateCommandsCommand(lua_State *lua) {
return
1
;
}
/* redis.set_repl()
*
* Set the propagation of write commands executed in the context of the
* script to on/off for AOF and slaves. */
int
luaRedisSetReplCommand
(
lua_State
*
lua
)
{
int
argc
=
lua_gettop
(
lua
);
int
flags
;
if
(
server
.
lua_replicate_commands
==
0
)
{
luaPushError
(
lua
,
"You can set the replication behavior only after turning on single commands replication with redis.replicate_commands()."
);
return
1
;
}
else
if
(
argc
!=
1
)
{
luaPushError
(
lua
,
"redis.set_repl() requires two arguments."
);
return
1
;
}
flags
=
lua_tonumber
(
lua
,
-
1
);
if
((
flags
&
~
(
PROPAGATE_AOF
|
PROPAGATE_REPL
))
!=
0
)
{
luaPushError
(
lua
,
"Invalid replication flags. Use REPL_AOF, REPL_SLAVE, REPL_ALL or REPL_NONE."
);
return
1
;
}
server
.
lua_repl
=
flags
;
return
0
;
}
/* redis.log() */
int
luaLogCommand
(
lua_State
*
lua
)
{
int
j
,
argc
=
lua_gettop
(
lua
);
...
...
@@ -741,6 +773,27 @@ void scriptingInit(void) {
lua_pushcfunction
(
lua
,
luaRedisReplicateCommandsCommand
);
lua_settable
(
lua
,
-
3
);
/* redis.set_repl and associated flags. */
lua_pushstring
(
lua
,
"set_repl"
);
lua_pushcfunction
(
lua
,
luaRedisSetReplCommand
);
lua_settable
(
lua
,
-
3
);
lua_pushstring
(
lua
,
"REPL_NONE"
);
lua_pushnumber
(
lua
,
PROPAGATE_NONE
);
lua_settable
(
lua
,
-
3
);
lua_pushstring
(
lua
,
"REPL_AOF"
);
lua_pushnumber
(
lua
,
PROPAGATE_AOF
);
lua_settable
(
lua
,
-
3
);
lua_pushstring
(
lua
,
"REPL_SLAVE"
);
lua_pushnumber
(
lua
,
PROPAGATE_REPL
);
lua_settable
(
lua
,
-
3
);
lua_pushstring
(
lua
,
"REPL_ALL"
);
lua_pushnumber
(
lua
,
PROPAGATE_AOF
|
PROPAGATE_REPL
);
lua_settable
(
lua
,
-
3
);
/* Finally set the table as 'redis' global var. */
lua_setglobal
(
lua
,
"redis"
);
...
...
@@ -987,6 +1040,7 @@ void evalGenericCommand(client *c, int evalsha) {
server
.
lua_write_dirty
=
0
;
server
.
lua_replicate_commands
=
0
;
server
.
lua_multi_emitted
=
0
;
server
.
lua_repl
=
PROPAGATE_AOF
|
PROPAGATE_REPL
;
/* Get the number of arguments that are keys */
if
(
getLongLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
numkeys
,
NULL
)
!=
C_OK
)
...
...
src/server.h
浏览文件 @
a3e8de04
...
...
@@ -940,7 +940,7 @@ struct redisServer {
int
cluster_migration_barrier
;
/* Cluster replicas migration barrier. */
int
cluster_slave_validity_factor
;
/* Slave max data age for failover. */
int
cluster_require_full_coverage
;
/* If true, put the cluster down if
there is at least an uncovered slot.
*/
there is at least an uncovered slot.*/
/* Scripting */
lua_State
*
lua
;
/* The Lua interpreter. We use just one for all clients */
client
*
lua_client
;
/* The "fake client" to query Redis from Lua */
...
...
@@ -954,6 +954,7 @@ struct redisServer {
execution of the current script. */
int
lua_replicate_commands
;
/* True if we are doing single commands repl. */
int
lua_multi_emitted
;
/* True if we already proagated MULTI. */
int
lua_repl
;
/* Script replication flags for redis.set_repl(). */
int
lua_timedout
;
/* True if we reached the time limit for script
execution. */
int
lua_kill
;
/* Kill the script if true. */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录