Last active
December 26, 2015 03:49
-
-
Save x0bandeira/7088498 to your computer and use it in GitHub Desktop.
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
# http://redis.io/commands/rpoplpush | |
module Resque | |
def self.move_queue(source, destination) | |
r = Resque.redis | |
r.llen("queue:#{source}").times do | |
r.rpoplpush("queue:#{source}", "queue:#{destination}") | |
end | |
end | |
end |
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
module Resque | |
def remove_from_queue(queue, match, redis = nil) | |
redis ||= Resque.redis | |
key = "queue:#{queue}" | |
len = redis.llen(key) | |
offset = 0 | |
(1...len).each do |n| | |
idx = n - offset | |
val = redis.lindex(key, idx) | |
break if val.nil? | |
next unless val =~ match | |
redis.lrem(key, 1, val) | |
offset += 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment