One way to do this is to pull the entries out of the queue, dispense them, shuffle the packet, and then reinsert them:
key = "resque:queue:bulk"
total = Redis.current.llen(key)
batch_size = 5_000
batch = []
total.times do |i|
entry = Redis.current.lpop(key)
batch << entry
if batch.size == batch_size
puts "re-inserting batch..."
Redis.current.rpush key, batch.shuffle
batch = []
end
end
This is really useful when you mistakenly queue up several jobs that end up racing for shared resources, locks, etc.
rafb3 source
share