使用 nodejs 和 redis-node 的异步编程范式

问题描述:

如何将下面的同步伪代码翻译成异步js代码

How to translate the following sync pseudo code into async js code

result = []
for pid in r.smembers('active_prog'):
    for prog_obj in r.hgetall("prog:" + pid):
        for item_obj in r.hgetall("item:" + prog_obj['iid']):
            prog_obj['items'].append(item_obj)
        result.append(prog_obj)
return result

这在同步编程中似乎很自然:

That's seems natural in sync programming:

  1. 获取一些 ID,
  2. 通过 id 获取项目
  3. 获取每个项目的相关信息并将这些信息附加到它们
  4. 将所有项目合并到一个数组中并返回

我尝试过使用 MULTI,但是当递归深入时它似乎不起作用.

I've tried using MULTI but it seem doesn't work when the recursion goes deeper.

有没有关于在异步范式中学习编程的建议?(最好使用 js 代码而不是 .net 的东西)

Is there any recommendation for learning programming in async paradigm?(preferably in js code rather than .net stuff)

有没有关于异步学习编程的推荐范式?

Is there any recommendation for learning programming in async paradigm?

试着看看这些:

为了防止代码中的深度嵌套回调,您可以利用几个流量控制节点.js 模块,例如:

In order to prevent deeply nested callbacks in your code you can take advantage of several flow control node.js modules such as: