简体   繁体   中英

Redis + Node.js - how do I retrieve the values

I am using a Redis database with Node.js. Using client.hmset("jobs", "jobId_12345", JSON.stringify(jsonJob)) I store JSON stringified jobs.

Now I want to iterate over all jobs and retrieve both job id and stringified job.

I tried client.hkeys("jobs", function (err, replies) {} but that only retrieves the keys.

I tried client.hgetall("jobs", function (err, obj) {} but I don't know how to retrieve both key and value from obj.

Any help is greatly appreciated because I'm stuck.

This is how it works. id in the code below is the record id.

redisclient.hgetall(key, function (err, dbset) {

  // gather all records
  for (id in dbset) {
       ...
  }
}); 

Redis HGETALL is the right command (client.hgetall)

As you can also see in redis docs, HGETALL returns all fields and values of the hash stored for the requested key.

I am not 100% sure but client.hgetall should return a list with fields and values

[field1_name, field1_value, field2_name, field2_value ...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM