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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:24:59+00:00 2026-06-10T00:24:59+00:00

Im trying to create a file ‘users.js’ where id like to manage all the

  • 0

Im trying to create a file ‘users.js’ where id like to manage all the redis accesses to the users data. In this file i have the next function, where i get the users ive saved in a list, to then load all of them from their keys:

exports.getUsers = function(){
    var usrs;
    client.lrange('users', 0, -1, function(err, rep){
        client.mget(rep, function(e,r){
            usrs = r;
        });
    });
    return usrs;
};

I have another file ‘admin.js’ where i try to manage the routes for my administration panel. In this file I require the users.js file, and i call to the users.getUsers() function. I expect to get an array with the users objects, or at least the string with all of them. The problem is that it always returns ‘undefined’.

As i understand it, what is happening is that i try to return the usrs variable before the mget finish with the callback. But i dont know how to solve that.

The question is… how can i make the return statement wait for mget? Is there any other way to organize the code and keep the DB accesses separated by fields?

  • 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-10T00:25:01+00:00Added an answer on June 10, 2026 at 12:25 am

    You can’t make getUsers wait for the response before returning, so you need to have your function support a callback parameter that your function calls when the data is ready:

    exports.getUsers = function(callback){
        client.lrange('users', 0, -1, function(err, rep){
            client.mget(rep, function(e,usrs){
                callback(e,usrs);
            });
        });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create batch file which should have this commands: cd c:\Program files\NuSMV\2.5.2\bin\
Im trying to create new file on D: drive with c/c++ I found this
I have just started learning python version 3 and trying to create a file
I'm trying to create an xlsx file programmatically on iOS. Since the internal data
I am trying to create a debugfs file using the debugfs_create_file(...). I have written
I'm trying to create a file for my audio recorder, but this file keeps
I am trying to create a file containing a pkcs 7 block. In this
I'm trying to create a file download page. This page when requested should prompt
I am trying to create an XML file based on data fields from a
I'm trying to create an xml file.when I create the file I obtain this

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.