File: moving_window.lua

package info (click to toggle)
python-limits 4.4.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,064 kB
  • sloc: python: 7,833; makefile: 162; sh: 59
file content (21 lines) | stat: -rw-r--r-- 430 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local items = redis.call('lrange', KEYS[1], 0, tonumber(ARGV[2]))
local expiry = tonumber(ARGV[1])
local a = 0
local oldest = nil

for idx=1,#items do
    if tonumber(items[idx]) >= expiry then
        a = a + 1

        local value = tonumber(items[idx])
        if oldest == nil or value < oldest then
            oldest = value
        end
    else
        break
    end
end

if oldest then
    return {tostring(oldest), a}
end