1

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.

2 Answers 2

2

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) {
       ...
  }
}); 
Sign up to request clarification or add additional context in comments.

Comments

0

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 ...]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.