Last active
December 15, 2015 21:39
-
-
Save chapel/5327502 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var RedisClient = require('redis').RedisClient; | |
var util = require('util') | |
var CustomClient = function () { | |
RedisClient.call(this) | |
} | |
util.inherit(CustomClient, RedisClient); | |
// Extend CustomClient here | |
CustomClient.prototype.publishJSON = function(chan, obj) { | |
// do stuff | |
} | |
// Taken from node_redis exports.createClient | |
var createClient = function (port_arg, host_arg, options) { | |
var port = port_arg || default_port, | |
host = host_arg || default_host, | |
redis_client, net_client; | |
net_client = net.createConnection(port, host); | |
redis_client = new CustomClient(net_client, options); | |
redis_client.port = port; | |
redis_client.host = host; | |
return redis_client; | |
}; | |
// normal client usage | |
var listener = createClient(); | |
var publisher = createClient(); | |
listener.on('message', function(chan, msg) { | |
console.log(chan, msg); | |
}); | |
listener.subscribe('chan'); | |
//// lower down the line, assuming .subscribe already succeeded | |
publisher.publish('chan', 'message'); | |
/// what I want to do is to be able to | |
publisher.publish('chan', { level: "WARN", code: 500, msg: "Wrong index number" }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment