Announcing Cthulhu, a JavaScript interpreter for Redis

Salvatore Sanfilippo, a.k.a. Antirez and Redis Labs just announced the release of Redis 4.0. One of the most prominent features is the support for modules, Redis extensions that can add commands available to clients.

I've had the pleasure of working a bit with Salvatore for the past few months learning the ropes of Redis and C, and one of the results of this collaboration is Cthulhu, a JavaScript interpreter for Redis.

courtesy of https:\//www.flickr.com/photos/gwendalcentrifugue/18161295638/in/album-72157651670726983/
Hopefully this is an allowed CC usage of the image!

Basically, it allows you to write a Redis module in JavaScript. The Redis module API is supported and exposed through an object oriented interface.

You can get started by following the super simple instructions on github.

What can you do with Cthulhu?

For example, you can manipulate any object in the Redis DB. For example, here's how to create a function to delete the top values of a Sorted Set:

function DeleteTop(name, num) {
    var set = new Redis.SortedSet(name);
    var i = 0;
    var range = set.getRange();
    range.each(function(elem){
        if (i++<num) {
            set.remove(elem.key);
        }
    });
}

You can put this in a file called deleteTop.js, load it with cthulhu into Redis and you will have a new command available:

INVOKE DeleteTop <name> <num>

For example:

example

How do I get it?

It's available on GitHub, released under a 3-clause BSD license.

Other features

Right now, the API supports all the low level APIs available through Redis Modules, with one notable exception: the generic RedisModule_Call() which would allow any command to be passed to Redis as if the extension was a client. I'm a bit torn on that because of replication issues.

Speaking of replication, calling Redis.setAutoReplicate( true ); from JavaScript automatically replicates all side effects of your JavaScript modules onto any slave servers that might be present.

For more information the test.js file contains example of all the APIs which are also documented in the GitHub project.

Roadmap

If enough people find this useful, I plan to implement the new (still not official, experimental) threading APIs so that long running, background processes can be written with Cthulhu.

I'm also planning to support more features out of Redis either by extending the RedisModule API. or by internally simulating new APIs by making use of judicious RedisModule_Call().

More on the roadmap on the GitHub roadmap page.


Hi, I'm Marco Cecconi. I am the founder of Intelligent Hack, developer, hacker, blogger, conference lecturer. Bio: ex Stack Overflow core team, ex Toptal EM.

Read more

Newest Posts

What can Stack Overflow learn from ChatGPT?

Stack Overflow could benefit from adopting a using conversational AI to provide specific answers

Read more
Fan mail

Multiple people with my name use my email address and I can read their email, chaos ensues!

Read more
Intelligent Trip

After years of building, our top-notch consultancy to help start-ups and scale-ups create great, scalable products, I think it is high time I added an update to how it is going and what's next for us.

Read more
Guest blog: Building, in partnership with communities by Shog9

A lesson in building communities by Stack Overflow's most prominent community manager emeritus, Shog9

Read more
Can you migrate a company from on-premise to remote-only?

Some lessons learned over the past 8 years of remote work in some of the best remote companies on the planet

Read more

Gleanings

No, I Don’t Want to Subscribe to Your Newsletter
The Bureau of Programming • Feb 25, 2017

No, I don’t want to subscribe to your newsletter. No, I don’t want to complete a short survey. And no, I don’t want to become a member.

Read more…