Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ioredis v5 and dependency updates #86

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"dependencies": {
"@babel/runtime": "^7.8.3",
"co-wrap-all": "^1.0.0",
"debug": "^4.1.1",
"ioredis": "^4.14.1"
"debug": "^4.1.1"
},
"devDependencies": {
"@babel/cli": "^7.8.3",
Expand All @@ -46,10 +45,14 @@
"remark-preset-github": "^0.0.16",
"rimraf": "^3.0.0",
"should": "^13.2.3",
"xo": "^0.25.3"
"xo": "^0.25.3",
"ioredis": "^5.2.4"
},
"peerDependencies": {
"ioredis": "5.x"
},
"engines": {
"node": ">= 4"
"node": ">= 12.22.0"
},
"files": [
"lib"
Expand Down
15 changes: 10 additions & 5 deletions test/async.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
const should = require('should');

// allow the default url to be overriden for local testing
const redisUrl = process.env.REDIS_URL
? process.env.REDIS_URL
: 'redis://localhost:6379/';

if (parseFloat(process.version.slice(1)) >= 7.6) {
describe('test/async.test.js', function() {
it('should set with ttl ok', async () => {
const store = require('..')();
const store = require('..')({ url: redisUrl });
await store.set('key:ttl', { a: 1 }, 86400000);
(await store.get('key:ttl')).should.eql({ a: 1 });
(await store.client.ttl('key:ttl')).should.equal(86400);
await store.quit();
});

it('should not throw error with bad JSON', async () => {
const store = require('..')();
const store = require('..')({ url: redisUrl });
await store.client.set('key:badKey', '{I will cause an error!}');
should.not.exist(await store.get('key:badKey'));
await store.quit();
});

it('should set without ttl ok', async () => {
const store = require('..')();
const store = require('..')({ url: redisUrl });
await store.set('key:nottl', { a: 1 });
(await store.get('key:nottl')).should.eql({ a: 1 });
(await store.client.ttl('key:nottl')).should.equal(-1);
await store.quit();
});

it('should destroy ok', async () => {
const store = require('..')();
const store = require('..')({ url: redisUrl });
await store.destroy('key:nottl');
await store.destroy('key:ttl');
await store.destroy('key:badKey');
Expand All @@ -44,7 +49,7 @@ if (parseFloat(process.version.slice(1)) >= 7.6) {
});
}

const store = require('..')();
const store = require('..')({ url: redisUrl });
await store.set('key:ttl2', { a: 1, b: 2 }, 1000);
await sleep(1200); // Some odd delay introduced by co-mocha
should.not.exist(await store.get('key:ttl2'));
Expand Down
31 changes: 19 additions & 12 deletions test/koa-redis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
const should = require('should');
const Redis = require('ioredis');

// allow the default url to be overriden for local testing
const redisUrl = process.env.REDIS_URL
? process.env.REDIS_URL
: 'redis://localhost:6379/';

function event(object, name) {
// Convert events to promises
return new Promise(resolve => {
Expand All @@ -23,7 +28,7 @@ function event(object, name) {

describe('test/koa-redis.test.js', () => {
it('should connect and ready with external client and quit ok', function*() {
const store = require('..')({ client: new Redis() });
const store = require('..')({ client: new Redis(redisUrl) });
yield event(store, 'connect');
store.connected.should.eql(true);
yield event(store, 'ready');
Expand All @@ -34,7 +39,7 @@ describe('test/koa-redis.test.js', () => {

it('should connect and ready with duplicated external client and disconnect ok', function*() {
const store = require('..')({
client: new Redis(),
client: new Redis(redisUrl),
duplicate: true
});
yield event(store, 'connect');
Expand All @@ -47,7 +52,7 @@ describe('test/koa-redis.test.js', () => {

it('should connect and ready with url and quit ok', function*() {
const store = require('..')({
url: 'redis://localhost:6379/'
url: redisUrl
});
yield event(store, 'connect');
store.connected.should.eql(true);
Expand All @@ -58,8 +63,8 @@ describe('test/koa-redis.test.js', () => {
});

it('should set and delete with db ok', function*() {
const store = require('..')({ db: 2 });
const client = new Redis();
const store = require('..')({ db: 2, url: redisUrl });
const client = new Redis(redisUrl);
client.select(2);
yield store.set('key:db1', { a: 2 });
(yield store.get('key:db1')).should.eql({ a: 2 });
Expand All @@ -71,15 +76,15 @@ describe('test/koa-redis.test.js', () => {
});

it('should set with ttl ok', function*() {
const store = require('..')();
const store = require('..')({ url: redisUrl });
yield store.set('key:ttl', { a: 1 }, 86400000);
(yield store.get('key:ttl')).should.eql({ a: 1 });
(yield store.client.ttl('key:ttl')).should.equal(86400);
yield store.quit();
});

it('should not throw error with bad JSON', function*() {
const store = require('..')();
const store = require('..')({ url: redisUrl });
yield store.client.set('key:badKey', '{I will cause an error!}');
should.not.exist(yield store.get('key:badKey'));
yield store.quit();
Expand All @@ -88,7 +93,8 @@ describe('test/koa-redis.test.js', () => {
it('should use default JSON.parse/JSON.stringify without serialize/unserialize function', function*() {
const store = require('..')({
serialize: 'Not a function',
unserialize: 'Not a function'
unserialize: 'Not a function',
url: redisUrl
});
yield store.set('key:notserialized', { a: 1 });
(yield store.get('key:notserialized')).should.eql({ a: 1 });
Expand All @@ -98,23 +104,24 @@ describe('test/koa-redis.test.js', () => {
it('should parse bad JSON with custom unserialize function', function*() {
const store = require('..')({
serialize: value => 'JSON:' + JSON.stringify(value),
unserialize: value => JSON.parse(value.slice(5))
unserialize: value => JSON.parse(value.slice(5)),
url: redisUrl
});
yield store.set('key:notserialized', { a: 1 });
(yield store.get('key:notserialized')).should.eql({ a: 1 });
yield store.quit();
});

it('should set without ttl ok', function*() {
const store = require('..')();
const store = require('..')({ url: redisUrl });
yield store.set('key:nottl', { a: 1 });
(yield store.get('key:nottl')).should.eql({ a: 1 });
(yield store.client.ttl('key:nottl')).should.equal(-1);
yield store.quit();
});

it('should destroy ok', function*() {
const store = require('..')();
const store = require('..')({ url: redisUrl });
yield store.destroy('key:nottl');
yield store.destroy('key:ttl');
yield store.destroy('key:badKey');
Expand All @@ -132,7 +139,7 @@ describe('test/koa-redis.test.js', () => {
});
}

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