Last active
August 29, 2015 14:17
-
-
Save a-x-/7eda16871a20cd527210 to your computer and use it in GitHub Desktop.
Async code like a sync in the record
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install -S q | |
var Q = require('q'); | |
Q.async(function*() { | |
yield db.hmset('blog::post', { | |
date: '20130605', | |
title: 'g3n3rat0rs r0ck', | |
tags: 'js,node' | |
}); | |
var post = yield db.hgetall('blog::post'); | |
var tags = post.tags.split(','); | |
var taggedPosts = yield Q.all(tags.map(function(tag) { | |
return db.hgetall('blog::tag::' + tag); | |
})); | |
// Do some stuff with post и taggedPosts | |
client.quit(); | |
})().done(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment