Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加lua脚本的注释 #88

Open
wants to merge 2 commits into
base: 7.0-cn-annotated
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ redis 仓库链接:https://github.com/redis/redis<br>
| [listpack.h](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/listpack.h) | listpack 紧凑列表定义 | 完成 |
| [listpack.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/listpack.c) | listpack 紧凑列表实现 | 低于一半 |
| [networking.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/networking.c) | Redis 客户端、主、副本 I/O 相关 | 低于一半 |
| [script.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/script.c) | redis功能api的lua方法实现 | 过半 |
| [script_lua.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/script_lua.c) | redis调用lua方法的通用api抽象 | 过半 |
| [eval.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/eval.c) | lua执行实现 | 过半 |

</p>
尚未有中文注释的文件不会出现在表格中。<br>
更新日期:2022/11/7
Expand Down
4 changes: 4 additions & 0 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,10 @@ int keyIsExpired(redisDb *db, robj *key) {
* only the first time it is accessed and not in the middle of the
* script execution, making propagation to slaves / AOF consistent.
* See issue #1525 on Github for more information. */

/* 如果我们在 Lua 脚本的上下文中,我们需要认为当前时间是 Lua 脚本开始的时间。
* 这样一来,key 只能在第一次访问时过期,而不是在脚本执行过程中过期,从而使到从属/ AOF 的传播保持一致。
* 有关更多信息,请参阅 Github 上的第1525期的 issue */
if (server.script_caller) {
now = scriptTimeSnapshot();
}
Expand Down
224 changes: 224 additions & 0 deletions src/eval.c

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions src/script.c

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
* to clients and perform script kill
*/

/* script.c单元为函数和eval提供了与Redis交互的API。
* 交互主要包括执行命令,但也包括调用Redis返回长脚本或检查脚本是否已被删除。
* 交互是使用scriptRunCtx对象完成的
* 需要由用户创建并使用scriptPrepareForRun初始化。
*
* 该单元公开的功能的详细列表:
* 1.调用命令(包括所有验证检查,如acl、cluster、read-only run等)
* 2.设置响应
* 3.设置复制方法(AOF/Replication/NONE)
* 4.在长时间运行的脚本上调用Redis,以允许Redis回复客户端并执行脚本终止
* 主要定位在于是c语言实现的lua方法 */

/*
* scriptInterrupt function will return one of those value,
*
Expand All @@ -67,6 +79,7 @@
#define SCRIPT_ALLOW_CROSS_SLOT (1ULL<<8) /* Indicate that the current script may access keys from multiple slots */
typedef struct scriptRunCtx scriptRunCtx;

/* 运行时上下文 */
struct scriptRunCtx {
const char *funcname;
client *c;
Expand Down
170 changes: 170 additions & 0 deletions src/script_lua.c

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/script_lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
* Uses script.c for interaction back with Redis.
*/

/*
* script_lua.c单元提供eval和function_lua之间的共享功能, 提供的功能:
*
* 1. 执行Lua代码,假设代码位于Lua堆栈的顶部。此外,解析执行结果并将其转换为resp并回复客户端。
* 2. 从Lua代码中运行Redis命令(包括解析回复并从中创建Lua对象)。
* 3. 向Lua解释器注册Redis API。仅注册共享API(仅与eval.c相关的API(如调试)在eval.cc上注册)。
*
* 使用script.c用于与Redis交互。
* 主要定位是在完全和lua引擎交互。
*/

#include "server.h"
#include "script.h"
#include <lua.h>
Expand Down