Permalink
Browse files

Added the redis connection.

  • Loading branch information...
1 parent 685028e commit f70730f3e92b20aa616d9612a842614665f704d8 @waratuman committed Aug 19, 2010
Showing with 14 additions and 0 deletions.
  1. +14 −0 server.js
View
@@ -7,6 +7,11 @@ var fs = require('fs'),
http = require('http'),
path = require('path'),
redis = require('redis-client');
+
+var db = redis.createClient(9281, 'goosefish.redistogo.com');
+var dbAuth = function() { db.auth('dc64f7b818f4e3ec2e3d3d033e3e5ff4'); }
+db.addListener('connected', dbAuth);
+db.addListener('reconnected', dbAuth);
var httpServer = http.createServer( function(request, response) {
var pathname = url.parse(request.url).pathname;
@@ -35,6 +40,15 @@ var httpServer = http.createServer( function(request, response) {
});
});
+db.subscribeTo("flight_stream", function(channel, message, pattern) {
+ try { var flight = JSON.parse(message); }
+ catch (SyntaxError) { return false; }
+
+ if ( flight.origin.iata == "BOS" || flight.destination.iata == "BOS") {
+ server.broadcast(flight);
+ }
+});
+
var server = ws.createServer({}, httpServer);
server.listen(8000);

0 comments on commit f70730f

Please sign in to comment.