Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address misleading documentation #2444

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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