Skip to content

Instantly share code, notes, and snippets.

@chapel
Last active December 15, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapel/5327502 to your computer and use it in GitHub Desktop.
Save chapel/5327502 to your computer and use it in GitHub Desktop.
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