@@ -22,14 +22,15 @@ const ATOMS = 'a'
22
22
const READ_MATCHING_COLLECTION = `\
23
23
local collections_prefix = ARGV[1];
24
24
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
29
29
30
30
local function read_collection (id)
31
31
local rows = {};
32
32
33
+ redis.log(redis.LOG_DEBUG, 'scanning for collection rows (rows_prefix: ' .. rows_prefix .. ')');
33
34
local cursor = "0";
34
35
while true do
35
36
-- todo: pass in collection rows prefix
@@ -43,22 +44,28 @@ local function read_collection (id)
43
44
44
45
if when >= when_min and when <= when_max
45
46
then
47
+ redis.log(redis.LOG_VERBOSE, 'collection row ' .. i .. ' matches');
46
48
local row = redis.call("get", key);
47
49
table.insert(rows, {i, row});
50
+ else
51
+ redis.log(redis.LOG_VERBOSE, 'collection row ' .. i .. ' doesn\\'t match (when: ' .. when .. ')');
48
52
end
49
53
end
50
54
51
55
if cursor == "0" then
56
+ redis.log(redis.LOG_VERBOSE, 'done scanning for collection rows');
52
57
break
53
58
end
54
59
end
55
60
56
61
return rows;
57
62
end
58
63
64
+ redis.log(redis.LOG_DEBUG, 'scanning for collections (collections_prefix: ' .. collections_prefix .. ')');
59
65
local cursor = "0";
60
66
while true do
61
67
-- todo: scan in reverse order to, when in doubt, get the latest collection
68
+ -- todo: COUNT 30 instead?
62
69
local res = redis.call("scan", cursor, "match", collections_prefix .. "*", "COUNT", 100);
63
70
cursor = res[1];
64
71
@@ -70,17 +77,24 @@ while true do
70
77
then
71
78
local col = redis.call("get", key);
72
79
local _, __, id, when, duration = string.find(col, "([^:]+):([^:]+):([^:]+)");
80
+ redis.log(redis.LOG_VERBOSE, 'id: ' .. id .. 'when: ' .. when .. ' duration: ' .. duration);
73
81
when = tonumber(when);
74
82
duration = tonumber(duration);
75
83
76
84
if when <= when_min and (when + duration) >= when_max
77
85
then
86
+ redis.log(redis.LOG_VERBOSE, 'collection ' .. id .. ' matches');
78
87
return read_collection(id);
88
+ else
89
+ redis.log(redis.LOG_VERBOSE, 'collection ' .. id .. ' doesn\\'t match (when: ' .. when .. ' duration: ' .. duration .. ')');
79
90
end
91
+ else
92
+ redis.log(redis.LOG_VERBOSE, 'collection ' .. id .. ' doesn\\'t match (created: ' .. created .. ')');
80
93
end
81
94
end
82
95
83
96
if cursor == "0" then
97
+ redis.log(redis.LOG_VERBOSE, 'done scanning for collections');
84
98
break
85
99
end
86
100
end
@@ -90,9 +104,10 @@ return nil;
90
104
91
105
const READ_MATCHING_ATOM = `\
92
106
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
95
109
110
+ redis.log(redis.LOG_DEBUG, 'scanning for atoms (prefix: ' .. prefix .. ')');
96
111
local cursor = "0";
97
112
while true do
98
113
-- todo: scan in reverse order to, when in doubt, get the latest atom
@@ -107,10 +122,13 @@ while true do
107
122
then
108
123
local atom = redis.call("get", key);
109
124
return atom;
125
+ else
126
+ redis.log(redis.LOG_VERBOSE, 'atom doesn\\'t match (created: ' .. created .. ')');
110
127
end
111
128
end
112
129
113
130
if cursor == "0" then
131
+ redis.log(redis.LOG_VERBOSE, 'done scanning for atoms');
114
132
break
115
133
end
116
134
end
0 commit comments