Skip to content

Instantly share code, notes, and snippets.

@dannyamey
Created April 16, 2012 14:01
Show Gist options
  • Save dannyamey/2399018 to your computer and use it in GitHub Desktop.
Save dannyamey/2399018 to your computer and use it in GitHub Desktop.
exports.index = function(req, res, next) {
client.sort('movies', 'BY', 'movie:*:data->year', 'LIMIT', '0', '12', 'ALPHA', 'DESC', 'GET', '#', function(err, replies) {
var movies = [];
async.forEachSeries(replies, function(reply, done) {
client.hgetall('movie:'+reply+':data', function(err, movie) {
if (err) return done(err);
movies.push(movie);
done();
});
}, function(err) {
if (err) return next(err);
client.sort('genres', 'BY', 'genre:*:name', 'ALPHA', 'ASC', 'GET', '#', function(err, genre_ids) {
var genres = [];
async.forEachSeries(genre_ids, function(genre_id, done) {
client.get('genre:'+genre_id+':name', function(err, val) {
if (err) return done(err);
genres.push({ id: genre_id, name: val })
done();
});
}, function(err) {
res.render('index', {
movies: JSON.stringify(movies)
genres: genres
});
});
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment