Created
June 15, 2010 07:30
-
-
Save Valid/438803 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
require.paths.unshift('lib'); | |
require('express'); | |
require('express/plugins'); | |
redisclient = require('redis-node-client/lib/redis-client'); | |
Parallel = require('parallel').Parallel; | |
redis = redisclient.createClient(); | |
sys = require('sys'); | |
configure(function () { | |
use(Logger); | |
set('root', __dirname); | |
}); | |
get('/', function () { | |
starttime = new Date().getTime(); | |
self = this; | |
redis.hgetall('site:1:details', function (err, siteDetails) { | |
//redisclient.convertMultiBulkBuffersToUTF8Strings(siteDetails); | |
redis.zcard('site:1:auctions', function (err, auctions) { | |
redis.zcard('site:1:bids', function (err, bids) { | |
redis.zrange('site:1:open', 0, -1, function (err, liveAuctions) { | |
liveAuctionDetailList = {}; | |
//redisclient.convertMultiBulkBuffersToUTF8Strings(liveAuctions); | |
redis.zrange('site:1:auctions', 0, -1, function (err, pastAuctions) { | |
pastAuctionDetailList = {}; | |
//redisclient.convertMultiBulkBuffersToUTF8Strings(pastAuctions); | |
function getLiveAuctionDetails(iterator, callback) { | |
redis.hgetall('auction:' + liveAuctions[iterator] + ':details', function (err, auctionDetails) { | |
//redisclient.convertMultiBulkBuffersToUTF8Strings(auctionDetails); | |
//sys.p(auctionDetails); | |
liveAuctionDetailList[iterator] = auctionDetails; | |
callback(); | |
}); | |
} | |
function getPastAuctionDetails(iterator, callback) { | |
redis.hgetall('auction:' + pastAuctions[iterator] + ':details', function (err, auctionDetails) { | |
//redisclient.convertMultiBulkBuffersToUTF8Strings(auctionDetails); | |
//sys.p(auctionDetails); | |
pastAuctionDetailList[iterator] = auctionDetails; | |
callback(); | |
}); | |
} | |
var liveDetailsTask = new Parallel(); | |
var pastDetailsTask = new Parallel(); | |
for (var i = 0; i < liveAuctions.length; i++) { | |
liveDetailsTask.add(i, [getLiveAuctionDetails, i]); | |
} // for | |
for (var i = 0; i < pastAuctions.length; i++) { | |
pastDetailsTask.add(i, [getPastAuctionDetails, i]); | |
} // for | |
liveDetailsTask.run(function (task) { | |
pastDetailsTask.run(function (task2) { | |
//sys.puts('Parallel liveDetailsTask ran task ' + task); | |
if (task === null && task2 === null) { | |
//sys.p(liveAuctionDetailList); | |
self.render('front.html.ejs', { | |
locals: { | |
siteDetails: siteDetails, | |
auctions: auctions, | |
bids: bids, | |
liveAuctions: liveAuctions, | |
liveAuctionDetails: liveAuctionDetailList, | |
pastAuctions: pastAuctions, | |
pastAuctionDetails: pastAuctionDetailList, | |
timer: new Date().getTime() - starttime | |
} | |
}); | |
} | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment