Reputation: 123
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.
Upvotes: 1
Views: 3740
Reputation: 123
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) {
...
}
});
Upvotes: 2
Reputation: 12031
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 ...]
Upvotes: 0