forked from redis/node-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefix.spec.js
119 lines (109 loc) · 4.7 KB
/
prefix.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
'use strict';
var assert = require("assert");
var config = require("./lib/config");
var helper = require('./helper');
var redis = config.redis;
describe("prefix key names", function () {
helper.allTests(function(parser, ip, args) {
describe("using " + parser + " and " + ip, function () {
var client = null;
beforeEach(function(done) {
client = redis.createClient({
parser: parser,
prefix: 'test:prefix:'
});
client.on('ready', function () {
client.flushdb(function (err) {
done(err);
});
});
});
afterEach(function () {
client.end(true);
});
it("auto prefix set / get", function (done) {
client.set('key', 'value', function(err, reply) {
assert.strictEqual(reply, 'OK');
});
client.get('key', function(err, reply) {
assert.strictEqual(reply, 'value');
});
client.getrange('key', 1, -1, function(err, reply) {
assert.strictEqual(reply, 'alue');
assert.strictEqual(err, null);
});
client.exists('key', function (err, res) {
assert.strictEqual(res, 1);
});
client.exists('test:prefix:key', function (err, res) {
// The key will be prefixed itself
assert.strictEqual(res, 0);
});
client.mset('key2', 'value2', 'key3', 'value3');
client.keys('*', function (err, res) {
assert.strictEqual(res.length, 3);
assert(res.indexOf('test:prefix:key') !== -1);
assert(res.indexOf('test:prefix:key2') !== -1);
assert(res.indexOf('test:prefix:key3') !== -1);
done();
});
});
it("auto prefix set / get with .batch", function (done) {
var batch = client.batch();
batch.set('key', 'value', function(err, reply) {
assert.strictEqual(reply, 'OK');
});
batch.get('key', function(err, reply) {
assert.strictEqual(reply, 'value');
});
batch.getrange('key', 1, -1, function(err, reply) {
assert.strictEqual(reply, 'alue');
assert.strictEqual(err, null);
});
batch.exists('key', function (err, res) {
assert.strictEqual(res, 1);
});
batch.exists('test:prefix:key', function (err, res) {
// The key will be prefixed itself
assert.strictEqual(res, 0);
});
batch.mset('key2', 'value2', 'key3', 'value3');
batch.keys('*', function (err, res) {
assert.strictEqual(res.length, 3);
assert(res.indexOf('test:prefix:key') !== -1);
assert(res.indexOf('test:prefix:key2') !== -1);
assert(res.indexOf('test:prefix:key3') !== -1);
});
batch.exec(done);
});
it("auto prefix set / get with .multi", function (done) {
var multi = client.multi();
multi.set('key', 'value', function(err, reply) {
assert.strictEqual(reply, 'OK');
});
multi.get('key', function(err, reply) {
assert.strictEqual(reply, 'value');
});
multi.getrange('key', 1, -1, function(err, reply) {
assert.strictEqual(reply, 'alue');
assert.strictEqual(err, null);
});
multi.exists('key', function (err, res) {
assert.strictEqual(res, 1);
});
multi.exists('test:prefix:key', function (err, res) {
// The key will be prefixed itself
assert.strictEqual(res, 0);
});
multi.mset('key2', 'value2', 'key3', 'value3');
multi.keys('*', function (err, res) {
assert.strictEqual(res.length, 3);
assert(res.indexOf('test:prefix:key') !== -1);
assert(res.indexOf('test:prefix:key2') !== -1);
assert(res.indexOf('test:prefix:key3') !== -1);
});
multi.exec(done);
});
});
});
});