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 ¶
- Variables
- func SHA1(src string) string
- type Env
- type Scripts
- func (s *Scripts) Eval(src string, env Env) resp.Value
- func (s *Scripts) EvalSHA(sha string, env Env) resp.Value
- func (s *Scripts) Exists(sha string) bool
- func (s *Scripts) Flush()
- func (s *Scripts) Len() int
- func (s *Scripts) Load(src string) (string, error)
- func (s *Scripts) SHAs() []string
- func (s *Scripts) String() string
Constants ¶
This section is empty.
Variables ¶
var ErrNoScript = errors.New("NOSCRIPT No matching script. Please use EVAL.")
ErrNoScript is returned by RunSHA for an unknown sha1.
Functions ¶
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).