Skip to content

Commit b1d1ac0

Browse files
committed
Address misleading documentation
Add remarks for the evaluation methods of the 'LoadedLuaScript' abstraction which explicitly state that if a SHA-1 hash, of a previously loaded Lua script, was not found in the server cache - it will be reloaded with 'SCRIPT LOAD'. The first evaluation of the reloaded script will be carried out by the 'EVAL' command, but any subsequent evaluations will use 'EVALSHA'.
1 parent 571d832 commit b1d1ac0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

docs/Scripting.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ Any object that exposes field or property members with the same name as @-prefix
3737

3838
StackExchange.Redis handles Lua script caching internally. It automatically transmits the Lua script to redis on the first call to 'ScriptEvaluate'. For further calls of the same script only the hash with [`EVALSHA`](https://redis.io/commands/evalsha) is used.
3939

40-
For more control of the Lua script transmission to redis, `LuaScript` objects can be converted into `LoadedLuaScript`s via `LuaScript.Load(IServer)`.
41-
`LoadedLuaScripts` are evaluated with the [`EVALSHA`](https://redis.io/commands/evalsha), and referred to by hash.
40+
For more control of the Lua script transmission to redis, `LoadedLuaScripts` are evaluated with the [`EVALSHA`](https://redis.io/commands/evalsha), and referred to by hash.
41+
42+
If a previously loaded `Lua` script `SHA-1` hash was not found on the server, the script will be reloaded on the next call to `Evaluate()` or `EvaluateAsync()` with `SCRIPT LOAD`.
43+
The first evaluation of a reloaded script will be carried out by the `EVAL` redis command, any subsequent evaluations will use `EVALSHA`.
4244

4345
An example use of `LoadedLuaScript`:
4446

src/StackExchange.Redis/LuaScript.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ public sealed class LoadedLuaScript
239239

240240
/// <summary>
241241
/// <para>The SHA1 hash of ExecutableScript.</para>
242-
/// <para>This is sent to Redis instead of ExecutableScript during Evaluate and EvaluateAsync calls.</para>
243242
/// </summary>
244243
/// <remarks>Be aware that using hash directly is not resilient to Redis server restarts.</remarks>
245244
[EditorBrowsable(EditorBrowsableState.Never)]
@@ -265,6 +264,13 @@ internal LoadedLuaScript(LuaScript original, byte[] hash)
265264
/// <param name="ps">The parameter object to use.</param>
266265
/// <param name="withKeyPrefix">The key prefix to use, if any.</param>
267266
/// <param name="flags">The command flags to use.</param>
267+
/// <remarks>
268+
/// <para>
269+
/// If a previously loaded script hash was not found in the server cache, the script will be reloaded.
270+
/// After the SCRIPT LOAD command is executed to reload the script, EVAL will be used only once to execute it.
271+
/// Any subsequent evaluations of the same script will use EVALSHA.
272+
/// </para>
273+
/// </remarks>
268274
public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
269275
{
270276
Original.ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);
@@ -283,6 +289,13 @@ public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPr
283289
/// <param name="ps">The parameter object to use.</param>
284290
/// <param name="withKeyPrefix">The key prefix to use, if any.</param>
285291
/// <param name="flags">The command flags to use.</param>
292+
/// <remarks>
293+
/// <para>
294+
/// If a previously loaded script hash was not found in the server cache, the script will be reloaded.
295+
/// After the SCRIPT LOAD command is executed to reload the script, EVAL will be used only once to execute it.
296+
/// Any subsequent evaluations of the same script will use EVALSHA.
297+
/// </para>
298+
/// </remarks>
286299
public Task<RedisResult> EvaluateAsync(IDatabaseAsync db, object? ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
287300
{
288301
Original.ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);

0 commit comments

Comments
 (0)