⚠️ Internal: This API is not publically exported by the package.

Class Script<TResult>

Creates a new script.

Scripts offer the ability to optimistically try to execute a script without having to send the entire script to the server. If the script is loaded on the server, it tries again by sending the entire script. Afterwards, the script is cached on the server.

Example

const redis = new Redis({...})

const script = redis.createScript<string>("return ARGV[1];")
const arg1 = await script.eval([], ["Hello World"])
expect(arg1, "Hello World")

Type Parameters

  • TResult = unknown

Constructors

Methods

Properties

Constructors

  • Type Parameters

    • TResult = unknown

    Parameters

    • redis: Redis
    • script: string

    Returns Script<TResult>

Methods

  • Send an EVAL command to redis.

    Parameters

    • keys: string[]
    • args: string[]

    Returns Promise<TResult>

  • Calculates the sha1 hash of the script and then calls EVALSHA.

    Parameters

    • keys: string[]
    • args: string[]

    Returns Promise<TResult>

  • Optimistically try to run EVALSHA first. If the script is not loaded in redis, it will fall back and try again with EVAL.

    Following calls will be able to use the cached script

    Parameters

    • keys: string[]
    • args: string[]

    Returns Promise<TResult>

Properties

digest: any

Compute the sha1 hash of the script and return its hex representation.

redis: any
script: string
sha1: string