-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.lua
More file actions
31 lines (23 loc) · 778 Bytes
/
lib.lua
File metadata and controls
31 lines (23 loc) · 778 Bytes
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
#!lua name=lib
local function zsequence(keys, args)
local lower_bound, upper_bound = unpack(args)
local values = {}
for i, k in ipairs(keys) do
local value = redis.call('ZRANGE', k, lower_bound, upper_bound, 'BYSCORE', 'LIMIT', 0, 1, 'WITHSCORES')
if #value > 0 then
value = value[2]
lower_bound = value + 1
else
value = false
end
table.insert(values, value)
end
return values
end
local function zvalue(keys, args)
local lower_bound, upper_bound = unpack(args)
local value = redis.call('ZRANGE', keys[1], lower_bound, upper_bound, 'BYSCORE', 'LIMIT', 0, 1, 'WITHSCORES')
return {value[2]} or {}
end
redis.register_function('zvalue', zvalue)
redis.register_function('zsequence', zsequence)