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

moon-bucket

v0.0.2

Published

A bucket of Lua scripts for Redis

Downloads

1

Readme

:honey_pot: moon-bucket :last_quarter_moon_with_face:

A bucket of Lua scripts for Redis.

Usage

Shell:

redis-cli eval "$(cat scripts/join.lua)" [args]

node-redis

var lua = require('moon-bucket');
var redis = require('redis');
var client = redis.createClient();

lua.init(client);

var hashMaps = lua.join('ids', 'things');

Docs

join

Redis doesn't have joins. However, we can script them with Lua.

This script lets us get hashes by their id.

Prereqs: our hashes must be namespaced namespace:*, where namespace is our namespace (for example, cars), and * is an inremental id (which resides in a foreign list of ids, such as 1 2 3 4 5 etc.)

Shell:

# redis-cli eval "$(cat scripts/join.lua)" [2|3] [foreign-key] [namespace] [optional limit]

redis-cli eval "$(cat scripts/join.lua)" 3 ids things 5

JavaScript:

var lua = require('./index.js');
var redis = require('redis');
var client = redis.createClient();

lua.init(client);

/**
 * This example requires that there exists an "ids" list of `1, 2, 3`
 * and 3 hashmaps --
 *
 * things:1
 * things:2
 * things:3
 */

var hashMaps = lua.join('ids', 'things');

/**
 * This will return the hashes things:1, things:2, and things:3
 */
console.log(hashMaps);

This will return hashes things:*, where each things:* has an ID from the list of ids with a limit of 5.

This would return 5 of our hashes, looking like this (maybe JSON, if we're using node.js):

{
  "hello": "world",
  "some_other": "property",
  "_key": "things:1"
}

As you can see, a property called _key gets automatically embedded into the hash when it is returned to us so we know to which key this object belongs.

Just want to get all of the hashes?

redis-cli eval "$(cat scripts/join.lua)" 2 ids things

By default, our limit is -1, which is the last item in the list.

Technical stuff

Internally when using node.js to call any of the methods available (like join), we're actually calling node redis' evalsha method on the corresponding sha1 hash in /sha/index.js. This is more performant, because we don't have to actually read any files from the file system (in other words, we never make a call to read anything from the scripts directory directly; instead, we just make redis evaluate the sha1 hash of the script). So, moonBucket.join(/* args */) actually calls something like redis-cli evalsha b0eff2712326fb5b1cda561a013a0fcc16cb8d85 [...args]:

// ./sha/index.js

module.exports = {
  // this is the hash of the corresponding lua script
  "join":"b0eff2712326fb5b1cda561a013a0fcc16cb8d85"
};

If you want to add your own script to scripts, you'll need to implement the method in ./index.js and then run ./.bin/compile-sha in order to re-create the sha map.

What's in a name?

"Lua" is the name of the scripting language, and the portuguese word for "moon". "Balde lua" means moon bucket.

© 2015 Josh Beam - MIT License | www.joshbe.am | [email protected]