- Updated all component headers and documentation
- Changed navbar and footer branding
- Updated homepage hero badge
- Modified page title in index.html
- Simplified footer text to 'Built with ❤️'
- Consistent V2 capitalization across all references
50 lines
1.3 KiB
Lua
50 lines
1.3 KiB
Lua
--[[
|
|
Paginate a set or hash
|
|
|
|
Input:
|
|
KEYS[1] key pointing to the set or hash to be paginated.
|
|
|
|
ARGV[1] page start offset
|
|
ARGV[2] page end offset (-1 for all the elements)
|
|
ARGV[3] cursor
|
|
ARGV[4] offset
|
|
ARGV[5] max iterations
|
|
ARGV[6] fetch jobs?
|
|
|
|
Output:
|
|
[cursor, offset, items, numItems]
|
|
]]
|
|
local rcall = redis.call
|
|
|
|
-- Includes
|
|
--- @include "includes/findPage"
|
|
|
|
local key = KEYS[1]
|
|
local scanCommand = "SSCAN"
|
|
local countCommand = "SCARD"
|
|
local type = rcall("TYPE", key)["ok"]
|
|
|
|
if type == "none" then
|
|
return {0, 0, {}, 0}
|
|
elseif type == "hash" then
|
|
scanCommand = "HSCAN"
|
|
countCommand = "HLEN"
|
|
elseif type ~= "set" then
|
|
return
|
|
redis.error_reply("Pagination is only supported for sets and hashes.")
|
|
end
|
|
|
|
local numItems = rcall(countCommand, key)
|
|
local startOffset = tonumber(ARGV[1])
|
|
local endOffset = tonumber(ARGV[2])
|
|
if endOffset == -1 then
|
|
endOffset = numItems
|
|
end
|
|
local pageSize = (endOffset - startOffset) + 1
|
|
|
|
local cursor, offset, items, jobs = findPage(key, scanCommand, startOffset,
|
|
pageSize, ARGV[3], tonumber(ARGV[4]),
|
|
tonumber(ARGV[5]), ARGV[6])
|
|
|
|
return {cursor, offset, items, numItems, jobs}
|