diff --git a/中间件/redis/redis.md b/中间件/redis/redis.md index 5ca8325..9194e9c 100644 --- a/中间件/redis/redis.md +++ b/中间件/redis/redis.md @@ -174,6 +174,9 @@ - [Script Replication](#script-replication) - [Replicating commands instead of Scripts](#replicating-commands-instead-of-scripts) - [Scripts with deterministic writes](#scripts-with-deterministic-writes) + - [Debugging Eval scripts](#debugging-eval-scripts) + - [Execution under low memory conditions](#execution-under-low-memory-conditions) + - [Eval flags](#eval-flags) # redis @@ -2932,4 +2935,28 @@ puts r.eval(RandomPushScript,1,:mylist,10,rand(2**32)) 该seed是由client生成的,作为参数被传递给脚本,并且会作为参数被传播给replicas和AOF。这样,能够确保同步给AOF和replicas的changes相同。 +#### Debugging Eval scripts +从Redis 3.2开始,Redis支持natvie Lua debugging,redis lua debugger是远程的,由server和client组成。 + +#### Execution under low memory conditions +当redis的内存使用超过最大限制后,`the first write command encountered in the script that uses additional memory will cause the script to abort`。 + +但是,当script中的第一条write command没有使用额外内存时,存在例外(例如`DEL, LREM`命令)。在该场景下,redis会允许该脚本中所有的命令运行,从而保证lua脚本执行的原子性。`如果lua脚本中接下来的命令耗费了额外的内存,那么redis内存使用可以超过最大值限制。` + +#### Eval flags +通常,当运行Eval script时,server并不知道该脚本如何访问database。默认情况下,redis假设所有脚本都会对数据进行`读取和写入`。 + +但是,从Redis 7.0开始,支持在创建脚本时声明`flags`,用于告知redis将如何访问数据。 + +在如下示例中,将在脚本的第一行声明flags: +```lua +#!lua flags=no-writes,allow-stale +local x = redis.call('get','x') +return x +``` +当redis看到`#!`的注释时,其将会将脚本看作`声明了flags`,即使没有flags被实际定义,其相比于没有`#!`的脚本仍然存在一系列不同的默认值。 + +另一个不同的区别是,`scripts without #!`可以运行命令来访问`keys belonging to different cluster hash slots`,但是拥有`#!`的将继承默认的flags,故而其不能对`keys belonging to different cluster hash slots`进行访问。 + +