Registry / database / then-redis-scripts

then-redis-scripts

JSON →
library2.2.0jsnpmunverified

Script runner for Redis that loads Lua scripts from the file system, caches them, and executes via EVALSHA with automatic reload on SCRIPT FLUSH. Version 2.2.0 is current, stable, with low release cadence. Designed for use with the node_redis client, it simplifies managing and running Lua scripts in Redis by handling script loading, caching, and error recovery. Differentiator: automatic script caching and re-fetching if scripts are flushed from Redis server.

npm install then-redis-scripts
INSTALL
IMPORT
SIG · THEN-REDIS-SCRIPTS
T
then-redis-scripts
databasejavascriptv2.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
var redisScripts = require('then-redis-scripts');
import redisScripts from 'then-redis-scripts';
Package provides CommonJS default export; ESM import not supported.
default
const redisScripts = require('then-redis-scripts');
const { redisScripts } = require('then-redis-scripts');
Export is a function, not a named export.

Initialize script runner with a redis client and base path, then run a script with keys and args.

const redis = require('redis'); const redisScripts = require('then-redis-scripts'); const client = redis.createClient(); const scripts = redisScripts(client, { base: __dirname + '/lua' }); scripts.run('my-lua-script', ['key'], ['argv1', 'argv2']) .then(function (result) { console.log(result); }) .catch(function (err) { console.error(err); });
Debug
Known issues
gotchaScript path resolution: `.lua` extension is added automatically; avoid double extension.
fix
Pass 'my-script' instead of 'my-script.lua'.
affects: >=0.1
gotchaShared scripts with on-the-fly key/arg functions require careful synchronous execution; async functions are not supported.
fix
Use synchronous functions only for shared keys/args calculation.
affects: >=0.1
gotchaPackage depends on node_redis; does not work with ioredis or other Redis clients.
fix
Use the 'redis' package from npm, not 'ioredis' or 'redis-mock'.
affects: >=0.1
Errors
Common errors & fixes
TypeError: redisScripts is not a function
Incorrect import (named export instead of default) or using ESM import with CommonJS package.
fix
Use `const redisScripts = require('then-redis-scripts');`
Error: Cannot find module './lua/my-script.lua'
Script file missing or base path misconfigured.
fix
Ensure the Lua file exists at the resolved path relative to `base`.
Error: ERR Error running script (call to f_...): @user_script:1: ...
Lua script syntax error or runtime error.
fix
Check the Lua script for syntax errors using redis-cli or debug the script.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
redisrequiredpeer dependency; the library wraps a node_redis client
then-redis-promiseoptionalprovides promisified redis client interface; required for promise-based run method
Agent activity
20 hits · last 30 days
node
16
Meta
2
OpenAI (training)
1
Resources