mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-18 04:24:20 +00:00
pass entire redis object though with all opts in one go
This commit is contained in:
parent
629241611b
commit
a0c861cf5d
3 changed files with 46 additions and 33 deletions
|
@ -1,10 +1,19 @@
|
||||||
|
_ = require("underscore")
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
createClient: ()->
|
createClient: (opts)->
|
||||||
if arguments[0] instanceof Array
|
|
||||||
client = require("redis-sentinel").createClient.apply null, arguments
|
if opts.endpoints?
|
||||||
|
standardOpts = _.clone(opts)
|
||||||
|
delete standardOpts.endpoints
|
||||||
|
delete standardOpts.masterName
|
||||||
|
client = require("redis-sentinel").createClient opts.endpoints, opts.masterName, standardOpts
|
||||||
else
|
else
|
||||||
client = require("redis").createClient.apply null, arguments
|
standardOpts = _.clone(opts)
|
||||||
|
delete standardOpts.port
|
||||||
|
delete standardOpts.host
|
||||||
|
client = require("redis").createClient opts.port, opts.host, standardOpts
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,21 @@
|
||||||
{
|
{
|
||||||
"name": "redis-sharelatex",
|
"name": "redis-sharelatex",
|
||||||
"version": "0.0.0",
|
"version": "0.0.1",
|
||||||
"description": "",
|
"description": "redis wrapper for node which will either use sentinal or normal redis",
|
||||||
"main": "index.coffee",
|
"main": "index.coffee",
|
||||||
"scripts": {
|
"author": "henry oswald @ sharelatex",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chai": "^1.9.1",
|
"chai": "1.9.1",
|
||||||
"coffee-script": "^1.8.0",
|
"coffee-script": "1.8.0",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "0.4.5",
|
||||||
"grunt-contrib-coffee": "^0.11.1",
|
"grunt-contrib-coffee": "0.11.1",
|
||||||
"grunt-mocha-test": "^0.12.0",
|
"grunt-mocha-test": "0.12.0",
|
||||||
"mocha": "^1.21.4",
|
"mocha": "1.21.4",
|
||||||
"redis": "^0.12.1",
|
"redis": "0.12.1",
|
||||||
"redis-sentinel": "^0.1.1",
|
"redis-sentinel": "0.1.1",
|
||||||
"sandboxed-module": "^1.0.1",
|
"sandboxed-module": "1.0.1",
|
||||||
"sinon": "^1.10.3"
|
"sinon": "1.10.3",
|
||||||
|
"underscore": "^1.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,7 @@ describe "index", ->
|
||||||
@redis = SandboxedModule.require modulePath, requires:
|
@redis = SandboxedModule.require modulePath, requires:
|
||||||
"redis-sentinel":@sentinel
|
"redis-sentinel":@sentinel
|
||||||
"redis":@normalRedis
|
"redis":@normalRedis
|
||||||
@standardOpts =
|
@auth_pass = "1234 pass"
|
||||||
auth_pass: "my password"
|
|
||||||
|
|
||||||
describe "sentinel", ->
|
describe "sentinel", ->
|
||||||
|
|
||||||
|
@ -32,34 +31,41 @@ describe "index", ->
|
||||||
{host: '127.0.0.1', port: 26380}
|
{host: '127.0.0.1', port: 26380}
|
||||||
]
|
]
|
||||||
@masterName = "my master"
|
@masterName = "my master"
|
||||||
|
@sentinelOptions =
|
||||||
|
endpoints:@endpoints
|
||||||
|
masterName:@masterName
|
||||||
|
auth_pass:@auth_pass
|
||||||
|
|
||||||
it "should use sentinal if the first argument in an array", ->
|
it "should use sentinal if the first argument in an array", ->
|
||||||
|
client = @redis.createClient @sentinelOptions
|
||||||
client = @redis.createClient @endpoints, @masterName, @standardOpts
|
|
||||||
@sentinel.createClient.called.should.equal true
|
@sentinel.createClient.called.should.equal true
|
||||||
@normalRedis.createClient.called.should.equal false
|
@normalRedis.createClient.called.should.equal false
|
||||||
client.should.equal @sentinelClient
|
client.should.equal @sentinelClient
|
||||||
|
|
||||||
it "should pass the options correctly though", ->
|
it "should pass the options correctly though", ->
|
||||||
client = @redis.createClient @endpoints, @masterName, @standardOpts
|
client = @redis.createClient @sentinelOptions
|
||||||
@sentinel.createClient.calledWith(@endpoints, @masterName, @standardOpts).should.equal true
|
@sentinel.createClient.calledWith(@endpoints, @masterName, auth_pass:@auth_pass).should.equal true
|
||||||
client.should.equal @sentinelClient
|
client.should.equal @sentinelClient
|
||||||
|
|
||||||
describe "normal redis", ->
|
describe "normal redis", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@port = 1234
|
@standardOpts =
|
||||||
@host = "redis.mysite.env"
|
auth_pass: @auth_pass
|
||||||
|
port: 1234
|
||||||
|
host: "redis.mysite.env"
|
||||||
|
|
||||||
it "should use the normal redis driver if a non array is passed", ->
|
it "should use the normal redis driver if a non array is passed", ->
|
||||||
|
client = @redis.createClient @standardOpts
|
||||||
client = @redis.createClient @port, @host, @standardOpts
|
|
||||||
@sentinel.createClient.called.should.equal false
|
@sentinel.createClient.called.should.equal false
|
||||||
@normalRedis.createClient.called.should.equal true
|
@normalRedis.createClient.called.should.equal true
|
||||||
client.should.equal @normalRedisClient
|
client.should.equal @normalRedisClient
|
||||||
|
|
||||||
|
|
||||||
it "should use the normal redis driver if a non array is passed", ->
|
it "should use the normal redis driver if a non array is passed", ->
|
||||||
|
client = @redis.createClient @standardOpts
|
||||||
|
@normalRedis.createClient.calledWith(@standardOpts.port, @standardOpts.host, auth_pass:@auth_pass).should.equal true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
client = @redis.createClient @port, @host, @standardOpts
|
|
||||||
@normalRedis.createClient.calledWith(@port, @host, @standardOpts).should.equal true
|
|
||||||
|
|
Loading…
Reference in a new issue