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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:48:23+00:00 2026-05-31T02:48:23+00:00

I have a whole bunch of fields for each user in my redis database,

  • 0

I have a whole bunch of fields for each user in my redis database, and I want to be able to retrieve all their records and display them.
The way I do it, is store a set of all userids, When I want all their records, I recursively iterate the set grabbing their records using the userids in the set and adding them to a global array, then finally returning this global array. Anyway I don’t particularly like this method and would like to hear some suggestions of alternatives, I feel there must be better functionality in node.js or redis for this very problem. Maybe there is a way to do away with using the set entirely, but looking around I couldn’t see anything obvious.

This is an example of my psuedoish (pretty complete) node.js code, note the set size is not a problem as it will rarely be > 15.

Register Function:

var register = function(username, passwordhash, email){

    // Get new ID by incrementing idcounter
    redis.incr('db:users:idcounter', function(err, userid){

        // Setup user hash with user information, using new userid as key
        redis.hmset('db:user:'+userid, {
                'username':username,
                'passwordhash':passwordhash,
                'email':email
            },function(err, reply){

                 // Add userid to complete list of all users
                 redis.sadd('db:users:all', userid);

            }
        });
    });
}

Records retrieval function:
var getRecords = function(fcallback){

    // Grab a list of all the id's
    redis.smembers('db:users:all', function(err, allusersids){

        // Empty the returned (global) array
        completeArray = [];

        // Start the recursive function, on the allusersids Array.
        recursive_getNextUserHash(allusersids, fcallback);
    });  
}

Recursive function used to retrieve individual records:

// Global complete Array (so recursive function has access)
var completeArray = [];

// recursive method for filling up our completeArray
var recursive_getNextUserHash = function(userArray, callback){

    // If userArray==0 this means we have cycled entire list, 
    // call the callback, and pass it the completeArray which 
    // is now full of our usernames + emails

    if(userArray.length==0){
        callback.apply(this, [completeArray]);
        return;
    }

    // If still more items, start by popping the next user
    var userid = userArray.pop();

    // grab this users information
    redis.hvals('db:user:'+userid, function(err, fields){

        // Add users information to global array
        completeArray.push({username:fields[0],email:fields[2]});

        // Now move on to the next user
        recursive_getNextUserHash(userArray, callback);
    });

}

Use would be something like this:

register('bob', 'ASDADSFASDSA', 'bob@example.com');
register('bill', 'DDDASDADSAD', 'bill@example.com');
getRecords(function(records){
    for(var i=0;i<records.length;i++){
         console.log("u:"+records[i]['username']+',@:'+records[i]['email']);
    }
});

Summary: What is a good way to retrieve many fields of Hash’s using node.js and redis? After writing this question, I started to wonder if this is just the way you do it in redis, you make many roundtrips, regardless if this is the case, there must be a way to avoid the horrible recursion!

  • 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-31T02:48:24+00:00Added an answer on May 31, 2026 at 2:48 am

    Assuming you are using https://github.com/mranney/node_redis – have a look at Multi and Exec. You can send all of your commands in a single request and wait for all the responses at once. No need for recursion.

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

Sidebar

Related Questions

I have a database, consisting of a whole bunch of records (around 600,000) where
I have a table with a whole bunch of fields and records in it
I have whole bunch of <div class=productlistname><a href=#>The Text!</a></div> . What I want to
I have a whole bunch of buttons that all need to have both a
I have a whole bunch of projects which I want to reuse between the
I have a whole bunch of mavenised projects, and I want to check that
In C++, say you have a whole bunch of objects that you want to
I have a UITextFieldDelegate that does a whole bunch of validation on user input
I have a whole bunch of data from a series of rounds. Specifically, I
If I have a whole bunch of requires in my main app file: require

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.