que_pop.lua 990 B

123456789101112131415161718192021222324252627282930313233343536
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by Administrator.
  4. --- DateTime: 2018-03-13 10:42
  5. ---
  6. local queueKey = KEYS[1]
  7. local inFlightKey = KEYS[2]
  8. local freqKey = KEYS[3]
  9. local now = ARGV[1]
  10. local payload = nil
  11. local not_empty = function(x)
  12. return (type(x) == 'table') and (not x.err) and (#x ~= 0)
  13. end
  14. local ok, queueType = next(redis.call('TYPE', queueKey))
  15. if queueType == 'zset' then
  16. local i, lPayload = next(redis.call('ZRANGEBYSCORE', queueKey, '-inf', now, 'LIMIT' , '0' , '1'))
  17. if lPayload then
  18. payload = lPayload
  19. local frequency = redis.call('HGET', freqKey, payload)
  20. if frequency then
  21. redis.call('ZINCRBY', queueKey, frequency, payload)
  22. else
  23. redis.call('ZREM', queueKey, payload)
  24. end
  25. end
  26. elseif queueType == 'list' then
  27. payload = redis.call('LPOP', queueKey)
  28. ---if payload then
  29. --- redis.call('LPUSH', inFlightKey, payload)
  30. ---end
  31. end
  32. return payload