forked from redis/node-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename.spec.js
147 lines (123 loc) · 5.17 KB
/
rename.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
'use strict';
var assert = require('assert');
var config = require('./lib/config');
var helper = require('./helper');
var redis = config.redis;
if (process.platform === 'win32') {
// TODO: Fix redis process spawn on windows
return;
}
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;
beforeEach(function (done) {
if (helper.redisProcess().spawnFailed()) return done();
client = redis.createClient({
rename_commands: {
set: '807081f5afa96845a02816a28b7258c3',
GETRANGE: '9e3102b15cf231c4e9e940f284744fe0'
},
parser: parser
});
client.on('ready', function () {
client.flushdb(done);
});
});
afterEach(function () {
if (helper.redisProcess().spawnFailed()) return;
client.end(true);
});
it('allows to use renamed functions', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
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 batch', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
client.batch([['set', 'key', 'value']]).exec(function (err, res) {
assert.strictEqual(res[0], 'OK');
});
var batch = client.batch();
batch.getrange('key', 1, -1);
batch.exec(function (err, res) {
assert(!err);
assert.strictEqual(res.length, 1);
assert.strictEqual(res[0], 'alue');
done();
});
});
it('should also work with multi', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
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();
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();
});
});
it('should also work prefixed commands', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();
client.end(true);
client = redis.createClient({
rename_commands: {
set: '807081f5afa96845a02816a28b7258c3'
},
parser: parser,
prefix: 'baz'
});
client.set('foo', 'bar');
client.keys('*', function (err, reply) {
assert.strictEqual(reply[0], 'bazfoo');
assert.strictEqual(err, null);
done();
});
});
});
});
after(function (done) {
if (helper.redisProcess().spawnFailed()) return done();
helper.stopRedis(function () {
helper.startRedis('./conf/redis.conf', done);
});
});
});