Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including then-redis-scripts with all npm packages installed. Try it out:

var thenRedisScripts = require("then-redis-scripts")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

then-redis-scripts v2.2.0

Script runner for redis

then-redis-scripts

Script runner for the redis package. This package loads scripts from the file system and caches them. Then uses EVALSHA to execute them. Automatically reloads the script when it is removed from the db (SCRIPT FLUSH).

Build Status Dependency Status

Usage:

var redis = require('redis');
var redisScripts = require('then-redis-scripts');

var client = redis.createClient();
var scripts = redisScripts(client, {
  base: __dirname + '/lua'
});

scripts.run('my-lua-script', [ 'key' ], [ 'argv1', 'argv2' ])
  .then(function (result) {
    console.log(result);
  });

Assuming there is a script .../lua/my-lua-script.lua

API

var scripts = redisScripts(RedisClient client, [Object options])

Returns: ScriptRunner

Builds a script runner for a certain redis client.

Option String base

Base folder for relative paths.

Option String|Object shared

Either the path to a script that should be prepended to every script that is run.

Or an object with following properties:

  • String path: path to the shared script.
  • Array<String> keys: Optional array containg KEYS for the shared script. If this array conatins a function it will be executed to obtain the value for a key each time the script is run.
  • Array<String> argv: Optional array containing ARGV for the shared script. If this array conatins a function it will be executed to obtain the value for an argument each time the script is run.

Calculating shared arguments on the fly can be useful when you want to pass a timestamp or a random seed for instance.


scripts.run(String path, [Array<String> keys], [Array<String> argv])

Returns: Promise<dynamic>

Runs a script at path. The path is resolved against the base dir. .lua extension is automatically added when not specified. keys and argv can be passed as KEYS and ARGV variables in the script.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free