I have a mailer queue. I want to delete all Newsletter
jobs in that queue, leaving only sign_up
mails in it. I basically need to find jobs which contains the substring 'Newsletter'. How can I do it in Rails console or in redis-cli?
Asked
Active
Viewed 1,407 times
1

hexacyanide
- 88,222
- 31
- 159
- 162

lulalala
- 17,572
- 15
- 110
- 169
2 Answers
2
You basically just want to atomically delete keys with the string "Newsletter" in them as a single transaction, as I understand this. The way to do that is:
redis-cli -n [some_db] -h [some_host_name] EVAL "return redis.call('DEL', unpack(redis.call('KEYS', '*' .. ARGV[1] .. '*')))" 0 Newsletter
What you're doing in the code above is running a lua script that queries for all keys in database [some_db] that have the substring "Newsletter" in them. It then deletes them all. This is all done as one single transaction, so no other commands are run on Redis from the time KEYS
is run to the time all the related keys are deleted.
Related discussion here.
-
I am assuming I can leave -n and -h flags alone, but it gives me the error that "(error) ERR Error running script (call to f_729a221194284c3756b416201c816f2c1996514f): Wrong number of args calling Redis command From Lua script". Would you know what I did wrong? – lulalala Jun 18 '13 at 08:02
-
Another thing, I read the list of all keys (KEYS *), and do not see "Newsletter". I guess sidekiq stores the job differently. – lulalala Jun 18 '13 at 08:15
-
@lulalala yeah, "newsletter" was an example. You'll need to find exactly how it stores them for this to be effective. As for the error, make sure you're putting everything in exactly as above and are on redis 2.6+. All works fine for me, and this is a command I regularly use across multiple redis servers. – Eli Jun 18 '13 at 19:29
-
I am not sure how Sidekiq stores jobs. Would you have any idea? – lulalala Sep 16 '13 at 01:50
0
here an example to how to remove jobs:
name = 'Newsletter'
queue = Sidekiq::Queue.new
queue.each do |job|
job.delete if job.klass.include? name
end
instead of klass.include? you can in any other kind of thing to match what are u looking for.

poramo
- 546
- 5
- 7