原子sdiffstore +为结果创建键

时间:2016-03-17 11:00:43

标签: javascript node.js concurrency redis atomic

如何使此操作成为原子?

redisClient.flushallAsync()
  .then(() => redisClient.saddAsync('myset', ['a']))
  .then(() => redisClient.saddAsync('myset_new', ['a', 'b', 'c']))
  .then(() => redisClient.sdiffstoreAsync('myset_added', 'myset_new', 'myset'))
  .then(() => redisClient.smembersAsync('myset_added'))
  .then(result => Promise.all(_.map(result, newKey => redisClient.setAsync(newKey, ''))))
  .then(result => redisClient.keysAsync('*'))
  .then(result => console.log(result))
  .catch(error => console.log(error));

输出:

[ 'myset_new', 'myset_added', 'myset', 'c', 'b' ]

0 个答案:

没有答案