2

I am very new to redis & node and at the moment I am trying to loop through some test hash keys that i have created and print out to screen the results. Here is the result I expect to see:

{ "aaData": [['Tim Osbourne'],['Joe Bloggs'],['John Doe'],['Perry Coke'],['Will Holmes'],['Steven Smith']}

but instead I get this result:

{ "aaData": [[],[],[],[],[],[],]}'Tim Osbourne','Joe Bloggs','John Doe','Perry Coke','Will Holmes','Steven Smith',

Here is my code:

    app = require('../app');
    var redis = require("redis"),
    client = redis.createClient();
    routes = require('./');
    var key_types = '';

    client.keys("*", function (err, all_keys) {
        key_types += '{ "aaData": [';

        all_keys.forEach(function (key, pos) { // use second arg of forEach to get pos      
            key_types += "[";

            client.hmget([key, 'Owner of space'], function(err, field_val){
                key_types = key_types + "'" + field_val + "',";
            });

            key_types += "],";
        });

        key_types += "]}";               
    });

    app.get('/table_data', function(req, res){
        res.render('table_data', { keys: key_types});
    });

1 Answer 1

0
  • You should not do a keys *
  • It does not work because hmget is asynchronous, you should use the async module (async.map) for that.

What is the goal of [key, 'Owner of space'] since 'Owner of space' will always yield the same result?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.