From b1d1ac0b2fc04d63e1f61e1b25bcc5dc99a9bc70 Mon Sep 17 00:00:00 2001 From: Vasil Kotsev <9307969+SonnyRR@users.noreply.github.com> Date: Tue, 25 Apr 2023 20:26:45 +0300 Subject: [PATCH] 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'. --- docs/Scripting.md | 6 ++++-- src/StackExchange.Redis/LuaScript.cs | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/Scripting.md b/docs/Scripting.md index 56af7afc1..6178bb2a0 100644 --- a/docs/Scripting.md +++ b/docs/Scripting.md @@ -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`: diff --git a/src/StackExchange.Redis/LuaScript.cs b/src/StackExchange.Redis/LuaScript.cs index 6e4ac7cd3..65ed89047 100644 --- a/src/StackExchange.Redis/LuaScript.cs +++ b/src/StackExchange.Redis/LuaScript.cs @@ -239,7 +239,6 @@ public sealed class LoadedLuaScript /// /// The SHA1 hash of ExecutableScript. - /// This is sent to Redis instead of ExecutableScript during Evaluate and EvaluateAsync calls. /// /// Be aware that using hash directly is not resilient to Redis server restarts. [EditorBrowsable(EditorBrowsableState.Never)] @@ -265,6 +264,13 @@ internal LoadedLuaScript(LuaScript original, byte[] hash) /// The parameter object to use. /// The key prefix to use, if any. /// The command flags to use. + /// + /// + /// 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. + /// + /// 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); @@ -283,6 +289,13 @@ public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPr /// The parameter object to use. /// The key prefix to use, if any. /// The command flags to use. + /// + /// + /// 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. + /// + /// public Task EvaluateAsync(IDatabaseAsync db, object? ps = null, RedisKey? withKeyPrefix = null, CommandFlags flags = CommandFlags.None) { Original.ExtractParameters(ps, withKeyPrefix, out RedisKey[]? keys, out RedisValue[]? args);