本文介绍了是否有用于 node.js 的阻塞 redis 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Redis 非常快.在我的机器上的大多数情况下,它与 node.js 中的原生 Javascript 语句或函数调用一样快.在 node.js 中编写常规 Javascript 代码很容易/无痛,因为不需要回调.我不明白为什么使用 node.js 在 Redis 中获取/设置键/值数据不应该那么容易.

Redis is very fast. For most part on my machine it is as fast as say native Javascript statements or function calls in node.js. It is easy/painless to write regular Javascript code in node.js because no callbacks are needed. I don't see why it should not be that easy to get/set key/value data in Redis using node.js.

假设 node.js 和 Redis 在同一台机器上,是否有任何 npm 库允许使用阻塞调用与 node.js 上的 Redis 交互?我知道这必须是一个与 V8 接口的 C/C++ 库.

Assuming node.js and Redis are on the same machine, are there any npm libraries out there that allow interacting with Redis on node.js using blocking calls? I know this has to be a C/C++ library interfacing with V8.

推荐答案

我想您想确保所有的 redis 插入操作都已执行.为此,您可以使用 MULTI 命令插入键或执行其他操作.https://github.com/mranney/node_redis 模块将在多对象中推送的命令排队,并且相应地执行它们.

I suppose you want to ensure all your redis insert operations have been performed. To achieve that, you can use the MULTI commands to insert keys or perform other operations.The https://github.com/mranney/node_redis module queues up the commands pushed in multi object, and executes them accordingly.

这样你只需要一个回调,在 exec 调用结束时.

That way you only require one callback, at the end of exec call.

这篇关于是否有用于 node.js 的阻塞 redis 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:19