Übernehme fehlende Änderungen

This commit is contained in:
Andreas Bielawski
2016-08-15 23:26:16 +02:00
parent dbf323a02a
commit b8ce686e11
2 changed files with 27 additions and 19 deletions

View File

@ -1,13 +1,6 @@
local Redis = require 'redis'
local FakeRedis = require 'fakeredis'
local params = {
host = os.getenv('REDIS_HOST') or '127.0.0.1',
port = tonumber(os.getenv('REDIS_PORT') or 6379)
}
local database = os.getenv('REDIS_DB')
local password = os.getenv('REDIS_PASSWORD')
local config = require('config')
-- Overwrite HGETALL
Redis.commands.hgetall = Redis.command('hgetall', {
@ -22,7 +15,15 @@ local redis = nil
-- Won't launch an error if fails
local ok = pcall(function()
redis = Redis.connect(params)
if config.redis.use_socket and config.redis.socket_path then
redis = Redis.connect(config.redis.socket_path)
else
local params = {
host = config.redis.host,
port = config.redis.port
}
redis = Redis.connect(params)
end
end)
if not ok then
@ -33,9 +34,6 @@ if not ok then
fake_func()
fake = FakeRedis.new()
print('\27[31mRedis addr: '..params.host..'\27[39m')
print('\27[31mRedis port: '..params.port..'\27[39m')
redis = setmetatable({fakeredis=true}, {
__index = function(a, b)
if b ~= 'data' and fake[b] then
@ -45,13 +43,13 @@ if not ok then
end })
else
if password then
redis:auth(password)
if config.redis.password then
redis:auth(config.redis.password)
end
if database then
redis:select(database)
if config.redis.database then
redis:select(config.redis.database)
end
end
return redis
return redis