I'm using Spring Data Redis. In Redis the basic data models are
job
: Hash that contains a job's data.
queue
: List that contains job ids serving as a queue.
New job will be saved in job
hash and it will be pushed to queue
. We have multiple worker clients pooling the queue
to consume new job id by popping the id and read details from hash.
Now I'm trying to work out a new feature that certain worker can only consume certain jobs, based on some flags within job data. The problem is worker will only know if it can consume the job after reading its details, but not at the moment of taking the id from the queue.
I originally thought I can put this sequence of operations into a transaction,
- Peek the queue.
- Read job details from hash and check if consumable.
- If yes, take its id from queue, otherwise do nothing.
However this kind of transaction involves both queue and hash data. After reading Redis's transaction support I'm not sure if this is achievable. Please help to advise what approach should I take.