Skip to content

Instantly share code, notes, and snippets.

@shirro
Created May 3, 2011 01:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirro/952677 to your computer and use it in GitHub Desktop.
Save shirro/952677 to your computer and use it in GitHub Desktop.
Redis scripting memoize commands
-- 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