Skip to content

Instantly share code, notes, and snippets.

@bobbrez
Created August 19, 2014 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobbrez/3ed754e70d2f24d40e6e to your computer and use it in GitHub Desktop.
Save bobbrez/3ed754e70d2f24d40e6e to your computer and use it in GitHub Desktop.
Redis RPOPZADD for Ruby
require 'redis'
class Redis
REDIS_RPOPZADD = "
local value = redis.call('zrange', KEYS[1], -1, -1)[1]
local score = redis.call('zscore', KEYS[1], value)
redis.call('zremrangebyrank', KEYS[1], -1, -1)
redis.call('zadd', KEYS[2], score, value)
return { value, score }"
def rpopzadd(source, dest)
eval REDIS_RPOPZADD, [source, dest]
end
end
Redis.current.rpopzadd :sorted_queue, :processing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment