Skip to content

Instantly share code, notes, and snippets.

@a-x-
Last active August 29, 2015 14:17
Show Gist options
  • Save a-x-/7eda16871a20cd527210 to your computer and use it in GitHub Desktop.
Save a-x-/7eda16871a20cd527210 to your computer and use it in GitHub Desktop.
Async code like a sync in the record
// 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