forked from redis/node-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ruben Bridgewater
committed
Oct 10, 2015
1 parent
6d8daef
commit 972d1cd
Showing
5 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
port 6379 | ||
bind ::1 127.0.0.1 | ||
unixsocket /tmp/redis.sock | ||
unixsocketperm 755 | ||
rename-command SET 807081f5afa96845a02816a28b7258c3 | ||
rename-command GET f397808a43ceca3963e22b4e13deb672 | ||
rename-command GETRANGE 9e3102b15cf231c4e9e940f284744fe0 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
'use strict'; | ||
|
||
var assert = require("assert"); | ||
var config = require("./lib/config"); | ||
var helper = require('./helper'); | ||
var redis = config.redis; | ||
|
||
describe("rename commands", function () { | ||
before(function (done) { | ||
helper.stopRedis(function () { | ||
helper.startRedis('./conf/rename.conf', done); | ||
}); | ||
}); | ||
|
||
helper.allTests(function(parser, ip, args) { | ||
|
||
describe("using " + parser + " and " + ip, function () { | ||
var client = null; | ||
|
||
afterEach(function () { | ||
client.end(); | ||
}); | ||
|
||
it("allows to use renamed functions", function (done) { | ||
if (helper.redisProcess().spawnFailed()) this.skip(); | ||
|
||
client = redis.createClient({ | ||
rename_commands: { | ||
set: '807081f5afa96845a02816a28b7258c3', | ||
GETRANGE: '9e3102b15cf231c4e9e940f284744fe0' | ||
} | ||
}); | ||
|
||
client.set('key', 'value', function(err, reply) { | ||
assert.strictEqual(reply, 'OK'); | ||
}); | ||
|
||
client.get('key', function(err, reply) { | ||
assert.strictEqual(err.message, "ERR unknown command 'get'"); | ||
assert.strictEqual(err.command, 'GET'); | ||
assert.strictEqual(reply, undefined); | ||
}); | ||
|
||
client.getrange('key', 1, -1, function(err, reply) { | ||
assert.strictEqual(reply, 'alue'); | ||
assert.strictEqual(err, null); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should also work with multi", function (done) { | ||
if (helper.redisProcess().spawnFailed()) this.skip(); | ||
|
||
client = redis.createClient({ | ||
rename_commands: { | ||
SET: '807081f5afa96845a02816a28b7258c3', | ||
getrange: '9e3102b15cf231c4e9e940f284744fe0' | ||
} | ||
}); | ||
|
||
client.multi([['set', 'key', 'value']]).exec(function (err, res) { | ||
assert.strictEqual(res[0], 'OK'); | ||
}); | ||
|
||
var multi = client.multi(); | ||
multi.getrange('key', 1, -1); | ||
multi.exec(function (err, res) { | ||
assert(!err); | ||
assert.strictEqual(res.length, 1); | ||
assert.strictEqual(res[0], 'alue'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should also work with multi and abort transaction", function (done) { | ||
if (helper.redisProcess().spawnFailed()) this.skip(); | ||
|
||
client = redis.createClient({ | ||
rename_commands: { | ||
SET: '807081f5afa96845a02816a28b7258c3', | ||
getrange: '9e3102b15cf231c4e9e940f284744fe0' | ||
} | ||
}); | ||
|
||
var multi = client.multi(); | ||
multi.get('key'); | ||
multi.getrange('key', 1, -1, function(err, reply) { | ||
assert.strictEqual(reply, 'alue'); | ||
assert.strictEqual(err, null); | ||
}); | ||
multi.exec(function (err, res) { | ||
assert(err); | ||
assert.strictEqual(err.message, 'EXECABORT Transaction discarded because of previous errors.'); | ||
assert.strictEqual(err.errors[0].message, "ERR unknown command 'get'"); | ||
assert.strictEqual(err.errors[0].command, 'GET'); | ||
assert.strictEqual(err.code, 'EXECABORT'); | ||
assert.strictEqual(err.errors[0].code, 'ERR'); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
after(function (done) { | ||
helper.stopRedis(function () { | ||
helper.startRedis('./conf/redis.conf', done); | ||
}); | ||
}); | ||
}); |