我有以下操作来创建与node_redis用户:如何使用可延迟来执行一系列Redis操作?
server.post('/create_user', function(req, res, next) { console.log(req.body); var body = req.body; client.hincrby('users', 'count', 1, function(err, id) { client.hmset('user:'+id, 'username', body.username, 'password', body.password, 'email', body.email, function(err, write) { client.hmget('user:'+id, 'username', 'email', function(err, read) { res.send({id: id, username: read[0], email: read[1]}); }); }); }); })
我想阅读有关可延迟和Promisses这里:http://blog.jcoglan.com/2011/03/11/promises-are-the-monad-of-asynchronous-programming/
如何验证码与Deferrables和Promisses改写,使清洁例外处理和更好的过程维护?
的行动基本上是:
- 增加计数器拿到ID
- 的用户设置Redis的哈希ID为
- 返回从创建的Redis
谢谢!正是我正在寻找的! – poseid