This document describes the host contract required by the Redis Lua WASM engine.
- The engine calls host functions to implement
redis.call,redis.pcall, andredis.log. - All arguments are binary-safe and passed as
Buffervalues. - Replies must be shaped as Redis-compatible reply values.
export type RedisCallHandler = (args: Buffer[]) => ReplyValue;
export type RedisLogHandler = (level: number, message: Buffer) => void;
export type RedisHost = {
redisCall: RedisCallHandler;
redisPcall: RedisCallHandler;
log: RedisLogHandler;
};- Invoked for
redis.call(...). - Receives the command name and arguments as
Buffer[]. - May throw to signal an error; the engine converts it to
{ err: Buffer }.
- Invoked for
redis.pcall(...). - Receives the command name and arguments as
Buffer[]. - Should return
{ err: Buffer }instead of throwing.
- Invoked for
redis.log(level, message). levelis the numeric Redis log level.messageis a binary-safeBuffer.
export type ReplyValue =
| null
| number
| bigint
| Buffer
| { ok: Buffer }
| { err: Buffer }
| ReplyValue[];- No string coercion is applied to arguments.
- If you need strings, decode them from
Bufferwith an explicit encoding. - To return binary data, return a
Bufferor{ ok: Buffer }.