From c6893e3d2c95cf93a0fad01cd0662cc00ad812bd 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 Remove references that mention SHA-1 hashes being passed when evaluating server loaded Lua scripts. The current implementation passes the script itself instead of the hash, generated when the script was initially loaded, due to resiliency concerns. --- docs/Scripting.md | 4 ++-- src/StackExchange.Redis/LuaScript.cs | 30 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/Scripting.md b/docs/Scripting.md index 56af7afc1..5ea20e380 100644 --- a/docs/Scripting.md +++ b/docs/Scripting.md @@ -35,10 +35,10 @@ Any object that exposes field or property members with the same name as @-prefix - RedisKey - RedisValue -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. +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 [`EVAL`](https://redis.io/commands/eval) is used instead of [`EVALSHA`](https://redis.io/commands/evalsha), due to resiliency concerns. 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. +`LoadedLuaScripts` are evaluated with the [`EVAL`](https://redis.io/commands/eval) command instead of [`EVALSHA`](https://redis.io/commands/evalsha), due to resiliency concerns. An example use of `LoadedLuaScript`: diff --git a/src/StackExchange.Redis/LuaScript.cs b/src/StackExchange.Redis/LuaScript.cs index 6e4ac7cd3..3a03aa3f2 100644 --- a/src/StackExchange.Redis/LuaScript.cs +++ b/src/StackExchange.Redis/LuaScript.cs @@ -166,13 +166,16 @@ public Task EvaluateAsync(IDatabaseAsync db, object? ps = null, Red /// /// - /// Loads this LuaScript into the given IServer so it can be run with it's SHA1 hash, instead of - /// using the implicit SHA1 hash that's calculated after the script is sent to the server for the first time. + /// Loads this LuaScript into the given IServer. Due to resiliency concerns, the LoadedLuaScript + /// does not evaluate the script by it's SHA-1 hash anymore. /// /// Note: the FireAndForget command flag cannot be set. /// /// The server to load the script on. /// The command flags to use. + /// + /// Previously, this method was intended provide scripts, that can be evaluated by their SHA-1 hashes. + /// public LoadedLuaScript Load(IServer server, CommandFlags flags = CommandFlags.None) { if ((flags & CommandFlags.FireAndForget) != 0) @@ -186,13 +189,16 @@ public LoadedLuaScript Load(IServer server, CommandFlags flags = CommandFlags.No /// /// - /// Loads this LuaScript into the given IServer so it can be run with it's SHA1 hash, instead of - /// using the implicit SHA1 hash that's calculated after the script is sent to the server for the first time. + /// Loads this LuaScript into the given IServer. Due to resiliency concerns, the LoadedLuaScript + /// does not evaluate the script by it's SHA-1 hash anymore. /// /// Note: the FireAndForget command flag cannot be set /// /// The server to load the script on. /// The command flags to use. + /// + /// Previously, this method was intended provide scripts, that can be evaluated by their SHA-1 hashes. + /// public async Task LoadAsync(IServer server, CommandFlags flags = CommandFlags.None) { if ((flags & CommandFlags.FireAndForget) != 0) @@ -239,7 +245,7 @@ public sealed class LoadedLuaScript /// /// The SHA1 hash of ExecutableScript. - /// This is sent to Redis instead of ExecutableScript during Evaluate and EvaluateAsync calls. + /// This is not sent to Redis, instead ExecutableScript is used during Evaluate and EvaluateAsync calls. /// /// Be aware that using hash directly is not resilient to Redis server restarts. [EditorBrowsable(EditorBrowsableState.Never)] @@ -257,14 +263,17 @@ internal LoadedLuaScript(LuaScript original, byte[] hash) /// /// Evaluates this LoadedLuaScript against the given database, extracting parameters for the passed in object if any. /// - /// This method sends the SHA1 hash of the ExecutableScript instead of the script itself. - /// If the script has not been loaded into the passed Redis instance, it will fail. + /// This method evaluates the script itself and does not send the SHA-1 hash, generated by the server when loaded initially, in order to execute it. + /// If the script has not been loaded into the passed Redis instance, it will not fail. /// /// /// The redis database to evaluate against. /// The parameter object to use. /// The key prefix to use, if any. /// The command flags to use. + /// + /// Previously, this method evaluated the script by it's SHA-1 hash. + /// 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); @@ -275,14 +284,17 @@ public RedisResult Evaluate(IDatabase db, object? ps = null, RedisKey? withKeyPr /// /// Evaluates this LoadedLuaScript against the given database, extracting parameters for the passed in object if any. /// - /// This method sends the SHA1 hash of the ExecutableScript instead of the script itself. - /// If the script has not been loaded into the passed Redis instance, it will fail. + /// This method evaluates the script itself and does not send the SHA-1 hash, generated by the server when loaded initially, in order to execute it. + /// If the script has not been loaded into the passed Redis instance, it will not fail. /// /// /// The redis database to evaluate against. /// The parameter object to use. /// The key prefix to use, if any. /// The command flags to use. + /// + /// Previously, this method evaluated the script by it's SHA-1 hash. + /// 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);