diff --git a/lib/redis-mock.js b/lib/redis-mock.js index 4c02bd5..93fd370 100755 --- a/lib/redis-mock.js +++ b/lib/redis-mock.js @@ -395,8 +395,10 @@ RedisClient.prototype.send_command = RedisClient.prototype.SEND_COMMAND = functi } } -RedisClient.prototype.select = function (database) { - +RedisClient.prototype.select = function (database, callback) { + if (callback) { + process.nextTick(callback(null, "OK")); + } return "OK"; } @@ -417,8 +419,3 @@ RedisMock.prototype.createClient = function (port_arg, host_arg, options) { return new RedisClient(); } - - - - - diff --git a/test/redis-mock.test.js b/test/redis-mock.test.js index 1e62aa9..5bbfd94 100755 --- a/test/redis-mock.test.js +++ b/test/redis-mock.test.js @@ -31,6 +31,15 @@ describe("redis-mock", function () { }); + it("should call a callback when selecting a database", function (done) { + var r = redismock.createClient(); + + r.select(0, function(error) { + should.not.exist(error); + done(); + }); + }); + it("should emit ready and connected when creating client", function (done) { var r = redismock.createClient(); @@ -85,13 +94,13 @@ describe("redis-mock", function () { describe("redis-error-mock", function () { it("should emit a connection error", function (done) { - + // Skip this when testing against actual Redis if (process.env['VALID_TESTS']) { done(); return; } - + var redis = new redismock.RedisErrorMock(); var r = redis.createClient();