Skip to content

Commit a344777

Browse files
committed
Update dependencies, update ioredis to v5, allow testing redis to be configurable, and move ioredis to peer dependency
1 parent 40bc726 commit a344777

File tree

4 files changed

+2645
-2168
lines changed

4 files changed

+2645
-2168
lines changed

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
"dependencies": {
1919
"@babel/runtime": "^7.8.3",
2020
"co-wrap-all": "^1.0.0",
21-
"debug": "^4.1.1",
22-
"ioredis": "^4.14.1"
21+
"debug": "^4.1.1"
2322
},
2423
"devDependencies": {
2524
"@babel/cli": "^7.8.3",
@@ -46,10 +45,14 @@
4645
"remark-preset-github": "^0.0.16",
4746
"rimraf": "^3.0.0",
4847
"should": "^13.2.3",
49-
"xo": "^0.25.3"
48+
"xo": "^0.25.3",
49+
"ioredis": "^5.2.4"
50+
},
51+
"peerDependencies": {
52+
"ioredis": "5.x"
5053
},
5154
"engines": {
52-
"node": ">= 4"
55+
"node": ">= 14"
5356
},
5457
"files": [
5558
"lib"

test/async.test.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
const should = require('should');
22

3+
// allow the default url to be overriden for local testing
4+
const redisUrl = process.env.REDIS_URL ? process.env.REDIS_URL : 'redis://localhost:6379/';
5+
6+
37
if (parseFloat(process.version.slice(1)) >= 7.6) {
48
describe('test/async.test.js', function() {
59
it('should set with ttl ok', async () => {
6-
const store = require('..')();
10+
const store = require('..')({url: redisUrl});
711
await store.set('key:ttl', { a: 1 }, 86400000);
812
(await store.get('key:ttl')).should.eql({ a: 1 });
913
(await store.client.ttl('key:ttl')).should.equal(86400);
1014
await store.quit();
1115
});
1216

1317
it('should not throw error with bad JSON', async () => {
14-
const store = require('..')();
18+
const store = require('..')({url: redisUrl});
1519
await store.client.set('key:badKey', '{I will cause an error!}');
1620
should.not.exist(await store.get('key:badKey'));
1721
await store.quit();
1822
});
1923

2024
it('should set without ttl ok', async () => {
21-
const store = require('..')();
25+
const store = require('..')({url: redisUrl});
2226
await store.set('key:nottl', { a: 1 });
2327
(await store.get('key:nottl')).should.eql({ a: 1 });
2428
(await store.client.ttl('key:nottl')).should.equal(-1);
2529
await store.quit();
2630
});
2731

2832
it('should destroy ok', async () => {
29-
const store = require('..')();
33+
const store = require('..')({url: redisUrl});
3034
await store.destroy('key:nottl');
3135
await store.destroy('key:ttl');
3236
await store.destroy('key:badKey');
@@ -44,7 +48,7 @@ if (parseFloat(process.version.slice(1)) >= 7.6) {
4448
});
4549
}
4650

47-
const store = require('..')();
51+
const store = require('..')({url: redisUrl});
4852
await store.set('key:ttl2', { a: 1, b: 2 }, 1000);
4953
await sleep(1200); // Some odd delay introduced by co-mocha
5054
should.not.exist(await store.get('key:ttl2'));

test/koa-redis.test.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
const should = require('should');
1515
const Redis = require('ioredis');
1616

17+
// allow the default url to be overriden for local testing
18+
const redisUrl = process.env.REDIS_URL ? process.env.REDIS_URL : 'redis://localhost:6379/';
19+
1720
function event(object, name) {
1821
// Convert events to promises
1922
return new Promise(resolve => {
@@ -23,7 +26,7 @@ function event(object, name) {
2326

2427
describe('test/koa-redis.test.js', () => {
2528
it('should connect and ready with external client and quit ok', function*() {
26-
const store = require('..')({ client: new Redis() });
29+
const store = require('..')({ client: new Redis(redisUrl) });
2730
yield event(store, 'connect');
2831
store.connected.should.eql(true);
2932
yield event(store, 'ready');
@@ -34,7 +37,7 @@ describe('test/koa-redis.test.js', () => {
3437

3538
it('should connect and ready with duplicated external client and disconnect ok', function*() {
3639
const store = require('..')({
37-
client: new Redis(),
40+
client: new Redis(redisUrl),
3841
duplicate: true
3942
});
4043
yield event(store, 'connect');
@@ -47,7 +50,7 @@ describe('test/koa-redis.test.js', () => {
4750

4851
it('should connect and ready with url and quit ok', function*() {
4952
const store = require('..')({
50-
url: 'redis://localhost:6379/'
53+
url: redisUrl
5154
});
5255
yield event(store, 'connect');
5356
store.connected.should.eql(true);
@@ -58,8 +61,8 @@ describe('test/koa-redis.test.js', () => {
5861
});
5962

6063
it('should set and delete with db ok', function*() {
61-
const store = require('..')({ db: 2 });
62-
const client = new Redis();
64+
const store = require('..')({ db: 2, url: redisUrl });
65+
const client = new Redis(redisUrl);
6366
client.select(2);
6467
yield store.set('key:db1', { a: 2 });
6568
(yield store.get('key:db1')).should.eql({ a: 2 });
@@ -71,15 +74,15 @@ describe('test/koa-redis.test.js', () => {
7174
});
7275

7376
it('should set with ttl ok', function*() {
74-
const store = require('..')();
77+
const store = require('..')({url: redisUrl});
7578
yield store.set('key:ttl', { a: 1 }, 86400000);
7679
(yield store.get('key:ttl')).should.eql({ a: 1 });
7780
(yield store.client.ttl('key:ttl')).should.equal(86400);
7881
yield store.quit();
7982
});
8083

8184
it('should not throw error with bad JSON', function*() {
82-
const store = require('..')();
85+
const store = require('..')({url: redisUrl});
8386
yield store.client.set('key:badKey', '{I will cause an error!}');
8487
should.not.exist(yield store.get('key:badKey'));
8588
yield store.quit();
@@ -88,7 +91,8 @@ describe('test/koa-redis.test.js', () => {
8891
it('should use default JSON.parse/JSON.stringify without serialize/unserialize function', function*() {
8992
const store = require('..')({
9093
serialize: 'Not a function',
91-
unserialize: 'Not a function'
94+
unserialize: 'Not a function',
95+
url: redisUrl
9296
});
9397
yield store.set('key:notserialized', { a: 1 });
9498
(yield store.get('key:notserialized')).should.eql({ a: 1 });
@@ -98,23 +102,24 @@ describe('test/koa-redis.test.js', () => {
98102
it('should parse bad JSON with custom unserialize function', function*() {
99103
const store = require('..')({
100104
serialize: value => 'JSON:' + JSON.stringify(value),
101-
unserialize: value => JSON.parse(value.slice(5))
105+
unserialize: value => JSON.parse(value.slice(5)),
106+
url: redisUrl
102107
});
103108
yield store.set('key:notserialized', { a: 1 });
104109
(yield store.get('key:notserialized')).should.eql({ a: 1 });
105110
yield store.quit();
106111
});
107112

108113
it('should set without ttl ok', function*() {
109-
const store = require('..')();
114+
const store = require('..')({url: redisUrl});
110115
yield store.set('key:nottl', { a: 1 });
111116
(yield store.get('key:nottl')).should.eql({ a: 1 });
112117
(yield store.client.ttl('key:nottl')).should.equal(-1);
113118
yield store.quit();
114119
});
115120

116121
it('should destroy ok', function*() {
117-
const store = require('..')();
122+
const store = require('..')({url: redisUrl});
118123
yield store.destroy('key:nottl');
119124
yield store.destroy('key:ttl');
120125
yield store.destroy('key:badKey');
@@ -132,7 +137,7 @@ describe('test/koa-redis.test.js', () => {
132137
});
133138
}
134139

135-
const store = require('..')();
140+
const store = require('..')({url: redisUrl});
136141
yield store.set('key:ttl2', { a: 1, b: 2 }, 1000);
137142
yield sleep(1200); // Some odd delay introduced by co-mocha
138143
should.not.exist(yield store.get('key:ttl2'));

0 commit comments

Comments
 (0)