|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var assert = require("assert"); |
| 4 | +var config = require("./lib/config"); |
| 5 | +var helper = require('./helper'); |
| 6 | +var redis = config.redis; |
| 7 | + |
| 8 | +describe("rename commands", function () { |
| 9 | + before(function (done) { |
| 10 | + helper.stopRedis(function () { |
| 11 | + helper.startRedis('./conf/rename.conf', done); |
| 12 | + }); |
| 13 | + }); |
| 14 | + |
| 15 | + helper.allTests(function(parser, ip, args) { |
| 16 | + |
| 17 | + describe("using " + parser + " and " + ip, function () { |
| 18 | + var client = null; |
| 19 | + |
| 20 | + afterEach(function () { |
| 21 | + client.end(); |
| 22 | + }); |
| 23 | + |
| 24 | + it("allows to use renamed functions", function (done) { |
| 25 | + if (helper.redisProcess().spawnFailed()) this.skip(); |
| 26 | + |
| 27 | + client = redis.createClient({ |
| 28 | + rename_commands: { |
| 29 | + set: '807081f5afa96845a02816a28b7258c3', |
| 30 | + GETRANGE: '9e3102b15cf231c4e9e940f284744fe0' |
| 31 | + } |
| 32 | + }); |
| 33 | + |
| 34 | + client.set('key', 'value', function(err, reply) { |
| 35 | + assert.strictEqual(reply, 'OK'); |
| 36 | + }); |
| 37 | + |
| 38 | + client.get('key', function(err, reply) { |
| 39 | + assert.strictEqual(err.message, "ERR unknown command 'get'"); |
| 40 | + assert.strictEqual(err.command, 'GET'); |
| 41 | + assert.strictEqual(reply, undefined); |
| 42 | + }); |
| 43 | + |
| 44 | + client.getrange('key', 1, -1, function(err, reply) { |
| 45 | + assert.strictEqual(reply, 'alue'); |
| 46 | + assert.strictEqual(err, null); |
| 47 | + done(); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should also work with multi", function (done) { |
| 52 | + if (helper.redisProcess().spawnFailed()) this.skip(); |
| 53 | + |
| 54 | + client = redis.createClient({ |
| 55 | + rename_commands: { |
| 56 | + SET: '807081f5afa96845a02816a28b7258c3', |
| 57 | + getrange: '9e3102b15cf231c4e9e940f284744fe0' |
| 58 | + } |
| 59 | + }); |
| 60 | + |
| 61 | + client.multi([['set', 'key', 'value']]).exec(function (err, res) { |
| 62 | + assert.strictEqual(res[0], 'OK'); |
| 63 | + }); |
| 64 | + |
| 65 | + var multi = client.multi(); |
| 66 | + multi.getrange('key', 1, -1); |
| 67 | + multi.exec(function (err, res) { |
| 68 | + assert(!err); |
| 69 | + assert.strictEqual(res.length, 1); |
| 70 | + assert.strictEqual(res[0], 'alue'); |
| 71 | + done(); |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + it("should also work with multi and abort transaction", function (done) { |
| 76 | + if (helper.redisProcess().spawnFailed()) this.skip(); |
| 77 | + |
| 78 | + client = redis.createClient({ |
| 79 | + rename_commands: { |
| 80 | + SET: '807081f5afa96845a02816a28b7258c3', |
| 81 | + getrange: '9e3102b15cf231c4e9e940f284744fe0' |
| 82 | + } |
| 83 | + }); |
| 84 | + |
| 85 | + var multi = client.multi(); |
| 86 | + multi.get('key'); |
| 87 | + multi.getrange('key', 1, -1, function(err, reply) { |
| 88 | + assert.strictEqual(reply, 'alue'); |
| 89 | + assert.strictEqual(err, null); |
| 90 | + }); |
| 91 | + multi.exec(function (err, res) { |
| 92 | + assert(err); |
| 93 | + assert.strictEqual(err.message, 'EXECABORT Transaction discarded because of previous errors.'); |
| 94 | + assert.strictEqual(err.errors[0].message, "ERR unknown command 'get'"); |
| 95 | + assert.strictEqual(err.errors[0].command, 'GET'); |
| 96 | + assert.strictEqual(err.code, 'EXECABORT'); |
| 97 | + assert.strictEqual(err.errors[0].code, 'ERR'); |
| 98 | + done(); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + after(function (done) { |
| 106 | + helper.stopRedis(function () { |
| 107 | + helper.startRedis('./conf/redis.conf', done); |
| 108 | + }); |
| 109 | + }); |
| 110 | +}); |
0 commit comments