Parse Redis HGETALL object in Node.js

15,895

RedisClient use callback to return the result.

Exemple:

var redis = require('redis'),
    r = redis.createClient();

r.hgetall('userList', function(err, results) {
   if (err) {
       // do something like callback(err) or whatever
   } else {
      // do something with results
      console.log(results)
   }
});
Share:
15,895
Travis
Author by

Travis

Data Scientist & Web Developer. I have a passion for discovering and working with cutting-edge technology. I enjoy collaborating with others to solve problems.

Updated on June 16, 2022

Comments

  • Travis
    Travis almost 2 years

    I'm trying to parse an HGETALL object in Node.js.


    In Redis CLI:

    > HGETALL userList
    

    returns

    1) "19578616521094096601"
    2) "User 1"
    3) "1682930884780137383"
    4) "User 2"
    

    In Node:

    var redis = require('redis')
    ,   r = redis.createClient();
    
    console.log(r.HGETALL('userList'));
    

    returns

    true
    

    I would like to parse the userList object as JSON or an array but I can't seem to figure out how to pull data out of it.