Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8009363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:25:41+00:00 2026-06-04T18:25:41+00:00

I am attempting to build a job queue using two redis master servers in

  • 0

I am attempting to build a job queue using two redis master servers in two EC2 availability zones. All LPUSH operations are done in the application layer to both master machines in both AZs. Ideally I would be using GitHub’s resque, but resque does not seem to have any notion of multiple masters in multiple AZs.

I need to ensure only one worker is working on a given job. Some workers will be in AZ 1A talking to the redis machine in 1A, and some will be in AZ 1B talking to the machine in 1B. I need to avoid the scenario where a worker in 1A and a worker in 1B both deque the same job from different redis masters and try to work on it simultaneously.

Does this worker pseudocode have any race conditions that I may have missed?

job_id = master1.BRPOPLPUSH "queue", "working"
m1lock = master1.SETNX "lock.#{job_id}"
m2lock = master2.SETNX "lock.#{job_id}"
completed = master1.ZSCORE "completed", job_id

if completed
  # must have been completed just now on other server, no-op
  master1.LREM "working", 0, job_id
  master1.del "lock.#{job_id}"
  master2.del "lock.#{job_id}"
elsif not m1lock or not m2lock
  # other server is working on it? We will put back at the end of our queue
  master1.LPUSH "queue", job_id
  master1.LREM "working", 0, job_id
  master1.del "lock.#{job_id}" if m1lock
  master2.del "lock.#{job_id}" if m2lock
else
  # have a lock, it's not complete, so do work
  do_work(job_id)

  now = Time.now.to_i
  master1.ZADD "completed", now, job_id
  master2.ZADD "completed", now, job_id

  master1.del "lock.#{job_id}"
  master2.del "lock.#{job_id}"

  master1.LREM "working", 0, job_id
  master2.LREM "queue", 0, job_id # not strictly necessary b/c of "completed"
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:25:43+00:00Added an answer on June 4, 2026 at 6:25 pm

    what you are trying to do in essence is master-master replication, whether it’s a queue or anything else, redis doesn’t support it, and your pseudo code has race conditions.
    just doing:

    m1lock = master1.SETNX "lock.#{job_id}"
    m2lock = master2.SETNX "lock.#{job_id}"
    

    means another worker can take the job while you are doing this, and two workers will work on it at once.
    I don’t think redis is ideal for your pattern, and I don’t know any queue server that can work that way, but then again, I don’t know many such servers, so I’m sure there is.

    If you load balance your work so that only one master gets a job at once, it is possible, but then you have two queues in essence, not one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to build a project called DropThings but I am getting all these
I'm attempting to build a ASP.NET website using MSBuild - specifically the AspNetCompiler tag.
I am attempting to build a simple WPF Application using msbuild via a custom
I am evaluating Microstrategy 9.0.1 and attempting to build a prototype metadata layer using
I am attempting to build an authentication mechanism using API keys for access. As
I am attempting to build a database for inventory control using a large number
I am attempting to build a simple content management system using Twitter's Bootstrap for
I'm attempting to build a currency converter function in PHP. I have all my
I'm attempting to build my first universal iOS app using the default Xcode templates
I'm attempting to run a parallel job in R using snow. I've been able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.