Skip to content

Scripts execution always uses EVAL with multi. #2084

Closed as not planned
Closed as not planned

Description

@tugtugtug

The implementation of the multi script execution seems to check a local map

readonly scriptsInUse = new Set<string>();
for whether to use the EVAL or EVALSHA for script execution.
However, multi is always re-initiated for every transaction or pipeline execution, thus this means the script executed in the multi always end up with a EVAL with the full script uploaded over and over again.
In v3, I used to run "SCRIPT LOAD" for all scripts and then all subsequent commands would use evalsha. And if evalsha fails with NOSCRIPT, then the script is reloaded to redis again. I think redis v4 can implement similar approach and only need to handle the corner case of NOSCRIPT when it arises.

Node.js Version: v16.14.2
Redis Server Version: 6.2.5
Node Redis Version: [email protected]
Platform: Debian bullseye

Activity

  1. marcbachmann commented on Feb 26, 2024

    @marcbachmann

    In ioredis I've solved this by caching script load information using a weakmap against the socket:
    https://github.com/redis/ioredis/blob/ec42c82ceab1957db00c5175dfe37348f1856a93/lib/Script.ts#L29-L36

    Whenever a custom script command gets execute, it uses either eval or evalsha.

  2. github-actions commented on Nov 11, 2026

    @github-actions

    This issue has been automatically marked as stale due to inactivity.
    It will be closed in 30 days if no further activity occurs.
    If you believe this issue is still relevant, please add a comment to keep it open.

  3. nkaradzhov commented on Nov 20, 2026

    @nkaradzhov
    Collaborator

    Closing this as not planned. The server already caches a script sent with EVAL, so the cost here is the bytes of the source once per batch. Tracking the server's script cache on the client side would add a way for a MULTI to partly fail with NOSCRIPT (see #3647). If this causes a real cost in your application, please open a new issue with the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions