getCountsPerPriority-4.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const content = `--[[
  2. Get counts per provided states
  3. Input:
  4. KEYS[1] wait key
  5. KEYS[2] paused key
  6. KEYS[3] meta key
  7. KEYS[4] prioritized key
  8. ARGV[1...] priorities
  9. ]]
  10. local rcall = redis.call
  11. local results = {}
  12. local waitKey = KEYS[1]
  13. local pausedKey = KEYS[2]
  14. local prioritizedKey = KEYS[4]
  15. -- Includes
  16. --[[
  17. Function to check for the meta.paused key to decide if we are paused or not
  18. (since an empty list and !EXISTS are not really the same).
  19. ]]
  20. local function isQueuePaused(queueMetaKey)
  21. return rcall("HEXISTS", queueMetaKey, "paused") == 1
  22. end
  23. for i = 1, #ARGV do
  24. local priority = tonumber(ARGV[i])
  25. if priority == 0 then
  26. if isQueuePaused(KEYS[3]) then
  27. results[#results+1] = rcall("LLEN", pausedKey)
  28. else
  29. results[#results+1] = rcall("LLEN", waitKey)
  30. end
  31. else
  32. results[#results+1] = rcall("ZCOUNT", prioritizedKey,
  33. priority * 0x100000000, (priority + 1) * 0x100000000 - 1)
  34. end
  35. end
  36. return results
  37. `;
  38. export const getCountsPerPriority = {
  39. name: 'getCountsPerPriority',
  40. content,
  41. keys: 4,
  42. };
  43. //# sourceMappingURL=getCountsPerPriority-4.js.map