Merge pull request #3 from sharelatex/bg-support-opts-for-cluster

add support for passing options to cluster
This commit is contained in:
Brian Gough 2017-06-26 13:43:36 +01:00 committed by GitHub
commit cf87ef7dd1
3 changed files with 25 additions and 4 deletions

View file

@ -17,7 +17,10 @@ module.exports = RedisSharelatex =
client.healthCheck = RedisSharelatex.singleInstanceHealthCheckBuilder(client)
else if opts.cluster?
Redis = require("ioredis")
client = new Redis.Cluster(opts.cluster)
standardOpts = _.clone(opts)
delete standardOpts.cluster
delete standardOpts.key_schema
client = new Redis.Cluster(opts.cluster, standardOpts)
client.healthCheck = RedisSharelatex.clusterHealthCheckBuilder(client)
RedisSharelatex._monkeyPatchIoredisExec(client)
else

View file

@ -1,6 +1,6 @@
{
"name": "redis-sharelatex",
"version": "1.0.2",
"version": "1.0.3",
"description": "Redis wrapper for node which will either use cluster, sentinal, or single instance redis",
"main": "index.js",
"author": "ShareLaTeX",

View file

@ -23,7 +23,7 @@ describe "index", ->
"redis":@normalRedis
"ioredis": @ioredis =
Cluster: class Cluster
constructor: (@config) ->
constructor: (@config, @options) ->
@auth_pass = "1234 pass"
@endpoints = [
{host: '127.0.0.1', port: 26379},
@ -69,12 +69,30 @@ describe "index", ->
describe "cluster", ->
beforeEach ->
@cluster = [{"mock": "cluster"}, { "mock": "cluster2"}]
@extraOptions = {keepAlive:100}
@settings =
cluster: @cluster
redisOptions: @extraOptions
key_schema: {foo: (x) -> "#{x}"}
it "should pass the options correctly though", ->
it "should pass the options correctly though with no options", ->
client = @redis.createClient cluster: @cluster
assert(client instanceof @ioredis.Cluster)
client.config.should.deep.equal @cluster
it "should not pass the key_schema through to the driver", ->
client = @redis.createClient cluster: @cluster, key_schema: "foobar"
assert(client instanceof @ioredis.Cluster)
client.config.should.deep.equal @cluster
expect(client.options).to.deep.equal {retry_max_delay: 5000}
it "should pass the options correctly though with additional options", ->
client = @redis.createClient @settings
assert(client instanceof @ioredis.Cluster)
client.config.should.deep.equal @cluster
# need to use expect here because of _.clone in sandbox
expect(client.options).to.deep.equal {redisOptions: @extraOptions, retry_max_delay: 5000}
describe "monkey patch ioredis exec", ->
beforeEach ->
@callback = sinon.stub()