Skip to content

Commit

Permalink
Address misleading documentation
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
SonnyRR committed May 3, 2023
1 parent 571d832 commit b1d1ac0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 4 additions & 2 deletions docs/Scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ Any object that exposes field or property members with the same name as @-prefix

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.

For more control of the Lua script transmission to redis, `LuaScript` objects can be converted into `LoadedLuaScript`s via `LuaScript.Load(IServer)`.
`LoadedLuaScripts` are evaluated with the [`EVALSHA`](https://redis.io/commands/evalsha), and referred to by hash.
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.

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`.
The first evaluation of a reloaded script will be carried out by the `EVAL` redis command, any subsequent evaluations will use `EVALSHA`.

An example use of `LoadedLuaScript`:

Expand Down
15 changes: 14 additions & 1 deletion src/StackExchange.Redis/LuaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ public sealed class LoadedLuaScript

/// <summary>
/// <para>The SHA1 hash of ExecutableScript.</para>
/// <para>This is sent to Redis instead of ExecutableScript during Evaluate and EvaluateAsync calls.</para>
/// </summary>
/// <remarks>Be aware that using hash directly is not resilient to Redis server restarts.</remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
Expand All @@ -265,6 +264,13 @@ internal LoadedLuaScript(LuaScript original, byte[] hash)
/// <param name="ps">The parameter object to use.</param>
/// <param name="withKeyPrefix">The key prefix to use, if any.</param>
/// <param name="flags">The command flags to use.</param>
/// <remarks>
/// <para>
/// If a previously loaded script hash was not found in the server cache, the script will be reloaded.
/// After the SCRIPT LOAD command is executed to reload the script, EVAL will be used only once to execute it.
/// Any subsequent evaluations of the same script will use EVALSHA.
/// </para>
/// </remarks>
public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
{
Original.ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);
Expand All @@ -283,6 +289,13 @@ public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPr
/// <param name="ps">The parameter object to use.</param>
/// <param name="withKeyPrefix">The key prefix to use, if any.</param>
/// <param name="flags">The command flags to use.</param>
/// <remarks>
/// <para>
/// If a previously loaded script hash was not found in the server cache, the script will be reloaded.
/// After the SCRIPT LOAD command is executed to reload the script, EVAL will be used only once to execute it.
/// Any subsequent evaluations of the same script will use EVALSHA.
/// </para>
/// </remarks>
public Task<RedisResult> EvaluateAsync(IDatabaseAsync db, object? ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None)
{
Original.ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);
Expand Down

0 comments on commit b1d1ac0

Please sign in to comment.