var redisClient = require("redisclient"),
         dealer = require("../lib"),
            sys = require('sys')

var port = process.env['PORT'] || 3840

conn = dealer.create()
conn.server.listen(port)

sys.puts("listening on " + port)

conn.addListener('connect', function(client) {
  sys.puts('connected to ' + sys.inspect(client.channels) + ': '+ client.id)
})

conn.addListener('disconnect', function(client) {
  sys.puts('disconnected: ' + client.id)
})

conn.addListener('receive', function(client, data) {
  sys.puts('from ' + client.id + sys.inspect(client.channels) + ': ' + data)
  client.send("PONG! " + data)
})

var redis = redisClient.createClient();
    
redis.stream.addListener("connect", function () {
  redis.subscribeTo("*", function (channel, message) {
    sys.puts("to " + channel + ": " + message);
    conn.sendToChannel(channel, message)
  })
})
@@ -104,16 +104,50 @@
 e('sys')
+,%0A            url = require('url')
 %0A%0Avar po
@@ -149,16 +149,21 @@
 ar port 
+     
 = proces
@@ -183,16 +183,87 @@
  %7C%7C 3840
+%0Avar redisConf = process.env%5B'REDIS_URL'%5D %7C%7C %22redis://127.0.0.1:6379/0%22
 %0A%0Aconn =
@@ -731,52 +731,162 @@
 %7D)%0A%0A
-var redis = redisClient.createClient();%0A    
+redisConf   = url.parse(redisConf)%0Avar redisDb = redisConf.pathname.substr(1)%0Avar redis   = redisClient.createClient(redisConf.port, redisConf.hostname);%0A
 %0Ared
@@ -932,16 +932,56 @@
 on () %7B%0A
+  redis.select(redisDb, function(a) %7B%0A  
   redis.
@@ -1031,16 +1031,18 @@
 ) %7B%0A    
+ 
+ 
 sys.puts
@@ -1081,16 +1081,18 @@
 e);%0A    
+  
 conn.sen
@@ -1120,15 +1120,22 @@
 essage)%0A
+    %7D)%0A
   %7D)%0A%7D)

configure redis client from REDIS_URL