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 6237775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:05:36+00:00 2026-05-24T11:05:36+00:00

My Node.js application accepts connections from the outside. Each connection handler reads a SET

  • 0

My Node.js application accepts connections from the outside. Each connection handler reads a SET on Redis, eventually modifies the set itself, then moves on. The problem is that in the meanwhile another async connection can try to read the same SET and try to update it or decide its next step based on what it reads.

I know that Redis does its best to be atomic, but this is not quite sufficient for my use case. Think about this: the set is read to understand if it’s FULL (there is a business rule for that). If it’s FULL, then something happens. The problem is that if there is one only slot left, two semi-concurrent connections could think each one is the last one. And I get an overflow.

I there a way to keep a connection “waiting” for the very short time the other eventually needs to update the set state?

I think this is a corner case, very very unluckely… but you know 🙂

Using another key as the “lock” is an option, or does it stink?

  • 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-05-24T11:05:37+00:00Added an answer on May 24, 2026 at 11:05 am

    You may be looking for WATCH with MULTI/EXEC. Here’s the pattern that both threads follow:

    WATCH sentinel_key
    GET value_of_interest
    if (value_of_interest = FULL)
        MULTI
        SET sentinel_key = foo
        EXEC
        if (EXEC returned 1, i.e. succeeded)
            do_something();
        else
            do_nothing();
    else
        UNWATCH
    

    The way this works is that all of the commands between MULTI and EXEC are queued up but not actually executed until EXEC is called. When EXEC is called, before actually executing the queued instructions it checks to see if sentinel_key has changed at all since the WATCH was set; if it has, it returns (nil) and the queued commands are discarded. Otherwise the commands are executed atomically as a block, and it returns the number of commands executed (1 in this case), letting you know you won the race and do_something() can be called.

    It’s conceptually similar to the fork()/exec() Unix system calls – the return value from fork() tells you which process you are (parent or child). In this case it tells you whether you won the race or not.

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

Sidebar

Related Questions

In a WinForms application, the level of a treeview is given by node.level What
I'm building a web service and have a node that accepts a POST to
I'm trying to set up jsTree to dynamically accept JSON data from django. This
Say you have a 4-node J2EE application server cluster, all running instances of a
I am using HTMLAgilityPack in my application, and i want to get the item(node)
Can an ArrayList of Node contain a non-Node type? Is there a very dirty
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
Duplicate Of : Find node clicked under context menu I've got a context menu
I've got a node struct struct Node{CString text, int id;}; in a sorted vector.
How can I find out which node in a tree list the context menu

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.