Skip to content

Commit

Permalink
fake redis support
Browse files Browse the repository at this point in the history
  • Loading branch information
yagop committed May 5, 2015
1 parent c498222 commit f935d70
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion libs/redis.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Redis = require 'redis'
local FakeRedis = require 'fakeredis'

local params = {
host = '127.0.0.1',
Expand All @@ -17,8 +18,28 @@ Redis.commands.hgetall = Redis.command('hgetall', {
local redis = nil

-- Won't launch an error if fails
pcall(function()
local ok = pcall(function()
redis = Redis.connect(params)
end)

if not ok then

local fake_func = function()
print('\27[31mRedis isn\'t installed, install it!\27[39m')
end

fake_func()
fake = FakeRedis.new()

redis = setmetatable({}, {
__index = function(a, b)
if b ~= 'data' and fake[b] then
fake_func(b)
end
return fake[b] or fake_func
end })

end


return redis

0 comments on commit f935d70

Please sign in to comment.