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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:40:44+00:00 2026-06-02T04:40:44+00:00

Node.js and redis look hot but I’m getting burned. I can’t gracefully overcome what

  • 0

Node.js and redis look hot but I’m getting burned. I can’t gracefully overcome what seems like a very simple task:

Given 3 numbers, check if the first two are greater than 10. If yes, print the third number.

I did accomplish this task with this rather comical script:

var http = require("http");
var redis = require("redis");
client = redis.createClient();

http.createServer(function(request, response) {
    client.SET("key1", "11");
    client.SET("key2", "9");
    client.SET("key3", "3");

    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello\n\n");
    client.GET("key1", function(err, reply) {
        response.write(reply + "\n\n");

        if(parseInt(reply) > 10) {
          client.GET("key2", function(err, reply) {
              response.write(reply + "\n\n");

              if(parseInt(reply) > 10) {
                client.GET("key3", function(err, reply) {
                    response.write(reply + "\n\n");

                    response.end();
                    client.end();
                  });
              } else {
                response.end();
                client.end();
              }

            });
        } else {
          response.end();
          client.end();
        }
      });
  }).listen(8000);

The few things I noticed are:

  • is it necessary to nest each time I want a new GET?
  • response.end() needs to called somewhere for the writes to appear. How do I avoid repeating them in the else blocks?

Then I tried this style of querying the DB:

http.createServer(function(request, response) {

client.SET("key1", "11");
client.SET("key2", "9");
client.SET("key3", "3");

var key1 = 0;
var key2 = 0;
var key3 = 0;

response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello\n\n");
client.GET("key1", function(err, reply) {
        response.write(reply + "\n\n");
        key1 = parseInt(reply);
    });

client.GET("key2", function(err, reply) {
        response.write(reply + "\n\n");
        key2 = parseInt(reply);
    });

client.GET("key3", function(err, reply) {
        response.write(reply + "\n\n");
        key3 = parseInt(reply);
    });

response.write(key1 + "\n\n");
response.write(key2 + "\n\n");
response.write(key3 + "\n\n");

response.end();
client.end();

After some reading and some thought, my explanation is that the code gets to the response.writes before the asynchronous GETs return, and then the response is closed so the inner writes never happen. At least I noticed from the first example that the SETs can be called easily, but I don’t know (and it doesn’t seem to matter) if they are actually set in that order.

So, perhaps I’m doing something that is not suitable for node and redis. And I must be missing something basic and obvious. What do I need to do to level up?

Or tell me I have to go back to PhpMyAdmin 🙁

  • 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-02T04:40:46+00:00Added an answer on June 2, 2026 at 4:40 am

    Have a look at async it can help you organize your code
    https://github.com/caolan/async
    Hope this helps

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

Sidebar

Related Questions

I really want to like node.js with redis, but I can't conquer asynchronicity. Again
I can start the redis server but it seems that I can not start
Hope someone can assist with a (simple) async question on node-redis. I'm trying to
Can node.js be setup to recognize a proxy (like Fiddler for example) and route
I am using redis and node (with node_redis ) and I would like to
node.js provides lower layer V8 options too. These options are very low layer like
node can be run with a debug parameter like this $ node --debug src/file.js
I know there are node.js libraries for Redis; what I'd like to do is
I built a simple chat server with Node.js & Redis Pub/Sub, acani-node on GitHub
Must be missing something here, but I'm using Node_redis as Node.js client for Redis.

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.