Created
May 3, 2011 01:38
-
-
Save shirro/952677 to your computer and use it in GitHub Desktop.
Redis scripting memoize commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Enables calling redis('command',...) as redis.command(...) | |
if type(redis) == 'function' | |
then redis = ( | |
function() | |
local redis_call = redis | |
local mt = { | |
__call = function (self, ...) | |
return redis_call(...) | |
end, | |
__index = function (self, key) | |
local fn = function(...) | |
return redis_call(key, ...) | |
end | |
self[key] = fn | |
return fn | |
end | |
} | |
return setmetatable({}, mt) | |
end) () | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment