mhunionthread.lua 771 B

1234567891011121314151617181920212223242526
  1. local result={}
  2. result.items={}
  3. local k1=KEYS[1] --未格式化key lists:user:%d
  4. local k2=KEYS[2] --过期时间
  5. local keyArr={}
  6. local outPut='output'
  7. table.insert(keyArr,outPut)
  8. table.insert(keyArr,#ARGV)
  9. for i = 1, #ARGV do
  10. local k=string.format(k1,ARGV[i])
  11. local v1=redis.call('expire',k,k2)
  12. if v1==0 then
  13. else
  14. table.insert(keyArr,k)
  15. end
  16. end
  17. redis.call('DEL',outPut)
  18. table.insert(keyArr,'WEIGHTS')
  19. for i = 1, #ARGV do
  20. table.insert(keyArr,1)
  21. end
  22. redis.call('ZUNIONSTORE',keyArr)
  23. --redis.call('ZUNIONSTORE','output',7,'lists:user:54','lists:user:427','lists:user:554','lists:user:563','lists:user:36','lists:user:795','lists:user:799','WEIGHTS',1,1,1,1,1,1,1)
  24. result.items=redis.call('ZREVRANGE',outPut,0,-1,'WITHSCORES')
  25. return cjson.encode(result)