-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharness.lua
56 lines (43 loc) · 1.43 KB
/
harness.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
redis = require 'redis'
KEYS = {}
ARGV = {}
-- If you have some different host/port change it here
local host = "redis"
local port = 6379
client = redis.connect(host, port)
-- Workaround for absence of redis.call
redis.call = function(cmd, ...)
cmd = string.lower(cmd)
local result = assert(loadstring('return client:'.. cmd ..'(...)'))(...)
-- The redis-lua library returns some values differently to how `redis.call` works inside redis.
-- this makes the responses look like those from the builtin redis
local response_lookup = {
type = function() return { ["ok"]= result } end,
sadd = function() return tonumber(result) end,
zrange = function()
if type(result) == "table" and type(result[1]) == "table" then
-- Deal with WITHSCORES...
local new_result = {}
for k,v in pairs(result) do
table.insert(new_result, v[1])
table.insert(new_result, v[2])
end
return new_result;
end
return result;
end
}
if response_lookup[cmd] then
return response_lookup[cmd]()
end
return result;
end
function call_redis_script(script, keys, argv)
-- This may not be strictly necessary
for k,v in pairs(ARGV) do ARGV[k] = nil end
for k,v in pairs(KEYS) do KEYS[k] = nil end
for k,v in pairs(keys) do table.insert(KEYS, v) end
for k,v in pairs(argv) do table.insert(ARGV, v) end
return assert(dofile(script))
end
return call_redis_script;