我是否需要等待 Redis 中(在 Node.js 中)调用 WATCH 的回调?
我正在使用node-redis
。在这样的代码中:
var store = require('redis').createClient();
store.watch('some:key');
store.get('some:key', function (err, results) {
var multi = store.multi();
// COMPUTE SOMETHING WITH results
multi.set('something:or:other', 25);
multi.exec(checkAllIsWell);
});
第 1-2 行应该读取
store.watch('some:key', function (err, alwaysok) {
store.get('some:key', function (err, result) {
还是 watch
总是立即生效?
编辑:稍微重新思考一下问题,同一 Redis 客户端上的顺序调用是否能保证顺序?或者 WATCH 是否可以在 GET 之后发生?
I'm using node-redis
. In code like this:
var store = require('redis').createClient();
store.watch('some:key');
store.get('some:key', function (err, results) {
var multi = store.multi();
// COMPUTE SOMETHING WITH results
multi.set('something:or:other', 25);
multi.exec(checkAllIsWell);
});
Should lines 1-2 read
store.watch('some:key', function (err, alwaysok) {
store.get('some:key', function (err, result) {
or will watch
always have immediate effect?
EDIT: To reframe the question a little, is sequence guaranteed on seqential calls on the same Redis client? Or could the WATCH happen after the GET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重新构建我的问题后,我意识到它肯定是保留序列的,而且我实际上是在重复这个问题: Redis更新是同步的吗?
所以答案肯定是我不需要等待WATCH回调,我原来的代码就可以了。
对不起各位,打扰了网络!
Having reframed my question, I realize that it must surely be sequence-preserving, and I'm actually duplicating this question: Are Redis updates synchronous?
So the answer is surely that I don't need to wait for WATCH to call back and my original code is OK.
Sorry to noise up the web, folks!
手表总是返回正常。 http://redis.io/commands/watch
仅当以后使用 MULTI/EXEC 时才有用,检查 EXEC 返回值。
有关 Redis 事务的更多信息,请访问 http://redis.io/topics/transactions
Watch always returns OK. http://redis.io/commands/watch
It is useful only if later you use MULTI/EXEC, to check the EXEC return value.
For more information about Redis transactions, visit http://redis.io/topics/transactions