Doing a batch delete in redis with ohm
Question
Is there a way to delete multiple objects in redis via the ruby gem ohm? Right now to delete multiple data we do a loop and call object.delete each one of them. I would appreciate if anyone could point me to the right direction.
La solution
There doesn't appear to be a way to do this with Ohm directly, but you can drop down to the base redis gem and do it that way as Redis supports multiple keys with the delete command.
So, something like this:
Model.redis.delete *records.map(&:id)
Autres conseils
Also try,
Model.all.map &:delete
Though it may not be the best solution because it also loops through all objects, but it works or me.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow