Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. -- hmincrby for redis
  2. --
  3. -- Usage:
  4. -- redis-cli EVAL "$(cat hmincrby.lua)" 1 key field1 num1 field2 num2 ... fieldn numn
  5.  
  6. if 1 ~= table.getn(KEYS) then
  7. error("Must have exactly 1 key")
  8. end
  9.  
  10. if 0 ~= table.getn(ARGV) % 2 then
  11. error("Must have an even number of arguments")
  12. end
  13.  
  14. local results = {}
  15.  
  16. for i = 0, #ARGV / 2 - 1 do
  17. local f = ARGV[(i * 2) + 1]
  18. local n = ARGV[(i * 2) + 2]
  19. -- pcall captures the exception so the error will be in the returned array
  20. -- of results so the caller should be able to retry just the erroneous
  21. -- field/num pairs without any double counting
  22. table.insert(results, redis.pcall('HINCRBY', KEYS[1], f, n))
  23. end
  24.  
  25. return results
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement