forked from dwyl/redis-connection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_redis.test.js
69 lines (61 loc) · 2.57 KB
/
local_redis.test.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
// require('env2')('config.env');
// var REDISCLOUD_URL = process.env.REDISCLOUD_URL;
// delete process.env.REDISCLOUD_URL; // delete to ensure we use LOCAL Redis!
var test = require('tape');
var decache = require('decache'); // http://goo.gl/JIjK9Y
var dir = __dirname.split('/')[__dirname.split('/').length-1];
var file = dir + __filename.replace(__dirname, '') + " -> ";
test(file +" Connect to LOCAL Redis instance as Subscriber", function(t) {
var redisSub = require('../index.js')('subscriber');
t.equal(redisSub.address, '127.0.0.1:6379',
"✓ Redis Client connected to: " + redisSub.address)
redisSub.set('redis', 'SUBSCRIBER', function(err, reply){
redisSub.get('redis', function (err, reply) {
t.equal(reply.toString(), 'SUBSCRIBER', '✓ LOCAL Redis is ' +reply.toString());
t.end();
});
});
});
test(file +" Connect to LOCAL Redis instance and GET/SET", function(t) {
var redisClient = require('../index.js')();
t.equal(redisClient.address, '127.0.0.1:6379',
"✓ Redis Client connected to: " + redisClient.address)
redisClient.set('redis', 'LOCAL', function(err, reply){
redisClient.get('redis', function (err, reply) {
t.equal(reply.toString(), 'LOCAL', '✓ LOCAL Redis is ' +reply.toString());
t.end();
});
});
});
test('Require an existing Redis connection', function(t){
var r2 = require('../index.js')();
r2.get('redis', function(err, reply){
t.equal(reply.toString(), 'LOCAL', '✓ LOCAL Redis is ' +reply.toString());
t.end();
});
});
test('Require an existing Redis SUBSCRIBER connectiong', function(t){
var rs2 = require('../index.js')('subscriber');
rs2.get('redis', function(err, reply){
t.equal(reply.toString(), 'LOCAL', '✓ LOCAL Redis is ' +reply.toString());
t.end();
});
});
test('Close Conection & Reset for Heroku Compatibility tests', function(t){
require('../index.js').killall(); // close all connections
decache('../index.js');
t.equal(redisClient.connected, false, "✓ Connection to LOCAL Closed");
t.end();
});
test(file +" Connect to LOCAL Redis instance with ReJSON enabled and use ReJSON functions", function(t) {
process.env.ENABLE_REJSON = true;
var redisClient = require('../index.js')();
t.equal(redisClient.address, '127.0.0.1:6379',
"✓ Redis Client connected to: " + redisClient.address);
redisClient.json_set('test', '.', 'LOCAL', function (err, reply) {
redisClient.json_get('test', function (err, reply) {
t.equal(reply.toString(), 'LOCAL', '✓ LOCAL Redis is ' +reply.toString());
t.end();
});
});
});