getCounts-1.lua 872 B

123456789101112131415161718192021222324252627282930313233343536
  1. --[[
  2. Get counts per provided states
  3. Input:
  4. KEYS[1] 'prefix'
  5. ARGV[1...] types
  6. ]]
  7. local rcall = redis.call;
  8. local prefix = KEYS[1]
  9. local results = {}
  10. for i = 1, #ARGV do
  11. local stateKey = prefix .. ARGV[i]
  12. if ARGV[i] == "wait" or ARGV[i] == "paused" then
  13. -- Markers in waitlist DEPRECATED in v5: Remove in v6.
  14. local marker = rcall("LINDEX", stateKey, -1)
  15. if marker and string.sub(marker, 1, 2) == "0:" then
  16. local count = rcall("LLEN", stateKey)
  17. if count > 1 then
  18. rcall("RPOP", stateKey)
  19. results[#results+1] = count-1
  20. else
  21. results[#results+1] = 0
  22. end
  23. else
  24. results[#results+1] = rcall("LLEN", stateKey)
  25. end
  26. elseif ARGV[i] == "active" then
  27. results[#results+1] = rcall("LLEN", stateKey)
  28. else
  29. results[#results+1] = rcall("ZCARD", stateKey)
  30. end
  31. end
  32. return results