Database Reference
In-Depth Information
}
arguments.callee.__instance = this;
events.EventEmitter.call(this);
this.options = options || {};
this.client =
redis.createClient(this.options.port || 6379
,host);
this.counterName = this.options.counters ||
"counters";
this.pubsub = redis.createClient(this.options.port
|| 6379,host);
var self = this;
this.pubsub.on('ready',function() {
self.pubsub.subscribe(self.counterName);
});
this.pubsub.on('message',function(channel,message) {
if(channel == self.counterName) {
self._sendUpdate(message);
}
});
}
util.inherits(Counter,events.EventEmitter);
module.exports = function(host,options) {
new Counter(host,options);
}
When a new counter event arrives on the pubsub connection that
corresponds to the hash being monitored by the server, the _sendUpdate
method is used to inform all subscribed clients:
Counter.prototype._sendUpdate = function(counter) {
var self = this;
this.get(counter,function(err,data) {
if(err) return;
self.emit("updated",counter,data);
});
};
Search WWH ::




Custom Search