You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a read-only variant of the `EVALSHA` command that cannot execute commands that modify data.
2
2
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).
4
4
5
5
For more information about `EVALSHA` scripts please refer to [Introduction to Eval Scripts](/topics/eval-intro).
Copy file name to clipboardExpand all lines: docs/manual/programmability/_index.md
+23-5Lines changed: 23 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,13 +62,31 @@ However, if you intend to use a slow script in your application, be aware that a
62
62
## Read-only scripts
63
63
64
64
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
+
69
88
70
89
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.
Copy file name to clipboardExpand all lines: docs/manual/programmability/lua-api.md
+14-7Lines changed: 14 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -454,25 +454,32 @@ You can use the following flags and instruct the server to treat the scripts' ex
454
454
455
455
*`no-writes`: this flag indicates that the script only reads data but never writes.
456
456
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.
458
458
Similarly, the server will not allow calling scripts with `FCALL_RO` / `EVAL_RO`.
459
459
Lastly, when data persistence is at risk due to a disk error, execution is blocked as well.
460
460
461
461
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)
464
466
465
467
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)
466
471
467
472
*`allow-oom`: use this flag to allow a script to execute when the server is out of memory (OOM).
468
473
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.
470
475
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`)
471
477
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`.
473
479
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.
476
483
477
484
*`no-cluster`: the flag causes the script to return an error in Redis cluster mode.
0 commit comments