From bce937f56227383a6bfa65f1b674dfa779b4e8e3 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 16 Jun 2017 15:28:55 +0100 Subject: [PATCH 1/2] add support for passing options to cluster --- libraries/redis-wrapper/index.coffee | 4 +++- libraries/redis-wrapper/package.json | 2 +- libraries/redis-wrapper/test.coffee | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libraries/redis-wrapper/index.coffee b/libraries/redis-wrapper/index.coffee index aa6e43cb1f..ba9a659a98 100644 --- a/libraries/redis-wrapper/index.coffee +++ b/libraries/redis-wrapper/index.coffee @@ -17,7 +17,9 @@ 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 + client = new Redis.Cluster(opts.cluster, standardOpts) client.healthCheck = RedisSharelatex.clusterHealthCheckBuilder(client) RedisSharelatex._monkeyPatchIoredisExec(client) else diff --git a/libraries/redis-wrapper/package.json b/libraries/redis-wrapper/package.json index 2f47b8cd92..cc8e847b39 100644 --- a/libraries/redis-wrapper/package.json +++ b/libraries/redis-wrapper/package.json @@ -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", diff --git a/libraries/redis-wrapper/test.coffee b/libraries/redis-wrapper/test.coffee index 0dc5c8ad74..e2bfa926b8 100644 --- a/libraries/redis-wrapper/test.coffee +++ b/libraries/redis-wrapper/test.coffee @@ -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,23 @@ describe "index", -> describe "cluster", -> beforeEach -> @cluster = [{"mock": "cluster"}, { "mock": "cluster2"}] + @extraOptions = {keepAlive:100} + @settings = + cluster: @cluster + redisOptions: @extraOptions - 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 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() From bda88c035649fc6d5df61d52435959e623072232 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Mon, 19 Jun 2017 15:46:21 +0100 Subject: [PATCH 2/2] remove the key_schema from options passed to redis --- libraries/redis-wrapper/index.coffee | 1 + libraries/redis-wrapper/test.coffee | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/libraries/redis-wrapper/index.coffee b/libraries/redis-wrapper/index.coffee index ba9a659a98..2dd8d23fe3 100644 --- a/libraries/redis-wrapper/index.coffee +++ b/libraries/redis-wrapper/index.coffee @@ -19,6 +19,7 @@ module.exports = RedisSharelatex = Redis = require("ioredis") 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) diff --git a/libraries/redis-wrapper/test.coffee b/libraries/redis-wrapper/test.coffee index e2bfa926b8..84e84f0894 100644 --- a/libraries/redis-wrapper/test.coffee +++ b/libraries/redis-wrapper/test.coffee @@ -73,12 +73,19 @@ describe "index", -> @settings = cluster: @cluster redisOptions: @extraOptions + key_schema: {foo: (x) -> "#{x}"} 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)