Skip to content

Commit

Permalink
Replace then-redis with ioredis.
Browse files Browse the repository at this point in the history
Also, significantly reduce mocking in the test suite by using an
in-memory redis client.
Fixes ember-cli-deploy#51
Fixes ember-cli-deploy#74
  • Loading branch information
blimmer committed Aug 30, 2018
1 parent b299ad5 commit 9b03b61
Show file tree
Hide file tree
Showing 5 changed files with 761 additions and 536 deletions.
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;

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;
}
}

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);
});
},

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

0 comments on commit 9b03b61

Please sign in to comment.