Skip to content

Commit

Permalink
feat: 增加lua脚本的注释
Browse files Browse the repository at this point in the history
  • Loading branch information
artikell committed Oct 30, 2022
1 parent d932e6e commit 954263d
Show file tree
Hide file tree
Showing 7 changed files with 512 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ redis 仓库链接:https://github.com/redis/redis<br>
| [redis-check-rdb.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/redis-check-rdb.c) | Redis RDB 检查工具 | 完成 |
| [evict.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/evict.c) | 四种 redis 内存淘汰算法 | 完成 |
| [aof.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/aof.c) | redis AOF 功能 | 过半 |
| [redis-check-rdb.c](https://github.com/CN-annotation-team/redis7.0-chinese-annotated/blob/7.0-cn-annotated/src/redis-check-rdb.c) | Redis RDB 检查工具 | 低于一半 |
| [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/10/23
Expand Down
4 changes: 4 additions & 0 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,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

0 comments on commit 954263d

Please sign in to comment.