Tuesday, September 18, 2012

Implementing a ReDiS COUNT command in Lua

I have recently been implementing a master/slave redis cache for our enterprise application and at certain points during the development/test phases, have found it useful to be able to query redis for the # of keys that have been inserted that match a certain regex.
redis has the 'keys' command that returns all keys that match a certain pattern, so for example, if I wanted to see all the keys that match the pattern '*:D' I would simply issue the command :

keys *:D

and redis would return a list of all keys that meet that pattern. This is all very well when the number of keys is small, but when you are handling millions of keys, it quickly becomes unmanageable. I've seen a lot of requests on the redis message boards requesting that the development team implement the COUNT command and at first thought it does seem intuitive, however its implementation would violate the O(1) performance requirements of basic commands that the developers have (rightly, in my NSHO) imposed upon themselves.

Thankfully, the redis lua integration comes quickly to your rescue. I'm not suggesting that the lua implementation of this command achieves O(1), far from it, in fact, but I'm pointing out that the functionality of a COUNT command is already easily achievable with the following simple command issued in the client :

eval "return #redis.pcall('keys', '*')" 0

Very smartly, the developers have implemented lua bindings so that if you need a command that would violate their very stringent requirements for performance, you can create as much hanging rope as you need.

Smart.

Wednesday, August 20, 2008

I will never sleep again...

Having been indulging in a little bit of amateur research into the patterns underlying disease outbreaks, I have read a number of very interesting books on the subject of hot zones (guess which book!), disease outbreak & containment and general virology recently. In each of these books, you typically find a lot of reference to declassified documents from the military and/or the USDA etc. I took it upon myself to look for several different sources of document and oh boy, did I strike a goldmine!

From now on, when I'm on dialysis, don't be surprised if I don't answer the phone or reply to text messages, I'll probably be too busy with my nose buried in a fascinating declassified document about Plum Island, or some hushed up virus outbreak. Either that or I'll be trying to finish writing my first Children's fiction story. That's a story for another blog post.

Currently, I'm browsing the CIA FOIA website (FOIA is an acronym for Freedom of Information Act and refers to the legislation requiring government departments to disclose previously classified information for public perusal) and reading an article about the 'Deception Research Program', which, you have to admit, sounds bloody fascinating! I also noticed that there are neither entries about nor references to the DRP in Wikipedia, so have undertaken my first ever wikipedia article writing excercise. Let's see where that takes us, shall we...

Tuesday, August 19, 2008

Large Hadron humour

I've seen a few different comic strips relating to the LHC recently so I thought I'd share them here, as I think they're quite funny.

http://xkcd.com/401/

http://overcompensating.com/posts/20061017.html

It seems like there's someone out there that's been spamming various notables with his eloquent arguments against powering the LHC up, here's a link to the first in a series of scans of his spam mails:

http://gizmodo.com/photogallery/lhcspam2/1001580933

I watched a fascinating presentation by Brian Cox yesterday, he is quite the charismatic spokesperson, isn't he, he's also working at CERN, on the LHC. I can't get over the fact that he was in D:REAM...