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

Replace then-redis with ioredis #86

Merged
Merged
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
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: node_js
node_js:
- 4
- 6
- '4'
- '6'
- '8'
- '10'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added node 8 and 10 since they're technically supported.

https://github.com/ember-cli/ember-cli/blob/master/docs/node-support.md

sudo: false
cache:
yarn: true
Expand Down
19 changes: 11 additions & 8 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = CoreObject.extend({
init: function(options, lib) {
this._super();
var redisOptions = {};
var redisLib = lib;
var RedisLib = lib;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I capitalized this because you call the the constructor with ioredis instead of createClient. It made more sense to me to call new RedisLib() instead of new redisLib().


if (options.url) {
redisOptions = this._stripUsernameFromConfigUrl(options.url);
Expand All @@ -21,15 +21,15 @@ module.exports = CoreObject.extend({
}

if (options.database) {
redisOptions.database = options.database;
redisOptions.db = options.database;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the API the same here, but then-redis was pretty much the only library to call this parameter database instead of db.

}
}

if (!redisLib) {
redisLib = require('then-redis');
if (!RedisLib) {
RedisLib = require('ioredis');
}

this._client = redisLib.createClient(redisOptions);
this._client = new RedisLib(redisOptions);

this._maxRecentUploads = options.maxRecentUploads;
this._allowOverwrite = options.allowOverwrite;
Expand Down Expand Up @@ -204,13 +204,16 @@ module.exports = CoreObject.extend({
if (!revisions) {
return;
}
var promises = [];
revisions.forEach(function(revision) {
if (revision !== current) {
client.del(keyPrefix + ":" + revision);
client.del(keyPrefix + ":revision-data:" + revision);
client.zrem(listKey, revision);
promises.push(client.del(keyPrefix + ":" + revision));
promises.push(client.del(keyPrefix + ":revision-data:" + revision));
promises.push(client.zrem(listKey, revision));
}
});

return RSVP.all(promises);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was seeing flaky tests when we weren't waiting on these promises, so I wrapped it in an RSVP.all so we wait for all the redis operations to complete.

});
},

Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"eslint": "^3.18.0",
"github": "^6.1.0",
"glob": "^7.1.1",
"ioredis-mock": "^3.14.0",
"mocha": "^3.2.0",
"multiline": "^1.0.2"
"multiline": "^1.0.2",
"sinon": "^6.1.5"
},
"keywords": [
"ember-addon",
Expand All @@ -34,9 +36,9 @@
"chalk": "^1.1.3",
"core-object": "^2.0.6",
"ember-cli-deploy-plugin": "^0.2.9",
"ioredis": "^3.2.2",
"redis": "^2.6.3",
"rsvp": "^3.0.18",
"then-redis": "^2.0.1"
"rsvp": "^3.0.18"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down
Loading