Skip to content

Commit d213b4d

Browse files
authored
script flags update (redis#1954)
updating docs about read only scripts and oom related flag changes in 7.0.1
1 parent e16828b commit d213b4d

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

commands/command.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Command flags are an array. It can contain the following simple strings (status
6464
* **fast:** the command operates in constant or log(N) time.
6565
This flag is used for monitoring latency with the `LATENCY` command.
6666
* **loading:** the command is allowed while the database is loading.
67-
* **may_replicate:** the command may be replicated to replicas and the AOF.
6867
* **movablekeys:** the _first key_, _last key_, and _step_ values don't determine all key positions.
6968
Clients need to use `COMMAND GETKEYS` or [key specifications][td] in this case.
7069
See below for more details.

commands/eval_ro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
This is a read-only variant of the `EVAL` command that cannot execute commands that modify data.
22

3-
For more information about when to use this command vs `EVAL`, please refer to [Read-only scripts](/docs/manual/programmability/#Read-only_scripts).
3+
For more information about when to use this command vs `EVAL`, please refer to [Read-only scripts](/docs/manual/programmability/#read-only_scripts).
44

55
For more information about `EVAL` scripts please refer to [Introduction to Eval Scripts](/topics/eval-intro).
66

commands/evalsha_ro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
This is a read-only variant of the `EVALSHA` command that cannot execute commands that modify data.
22

3-
For more information about when to use this command vs `EVALSHA`, please refer to [Read-only scripts](/docs/manual/programmability/#Read-only_scripts).
3+
For more information about when to use this command vs `EVALSHA`, please refer to [Read-only scripts](/docs/manual/programmability/#read-only_scripts).
44

55
For more information about `EVALSHA` scripts please refer to [Introduction to Eval Scripts](/topics/eval-intro).

commands/fcall_ro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
This is a read-only variant of the `FCALL` command that cannot execute commands that modify data.
22

3-
For more information about when to use this command vs `FCALL`, please refer to [Read-only scripts](/docs/manual/programmability/#Read-only_scripts).
3+
For more information about when to use this command vs `FCALL`, please refer to [Read-only scripts](/docs/manual/programmability/#read-only_scripts).
44

55
For more information please refer to [Introduction to Redis Functions](/topics/functions-intro).

docs/manual/programmability/_index.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,31 @@ However, if you intend to use a slow script in your application, be aware that a
6262
## Read-only scripts
6363

6464
A read-only script is a script that only executes commands that don't modify any keys within Redis.
65-
Read-only scripts are useful because they can always be executed on replicas and can always be killed by the `SCRIPT KILL` command.
66-
Read-only scripts can be executed either by adding the `no-writes` flag to the script or by executing the script with one of the read-only script command variants: `EVAL_RO`, `EVALSHA_RO`, or `FCALL_RO`.
67-
In addition to the benefits provided by all read-only scripts, the read-only script commands are also not blocked during write pauses, such as those that occur during coordinated failovers, and can be used to configure an ACL user to only be able to execute read-only scripts.
68-
Many clients also better support routing the read-only script commands to replicas for applications that want to use replicas for read scaling.
65+
Read-only scripts can be executed either by adding the `no-writes` [flag](/topics/lua-api#script_flags) to the script or by executing the script with one of the read-only script command variants: `EVAL_RO`, `EVALSHA_RO`, or `FCALL_RO`.
66+
They have the following properties:
67+
68+
* They can always be executed on replicas.
69+
* They can always be killed by the `SCRIPT KILL` command.
70+
* They never fail with OOM error when redis is over the memory limit.
71+
* They are not blocked during write pauses, such as those that occur during coordinated failovers.
72+
* They cannot execute any command that may modify the data set.
73+
* Currently `PUBLISH`, `SPUBLISH` and `PFCOUNT` are also considered write commands in scripts, because they could attempt to propagate commands to replicas and AOF file.
74+
75+
In addition to the benefits provided by all read-only scripts, the read-only script commands have the following advantages:
76+
77+
* They can be used to configure an ACL user to only be able to execute read-only scripts.
78+
* Many clients also better support routing the read-only script commands to replicas for applications that want to use replicas for read scaling.
79+
80+
#### Read-only script history
81+
82+
Read-only scripts and read-only script commands were introduced in Redis 7.0
83+
84+
* Before Redis 7.0.1 `PUBLISH`, `SPUBLISH` and `PFCOUNT` were not considered write commands in scripts
85+
* Before Redis 7.0.1 the `no-writes` [flag](/topics/lua-api#script_flags) did not imply `allow-oom`
86+
* Before Redis 7.0.1 the `no-writes` flag did not permit the script to run during write pauses.
87+
6988

7089
The recommended approach is to use the standard scripting commands with the `no-writes` flag unless you need one of the previously mentioned features.
71-
In future versions of Redis, this extra functionality may become available to all scripts that declare the `no-writes` flag.
7290

7391
## Sandboxed script context
7492

docs/manual/programmability/lua-api.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,25 +454,32 @@ You can use the following flags and instruct the server to treat the scripts' ex
454454

455455
* `no-writes`: this flag indicates that the script only reads data but never writes.
456456

457-
By default, Redis will deny the execution of scripts against read-only replicas, as they may attempt to perform writes.
457+
By default, Redis will deny the execution of flagged scripts (Functions and Eval scripts with [shebang](/topics/eval-intro#eval-flags)) against read-only replicas, as they may attempt to perform writes.
458458
Similarly, the server will not allow calling scripts with `FCALL_RO` / `EVAL_RO`.
459459
Lastly, when data persistence is at risk due to a disk error, execution is blocked as well.
460460

461461
Using this flag allows executing the script:
462-
1. With `FCALL_RO` / `EVAL_RO` against masters and read-only replicas.
463-
2. Even if there's a disk error (Redis is unable to persist so it rejects writes).
462+
1. With `FCALL_RO` / `EVAL_RO`
463+
2. On read-only replicas.
464+
3. Even if there's a disk error (Redis is unable to persist so it rejects writes).
465+
4. When over the memory limit since it implies the script doesn't increase memory consumption (see `allow-oom` below)
464466

465467
However, note that the server will return an error if the script attempts to call a write command.
468+
Also note that currently `PUBLISH`, `SPUBLISH` and `PFCOUNT` are also considered write commands in scripts, because they could attempt to propagate commands to replicas and AOF file.
469+
470+
For more information please refer to [Read-only scripts](/docs/manual/programmability/#read-only_scripts)
466471

467472
* `allow-oom`: use this flag to allow a script to execute when the server is out of memory (OOM).
468473

469-
Unless used, Redis will deny the execution of scripts when in an OOM state, regardless of the `no-write` flag and method of calling.
474+
Unless used, Redis will deny the execution of flagged scripts (Functions and Eval scripts with [shebang](/topics/eval-intro#eval-flags)) when in an OOM state.
470475
Furthermore, when you use this flag, the script can call any Redis command, including commands that aren't usually allowed in this state.
476+
Specifying `no-writes` or using `FCALL_RO` / `EVAL_RO` also implies the script can run in OOM state (without specifying `allow-oom`)
471477

472-
* `allow-stale`: a flag that enables running the script against a stale replica.
478+
* `allow-stale`: a flag that enables running the flagged scripts (Functions and Eval scripts with [shebang](/topics/eval-intro#eval-flags)) against a stale replica when the `replica-serve-stale-data` config is set to `no` .
473479

474-
By default, Redis prevents data consistency problems from using old data by having stale replicas return a runtime error.
475-
In cases where the consistency is a lesser concern, this flag allows stale Redis replicas to run the script.
480+
Redis can be set to prevent data consistency problems from using old data by having stale replicas return a runtime error.
481+
For scripts that do not access the data, this flag can be set to allow stale Redis replicas to run the script.
482+
Note however that the script will still be unable to execute any command that accesses stale data.
476483

477484
* `no-cluster`: the flag causes the script to return an error in Redis cluster mode.
478485

0 commit comments

Comments
 (0)