doc: 阅读redis文档

This commit is contained in:
asahi
2025-09-24 16:39:45 +08:00
parent 4a0ee84e7e
commit 10aca33a06

View File

@@ -171,6 +171,8 @@
- [evalsha in context of pipelining](#evalsha-in-context-of-pipelining)
- [Script Cache Semantics](#script-cache-semantics)
- [Script Command](#script-command)
- [Script Replication](#script-replication)
- [Replicating commands instead of Scripts](#replicating-commands-instead-of-scripts)
# redis
@@ -2807,3 +2809,30 @@ redis> EVALSHA ffffffffffffffffffffffffffffffffffffffff 0
- `SCRIPT KILL`: 该命令是打断`long-running script`的唯一方式。当script的执行时长超过限制默认为5s如果该脚本执行时未对数据进行任何修改则可以通过`SCRIPT KILL`命令来终止
- `SCRIPT DEBUG`: 用于控制`redis lua scripts debugger`的使用
#### Script Replication
在standalone部署场景下单个master实例管理整个database而在集群部署模式下至少会存在3个masters共同管理database。对于master实例redis会使用replication来维护一个或多个replicas。
由于scripts可能会修改数据故而redis需要保证所有由script执行的写操作都要被同步给replicas从而replicas的数据一致性。
在script replication方面存在如下两种方法
- `verbatim replication`master会将script的source code发送给replicasreplicas再执行接收到的脚本。这种模式能够节省replication brandwith因为在循环场景下短脚本能够产生大量的命令。
- 但是这种模式下replicas会对master的工作进行redo即使针对读指令这将会浪费资源并且要求脚本中的写操作具有确定性
- `effects replication`: 只有脚本中对数据造成修改的命令才会被同步replicas针对`被同步的写指令`进行执行,并不会像前一个模式一样重新执行脚本。
- 这这种模式下关于replication的brandwith会增加但是该模式本质上的确定的无需写操作具有确定性
> 在redis 3.2之前,`verbatim script replication`是唯一受支持的模式直到Redis 3.2加入`effects replication`。
#### Replicating commands instead of Scripts
从redis 3.2开始,可以选择`effects replication`的同步方式,该方式会`replicate commands generated by the script`
> 从redis 5.0开始script effects replication为默认模式并不需要显式启用。
在该模式下当lua脚本被执行时redis会收集`all the commands executed by Lua scripting engine that actually modify the dataset`。当脚本执行完成之后commands sequence将会被封装到`multi/exec`并且被发送给replcias和AOF。
该种replication方式在如下用例场景下具有优势
- script的计算速度很慢但是最终script的修改能够被统计为较少的write commands
- 当启用script effects replication时`non-determinstic function`校验将会被移除。故而,可以在脚本中自由的使用`TIME``SRANDMEMBER`这类非确定性的指令
- The Lua PRNG in this mode is seeded randomly on every call