Skip to content

Commit e496d9b

Browse files
committed
Pass through database number
1 parent 3b1f6ed commit e496d9b

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ The Redis port. If [url](#url) is defined, then this option is not needed.
7575

7676
*Default:* `6379`
7777

78+
### database
79+
80+
The Redis database number. If [url](#url) is defined, then this option is not needed.
81+
82+
*Default:* `undefined`
83+
7884
### password
7985

8086
The Redis password. If [url](#url) is defined, then this option is not needed.

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ module.exports = {
3939
return context.commandOptions.revision || context.revisionKey;
4040
},
4141
redisDeployClient: function(context) {
42-
return context.redisDeployClient || new Redis(context.config.redis);
42+
if(context.redisDeployClient) {
43+
return context.redisDeployClient;
44+
}
45+
46+
return new (context.redisDeployClientClass || Redis)(context.config.redis);
4347
}
4448
},
4549
configure: function(/* context */) {

lib/redis.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ module.exports = CoreObject.extend({
1717
redisOptions.password = options.password;
1818
}
1919

20+
if (options.database) {
21+
redisOptions.database = options.database;
22+
}
23+
2024
this._client = require('then-redis').createClient(redisOptions);
2125
}
2226
this._maxNumberOfRecentUploads = 10;

tests/unit/index-nodetest.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var Promise = require('ember-cli/lib/ext/promise');
44
var assert = require('ember-cli/tests/helpers/assert');
5+
var CoreObject = require('core-object');
56

67
var stubProject = {
78
name: function(){
@@ -53,7 +54,8 @@ describe('redis plugin', function() {
5354
config: {
5455
redis: {
5556
host: 'somehost',
56-
port: 1234
57+
port: 1234,
58+
database: 4
5759
}
5860
}
5961
};
@@ -62,6 +64,37 @@ describe('redis plugin', function() {
6264
assert.ok(true); // didn't throw an error
6365
});
6466

67+
it('passes through config options', function () {
68+
var plugin = subject.createDeployPlugin({
69+
name: 'redis'
70+
});
71+
72+
var redisDeployClientClassInitialised = false;
73+
var context = {
74+
ui: mockUi,
75+
project: stubProject,
76+
config: {
77+
redis: {
78+
host: 'somehost',
79+
port: 1234,
80+
database: 4
81+
}
82+
},
83+
redisDeployClientClass: CoreObject.extend({
84+
init: function (options) {
85+
assert.equal(options.host, 'somehost');
86+
assert.equal(options.port, 1234);
87+
assert.equal(options.database, 4);
88+
redisDeployClientClassInitialised = true;
89+
}
90+
})
91+
};
92+
plugin.beforeHook(context);
93+
plugin.configure(context);
94+
plugin.readConfig("redisDeployClient");
95+
assert.ok(redisDeployClientClassInitialised);
96+
});
97+
6598
describe('resolving revisionKey from the pipeline', function() {
6699
it('uses the config data if it already exists', function() {
67100
var plugin = subject.createDeployPlugin({

0 commit comments

Comments
 (0)