Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
local first_updated_at = table.remove(ARGV, 1) | ||
local last_updated_at = table.remove(ARGV, 1) | ||
local file = table.remove(ARGV, 1) | ||
local file_hash = table.remove(ARGV, 1) | ||
local ttl = table.remove(ARGV, 1) | ||
local file_length = table.remove(ARGV, 1) | ||
local hash_key = table.remove(KEYS, 1) | ||
redis.call('HMSET', hash_key, 'last_updated_at', last_updated_at, 'file', file, 'file_hash', file_hash, 'file_length', file_length) | ||
redis.call('HSETNX', hash_key, 'first_updated_at', first_updated_at) | ||
for i, key in ipairs(KEYS) do | ||
if ARGV[i] == '-1' then | ||
redis.call("HSET", hash_key, key, ARGV[i]) | ||
else | ||
redis.call("HINCRBY", hash_key, key, ARGV[i]) | ||
end | ||
end | ||
if ttl ~= '-1' then | ||
redis.call("EXPIRE", hash_key, ttl) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
inspect = require "inspect" | ||
require './lua/test/redis-call' | ||
|
||
|
||
KEYS = {} | ||
ARGV = {} | ||
|
||
|
||
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 dofile('./lua/lib/' .. script) | ||
end | ||
|
||
return call_redis_script; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
redis = require 'redis' | ||
|
||
-- If you have some different host/port change it here | ||
local host = "127.0.0.1" | ||
local port = 6379 | ||
|
||
|
||
client = redis.connect(host, port) | ||
|
||
-- Workaround for absence of redis.call | ||
redis.call = function(cmd, ...) | ||
local arg={...} | ||
local args_string = '' | ||
for i,v in ipairs(arg) do | ||
args_string = args_string .. ' ' .. v | ||
end | ||
cmd = string.lower(cmd) | ||
print(cmd .. args_string) | ||
--local result = assert(load('return client:'.. 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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local call_redis_script = require "./lua/test/harness"; | ||
|
||
describe("incr-and-stor", function() | ||
|
||
-- Flush the database before running the tests | ||
before_each(function() | ||
redis.call('FLUSHDB') | ||
end) | ||
|
||
it("should add single items", function() | ||
local args = { 1569453853, 1569453853, "./dog.rb", "abcd", '-1', 3, 0, 1, 2 } | ||
local keys = {"coverband_hash_3_3.coverband_test.runtime../dog.rb.abcd", 0, 1, 2 } | ||
call_redis_script('persist-coverage.lua', keys , args ); | ||
results = redis.call('HGETALL', "coverband_hash_3_3.coverband_test.runtime../dog.rb.abcd") | ||
assert.are.same({ | ||
["0"] = "0", | ||
["1"] = "1", | ||
["2"] = "2", | ||
file = "./dog.rb", | ||
file_hash = "abcd", | ||
file_length = "3", | ||
first_updated_at = "1569453853", | ||
last_updated_at = "1569453853" | ||
}, results) | ||
end) | ||
end) |