Skip to content

Instantly share code, notes, and snippets.

@raydog
Last active March 24, 2016 23:22
Show Gist options
  • Save raydog/a7b90f6d9f6918244dc6 to your computer and use it in GitHub Desktop.
Save raydog/a7b90f6d9f6918244dc6 to your computer and use it in GitHub Desktop.
A RedisClient that always errors.
var redis = require('redis')
, util = require('util')
, events = require('events');
// This aims to implement enough of the stream interface to survive in the RedisClient:
function EmptyStream() {
events.EventEmitter.call(this);
}
util.inherits(EmptyStream, events.EventEmitter);
EmptyStream.prototype.destroySoon = function destroySoon() {};
/**
* A "Zombie" RedisClient. This client will behave like any other, but will not attempt
* any connections, and will respond to all queries immediately with an error.
*/
function ZombieRedisClient() {
redis.RedisClient.call(this, new EmptyStream(), { no_ready_check: 1, max_attempts: 1 });
}
util.inherits(ZombieRedisClient, redis.RedisClient);
ZombieRedisClient.prototype.send_command = function (cmd, args, cb) {
if (!cb) { cb = args.pop(); }
if (typeof cb !== "function") { return; }
process.nextTick(cb.bind(null, new Error("Redis server is down")));
};
// Useage:
// var client = new ZombieRedisClient();
module.exports = ZombieRedisClient;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment