July 23, 2017 by Marco Cecconi
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.
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:
It's available on GitHub, released under a 3-clause BSD license.
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.
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 moreMarch 12, 2023 by Marco Cecconi
Stack Overflow could benefit from adopting a using conversational AI to provide specific answers
Read moreOctober 15, 2021 by Marco Cecconi
Multiple people with my name use my email address and I can read their email, chaos ensues!
Read moreSeptember 29, 2021 by Marco Cecconi
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 moreFebruary 03, 2021 by Marco Cecconi
A lesson in building communities by Stack Overflow's most prominent community manager emeritus, Shog9
Read moreDecember 02, 2020 by Marco Cecconi
Some lessons learned over the past 8 years of remote work in some of the best remote companies on the planet
Read more$ wget -O - hackurls.com/ascii | less
Read more…