Skip to content

Instantly share code, notes, and snippets.

@tsabat
Created September 9, 2011 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsabat/1207552 to your computer and use it in GitHub Desktop.
Save tsabat/1207552 to your computer and use it in GitHub Desktop.
node server
var http = require("http");
var redis = require("redis");
var url = require('url');
client = redis.createClient();
var requests = [];
var strings = [];
http.createServer(
function(request, response) {
if (request.url === '/favicon.ico') {
response.writeHead(200, {'Content-Type': 'image/x-icon'});
response.end();
console.log('favicon requested');
} else {
requests.push([request, response]);
//console.log(requests.length)
}
}).listen(8000);
function foo() {
var d = new Date();
var key = "pink-eye-p-" + d.getMinutes();
//console.log('reading key into array from ' + key);
client.smembers(key, function(err, obj) {
if (obj) {
for (var i = 0; i < obj.length; i++) {
strings.push(JSON.parse(obj[i]));
}
}
});
};
var myloop = function() {
while (requests.length) {
//console.log('sending requests back.');
out = requests.pop();
out[1].writeHead(200, { "Content-Type": "application/json" });
//var lVars = url.parse(out[0].url, true);
//var wrap = lVars.query.callback;
//var s = wrap+'({"coordinates":'+JSON.stringify(strings)+'})';
out[1].end('{ length:' + requests.length + '}');
}
strings = [];
}
setInterval(myloop, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment