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.



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:

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.