Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/upstash_redis/pkg/script.ts>Script

HTTP based Redis Client for Serverless and Edge Functions
Go to Latest
class Script
import { Script } from "https://deno.land/x/upstash_redis@v1.18.4/pkg/script.ts";

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.

Examples

Example 1

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

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

Constructors

new
Script(redis: Redis, script: string)

Type Parameters

optional
TResult = unknown

Properties

private
readonly
redis: Redis
readonly
script: string
readonly
sha1: string

Methods

private
digest(s: string): string

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

eval(keys: string[], args: string[]): Promise<TResult>

Send an EVAL command to redis.

evalsha(keys: string[], args: string[]): Promise<TResult>

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

exec(keys: string[], args: string[]): 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