Skip to content

Commit e6aeb85

Browse files
committed
Redis store: Lua code: add debug logging, put comments
1 parent 96133ce commit e6aeb85

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

stores/redis.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ const ATOMS = 'a'
2222
const READ_MATCHING_COLLECTION = `\
2323
local collections_prefix = ARGV[1];
2424
local rows_prefix = ARGV[2];
25-
local created_min = tonumber(ARGV[3]);
26-
local created_max = tonumber(ARGV[4]);
27-
local when_min = tonumber(ARGV[5]);
28-
local when_max = tonumber(ARGV[6]);
25+
local created_min = tonumber(ARGV[3]); -- UNIX epoch in seconds
26+
local created_max = tonumber(ARGV[4]); -- UNIX epoch in seconds
27+
local when_min = tonumber(ARGV[5]); -- UNIX epoch in milliseconds
28+
local when_max = tonumber(ARGV[6]); -- UNIX epoch in milliseconds
2929
3030
local function read_collection (id)
3131
local rows = {};
3232
33+
redis.log(redis.LOG_DEBUG, 'scanning for collection rows (rows_prefix: ' .. rows_prefix .. ')');
3334
local cursor = "0";
3435
while true do
3536
-- todo: pass in collection rows prefix
@@ -43,22 +44,28 @@ local function read_collection (id)
4344
4445
if when >= when_min and when <= when_max
4546
then
47+
redis.log(redis.LOG_VERBOSE, 'collection row ' .. i .. ' matches');
4648
local row = redis.call("get", key);
4749
table.insert(rows, {i, row});
50+
else
51+
redis.log(redis.LOG_VERBOSE, 'collection row ' .. i .. ' doesn\\'t match (when: ' .. when .. ')');
4852
end
4953
end
5054
5155
if cursor == "0" then
56+
redis.log(redis.LOG_VERBOSE, 'done scanning for collection rows');
5257
break
5358
end
5459
end
5560
5661
return rows;
5762
end
5863
64+
redis.log(redis.LOG_DEBUG, 'scanning for collections (collections_prefix: ' .. collections_prefix .. ')');
5965
local cursor = "0";
6066
while true do
6167
-- todo: scan in reverse order to, when in doubt, get the latest collection
68+
-- todo: COUNT 30 instead?
6269
local res = redis.call("scan", cursor, "match", collections_prefix .. "*", "COUNT", 100);
6370
cursor = res[1];
6471
@@ -70,17 +77,24 @@ while true do
7077
then
7178
local col = redis.call("get", key);
7279
local _, __, id, when, duration = string.find(col, "([^:]+):([^:]+):([^:]+)");
80+
redis.log(redis.LOG_VERBOSE, 'id: ' .. id .. 'when: ' .. when .. ' duration: ' .. duration);
7381
when = tonumber(when);
7482
duration = tonumber(duration);
7583
7684
if when <= when_min and (when + duration) >= when_max
7785
then
86+
redis.log(redis.LOG_VERBOSE, 'collection ' .. id .. ' matches');
7887
return read_collection(id);
88+
else
89+
redis.log(redis.LOG_VERBOSE, 'collection ' .. id .. ' doesn\\'t match (when: ' .. when .. ' duration: ' .. duration .. ')');
7990
end
91+
else
92+
redis.log(redis.LOG_VERBOSE, 'collection ' .. id .. ' doesn\\'t match (created: ' .. created .. ')');
8093
end
8194
end
8295
8396
if cursor == "0" then
97+
redis.log(redis.LOG_VERBOSE, 'done scanning for collections');
8498
break
8599
end
86100
end
@@ -90,9 +104,10 @@ return nil;
90104

91105
const READ_MATCHING_ATOM = `\
92106
local prefix = ARGV[1];
93-
local created_min = tonumber(ARGV[2]);
94-
local created_max = tonumber(ARGV[3]);
107+
local created_min = tonumber(ARGV[2]); -- UNIX epoch in seconds
108+
local created_max = tonumber(ARGV[3]); -- UNIX epoch in seconds
95109
110+
redis.log(redis.LOG_DEBUG, 'scanning for atoms (prefix: ' .. prefix .. ')');
96111
local cursor = "0";
97112
while true do
98113
-- todo: scan in reverse order to, when in doubt, get the latest atom
@@ -107,10 +122,13 @@ while true do
107122
then
108123
local atom = redis.call("get", key);
109124
return atom;
125+
else
126+
redis.log(redis.LOG_VERBOSE, 'atom doesn\\'t match (created: ' .. created .. ')');
110127
end
111128
end
112129
113130
if cursor == "0" then
131+
redis.log(redis.LOG_VERBOSE, 'done scanning for atoms');
114132
break
115133
end
116134
end

0 commit comments

Comments
 (0)