npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lured

v1.0.3

Published

Lua script loading tool for Redis.

Downloads

497

Readme

lured

NPM

stable Build Status Lua script loader for Redis.

Installation

$ npm install lured

Features

  • Makes easier for cumbersom script loading and management
  • Supports multiple scripts
  • Simple, intuitive and non-intrusive.
  • SHA values are available to user. User still has a full control. (See [Usage] section)
  • Automatically reload scripts after a reconnection. (assuming script cache may be wiped out)
  • When loading, it will try SCRIPT EXISTS before performing SCRIPT LOAD to reduce network resource usage.

API

Module method

  • create(redisClient, scripts) - Creates an instance of lured. The scripts is an object in with the following structure:
var scripts = {
    foo: {
        script: "return 1", // your lua script for 'foo'
        sha: "e0e1f9fabfc9d4800c877a703b823ac0578ff8db" // filled by lured
    },
    bar: {
        script: "return 2", // your lua script for 'bar'
        sha: "7f923f79fe76194c868d7e1d0820de36700eb649" // filled by lured
    }	
};

Where, sha properties are automatically filled by lured.

Instance method

  • lured.load(cb) - Load given scripts, then set shas to the scripts object.
  • lured.scripts (getter) - Returns the scripts object. (just for convenience)
  • Event: 'state' - Emits (using EventEmitter) state change. Possible states are; 0:CLOSED, 1:CONNECTED, 2:LOADING and 3:READY. Registered handler will have two arguments: from-state and to-state.

Usage

var fs = require('fs')
var scripts = {
    foo: {
        script: fs.readFileSync(__dirname + '/foo.lua', {encoding:'utf8'})
    },
    bar: {
        script: fs.readFileSync(__dirname + '/bar.lua', {encoding:'utf8'})
    }	
};
var client = require('redis').createClient();
var lured = require('lured').create(client, scripts);

// Load all scripts on to redis server.
lured.load(function (err) {
	if (err) { /* handler error */}
	else {
		// Do your cool stuff here
		// Now you can safely do something like this:
		client.multi()
             .evalsha(scripts.foo.sha, 0)	
             .evalsha(scripts.bar.sha, 0)
             .exec(function(err, replies) {
                 // Check your replies.
             });	
	}
});

Notes

Auto Reload

When redis client emits 'connect' event, lured will check if the scripts are still cached, if not it will reload the scripts for you. If you need to track down the underlying behavior, set a listener on 'state' event.

Why lured while there are other similar script loaders?

Script loading and management is pain. So, looked for a good tool. I wanted to use SHA values so that I can use MULTI with mixture of the scripts and other commands, but the tools I came across hide many good stuff including the SHA values, and here comes the lured!