var db = require('redis').createClient(); exports.book = function(req, res) { stats(function(free) { if (free > 0) { var code = "XCP"+Math.floor(Math.random()*1000); db.sadd("open", code); } show(res, 'book', (free>0)?0:1, code); }); }; exports.checkin = function(req, res) { var code = req.body.code; db.srem("open", code, function(err, rp) { if (rp > 0) { db.sadd("checkedIn", code); } show(res, 'checkin', (rp>0)?0:1, code); }); }; exports.checkout = function(req, res) { var code = req.body.code; // closure db.srem("checkedIn", code, function(err, rp) { show(res, 'checkout', (rp>0)?0:1, code); }); };