Skip to content

Commit 2a247c6

Browse files
committed
fix #2 RedisGraph constructor can get a node_redis client
1 parent fb07e23 commit 2a247c6

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
},
1414
"devDependencies": {
1515
"mocha": "^5.2.0"
16+
},
17+
"scripts": {
18+
"test": "mocha"
1619
}
1720
}

src/redisGraph.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ module.exports = class RedisGraph {
1212
* See: node_redis for more options on createClient
1313
*
1414
* @param graphId the graph id
15-
* @param host Redis host
15+
* @param host Redis host or node_redis client
1616
* @param port Redis port
17+
* @param options node_redis options
1718
*/
1819
constructor(graphId, host, port, options) {
19-
this._graphId = graphId;
20-
let client = redis.createClient.apply(redis, [].slice.call(arguments,1));
20+
this._graphId = graphId;
21+
let client = (host instanceof redis.RedisClient) ? host : redis.createClient.apply(redis, [].slice.call(arguments,1));
2122
this._sendCommand = util.promisify(client.send_command).bind(client);
2223
}
23-
24+
2425
/**
2526
* Execute a Cypher query
2627
*

test/redisGraphAPITest.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert'),
2+
redis = require('redis'),
23
Label = require('../src/statistics').Label,
34
RedisGraphAPI = require('../src/redisGraph');
45

@@ -9,6 +10,10 @@ describe('RedisGraphAPI Test', () =>{
910
return api.deleteGraph();
1011
});
1112

13+
it('test bring your client', () => {
14+
return new RedisGraphAPI( "social", redis.createClient());
15+
});
16+
1217
it('test Create Node', () => {
1318
// Create a node
1419
return api.query("CREATE ({name:'roi',age:32})")
@@ -79,4 +84,4 @@ describe('RedisGraphAPI Test', () =>{
7984
assert.equal( "32.000000", record.getString(0));
8085
});
8186
});
82-
})
87+
});

0 commit comments

Comments
 (0)