Created
January 13, 2011 23:03
-
-
Save ecto/778801 to your computer and use it in GitHub Desktop.
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
app.get('/top', function(req, res){ | |
db.keys('booking:*:name', function(err,keys){ | |
if (err) { throw err; } | |
if (typeof(keys.forEach) == 'undefined') { res.redirect('/battle'); } | |
var bookings = []; | |
var originalCount = 0; | |
var returnCount = 0; | |
try { keys.forEach(function(key){ | |
key = String(key); | |
var split = key.split(':'); | |
if (!isNaN(split[1])) { | |
originalCount++; | |
db.mget('booking:' + split[1] + ':booking', 'booking:' + split[1] + ':name', 'booking:' + split[1] + ':mugshot', 'booking:' + split[1] + ':rating', function(err, booking){ | |
bookings.push(booking); | |
returnCount++; | |
if (originalCount == returnCount) { | |
res.send(bookings); | |
console.log(String(bookings.length)); | |
} | |
}); | |
} | |
}); } catch (err) { | |
console.log(err); | |
res.redirect('/top'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment