如何使用Watch在Redis中执行哈希交易

时间:2018-08-02 14:39:23

标签: node.js redis node-redis

任何人都可以告诉我如何在观看哈希键foo的同时在redis中执行事务,并使用键test和value fooTest设置值。 multi执行正常,但未在redis中设置该值。

redisClient.watch("foo", function (err) {
                            if (err) {
                                console.log('There was an error while watching the key foo.');
                            }
                            // Is this the correct usage of multi with hset i could not find it anywhere in documentation?                             
                            // The documentation just says that it will watch the whole hash and trigger if any value of the hash is modified.
                            redisClient.multi().hset(data.conversationID, helper.lastActivity, data.sentTimeStamp).exec(function (err, result) {

                                if (err) {
                                    console.log('There was an error while executing the multi query');
                                }
                                if (result === null) {
                                    console.log('The transaction was not performed since the data was accessed by someone else during the transaction and changed.');
                                }
                            });
                        });

登录时会显示[OK]结果,但值会更新。

0 个答案:

没有答案