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

  • Home
  • SEARCH
  • 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 6726223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:54:06+00:00 2026-05-26T09:54:06+00:00

I have a node.js script which starts at boot. It uses node-redis to create

  • 0

I have a node.js script which starts at boot. It uses node-redis to create a client for Redis, but at boot Redis is not ready while node is already starting. So, it gives an exception and stops executing.

The first part looks like this:

var redis  = require("redis"),
    jobs   = require("jobs"),
    client = redis.createClient(),
    runner = new jobs(client, "job-queue",{});

// Continue using runner

The exception is thrown in line 3 (redis.createClient()).

My solution was to make an endless loop, create the client in a try/catch and when successful, stop the loop:

var redis  = require("redis"),
    jobs   = require("jobs"),
    queue  = 'job-queue',
    client = null,
    runner = null,
    createClient = function (redis, jobs, queue) {
        try {
            client = redis.createClient();
            return new jobs(client, queue, {});
        } catch (err) {
            return null;
        }
    };

while(true) {
    setTimeout(function() {
        runner = createClient(redis, jobs, queue);
    }, 1000);

    if (null !== runner) break;
}

// Continue using runner

After a couple of seconds, this is the output:

FATAL ERROR: JS Allocation failed - process out of memory

How can I solve this? I am searching for a solution which could be in php:

while (true) {
    $client = createClient($redis, $jobs, $queue);
    if ($client instanceof MyClient) break;
    else sleep(1);
}
  • 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-26T09:54:07+00:00Added an answer on May 26, 2026 at 9:54 am

    setTimeout is asynchronous. JavaScript (and Node.js) have very few functions that wait for something to happen before continuing (like sleep). Instead, execution continues to the next line right away, but you pass setTimeout a callback function which is run when it fires.

    I would do something like this (warning, untested):

    var redis  = require("redis"),
        jobs   = require("jobs"),
        queue  = 'job-queue';
    
    function initializeRedis(callback) {
        (function createClient(){
            var runner;
            try {
                client = redis.createClient();
                runner = new jobs(client, queue, {});
            } catch (e) {}
            if (runner){
                callback(runner);
            } else {
                setTimeout(createClient, 1000);
            }
        })();
    };
    
    initializeRedis(function(runner){
        // Continue using runner
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little script here which uses DOMDocument to get my data from
I have a JS script which created a new Node and inserts it to
I have a script which successfully creates new nodes. But I'm having trouble setting
So, I have my Node.js script. And I have some HTML page which contains
In the sitemap file, I have sitemap Node URL which have more than 1
I have a base class Node which contains a list of child nodes. Node
I have a script which contains two classes. (I'm obviously deleting a lot of
I want to create a greasymonkey script, which will add a shortcut key for
I created a little proxy node script, which looksup the request.url and either passes
I have developed an application which can create Xml files from Xml schema with

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.