Created
August 19, 2014 21:47
-
-
Save bobbrez/3ed754e70d2f24d40e6e to your computer and use it in GitHub Desktop.
Redis RPOPZADD for Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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