Permalink
Browse files

first draft

  • Loading branch information...
1 parent 33740a7 commit 0812da98c53819e4c4d6ebb2ef1141a493a371d4 @mnutt committed Dec 3, 2010
Showing with 43 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +28 −0 app.js
  3. +14 −0 package.json
View
@@ -0,0 +1 @@
+/node_modules
View
28 app.js
@@ -0,0 +1,28 @@
+require.paths.unshift(__dirname + "/node_modules");
+
+var redis = require("redis"),
+ http = require("http"),
+ io = require("socket.io"),
+ client = redis.createClient();
+
+// Set up websockets
+var server = http.createServer(function(req, res) {
+ res.writeHeader(200, {'Content-Type': 'text/html'});
+ res.writeBody('<h1>Hello world</h1>');
+ res.finish();
+});
+server.listen(8080, "0.0.0.0")
+var socket = io.listen(server);
+socket.on("connection", function(client) {
+ console.log("New client!");
+});
+
+// Watch redis
+console.log("Watching channel: " + process.argv[2]);
+
+client.on("message", function(channel, message) {
+ console.log(message.toString());
+ socket.broadcast(message.toString());
+});
+
+client.subscribe(process.argv[2]);
View
@@ -0,0 +1,14 @@
+{
+ "name" : "redis-pubsub-to-websockets",
+ "description" : "Watch a redis pubsub channel and broadcast it to websocket clients",
+ "version" : "0.0.1",
+ "dependencies" : {
+ "redis" : "0.3.9",
+ "socket.io" : "0.6.1"
+ },
+ "repository" : {
+ "type" : "git",
+ "url" : "http://github.com/mnutt/redis-pubsub-to-websockets"
+ },
+ "engines" : { "node" : ">=0.2.4" }
+}

0 comments on commit 0812da9

Please sign in to comment.