Redis + Node.js - 如何检索值 [英] Redis + Node.js - how do I retrieve the values

查看:44
本文介绍了Redis + Node.js - 如何检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 Node.js 的 Redis 数据库.使用client.hmset("jobs", "jobId_12345", JSON.stringify(jsonJob))我存储 JSON 字符串化作业.

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

现在我想遍历所有作业并检索作业 ID 和字符串化作业.

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

我试过了client.hkeys("jobs", function (err, replies) {}但这只会检索密钥.

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

我试过了client.hgetall("jobs", function (err, obj) {}但我不知道如何从 obj 中检索键和值.

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.

推荐答案

这就是它的工作原理.下面代码中的 id 是记录 id.

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 + Node.js - 如何检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆