scripting

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package scripting runs server-side JavaScript (EVAL/EVALSHA) with goja.

The package doesn't know the command engine: Run receives a Call function that executes one command and returns its reply. Atomicity (holding every shard lock while the script runs) is the caller's job.

Inside a script: KEYS and ARGV (arrays of strings), cb.call(cmd, ...args) (throws on an error reply), cb.pcall (returns {err: msg} instead) and cb.log(...). The script body is wrapped in a function, so `return` works.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoScript = errors.New("NOSCRIPT No matching script. Please use EVAL.")

ErrNoScript is returned by RunSHA for an unknown sha1.

Functions

func SHA1

func SHA1(src string) string

SHA1 returns the lowercase hex sha1 of src.

Types

type Env

type Env struct {
	Keys, Argv []string
	// Call runs one command (args[0] is its name) and returns the reply.
	Call func(args []string) resp.Value
	// Log receives cb.log output (default: the standard logger).
	Log func(msg string)
	// Timeout interrupts the script (0 = none).
	Timeout time.Duration
}

Env is what a script run gets from the server.

type Scripts

type Scripts struct {
	// contains filtered or unexported fields
}

Scripts is the SCRIPT LOAD cache (sha1 → compiled script).

func New

func New() *Scripts

func (*Scripts) Eval

func (s *Scripts) Eval(src string, env Env) resp.Value

Eval compiles (and caches) src, then runs it.

func (*Scripts) EvalSHA

func (s *Scripts) EvalSHA(sha string, env Env) resp.Value

EvalSHA runs a cached script.

func (*Scripts) Exists

func (s *Scripts) Exists(sha string) bool

Exists reports whether sha is cached (case-insensitive).

func (*Scripts) Flush

func (s *Scripts) Flush()

Flush empties the cache.

func (*Scripts) Len

func (s *Scripts) Len() int

Len returns the number of cached scripts.

func (*Scripts) Load

func (s *Scripts) Load(src string) (string, error)

Load compiles src, caches it and returns its sha1.

func (*Scripts) SHAs

func (s *Scripts) SHAs() []string

SHAs returns every cached sha1, sorted.

func (*Scripts) String

func (s *Scripts) String() string

String describes the scripts cache (for INFO).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL