Socket
Socket
Sign inDemoInstall

thoonk

Package Overview
Dependencies
6
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    thoonk

Thoonk is a persistent (and fast!) system for push feeds, queues, and jobs which leverages Redis. Thoonk follows a contract (schema + behavior) to allow multiple languages and custom implementations to interact reliably.


Version published
Weekly downloads
13
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Thoonk

What is Thoonk?

Thoonk is a persistent (and fast!) framework for Redis backed live data and objects, such as push feeds, queues, and jobs.

Thoonk lets you create a Model whose methods are mapped to Redis Lua scripts, and can listen for and emit events using Redis pubsub channels.

Since all of the actual logic for the model is written in Lua, Thoonk wrappers for other languages can be written which can interoperate with thoonk.js, such as the Python version thoonk.py.

Installing

npm install thoonk

By itself, Thoonk is just a small framework for marshalling and setting up subscriptions and loading Lua scripts into Redis. To see Thoonk in action you will want to look at the examples for how to build a Thoonk backed model.

Example

First, we create our model definition in examples/helloworld.js:

var ThoonkInterface = require('thoonk').ThoonkBaseInterface;


function HelloWorld(thoonk) {
    // Link the HelloWorld object to a thoonk connection.
    ThoonkInterface.call(this, thoonk);
}

HelloWorld.prototype = Object.create(ThoonkInterface.prototype);

// Set a unique type name for our HelloWorld model
HelloWorld.prototype.objtype = 'helloworld'; 

// Specify where to load Lua scripts from for our model
HelloWorld.prototype.scriptdir = __dirname + '/scripts';

(function () {

    this.greet = function (firstName, lastName, cb) {
        this.runScript('greet', [firstName, lastName], cb);
    };

}).call(HelloWorld.prototype);


module.exports = HelloWorld;

Then we create the Lua script we need in examples/scripts/greet.lua:

local firstName, lastName = unpack(ARGV);

return "Hello, " .. firstName .. " " .. lastName;

And finally, when we want to use our HelloWorld model:

var thoonk = require('thoonk').createClient();
var HelloWorld = require('helloworld');

thoonk.registerInterface('HelloWorld', HelloWorld, function () {
    // All scripts have been loaded and event subscriptions initialized.

    var hello = thoonk.objects.HelloWorld();

    hello.greet('Arthur', 'Dent', function (err, result) {
        if (err) {
            console.error(err);
        } else {
            console.log(result);
            // >>> Hello, Arthur Dent
        }
    });
});

Addons

  • Thoonk Jobs - A Thoonk-based Redis job system

License

MIT

Created By

If you like this, follow: @fritzy on twitter.

Keywords

FAQs

Last updated on 19 Jul 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc