update redis key

This commit is contained in:
Henry Oswald 2019-02-04 09:47:11 +00:00
parent 0939a558d7
commit a07e516f65
2 changed files with 10 additions and 8 deletions

View file

@ -5,15 +5,15 @@ settings =
port: process.env['REAL_TIME_REDIS_PORT'] or process.env['REDIS_PORT'] or "6379" port: process.env['REAL_TIME_REDIS_PORT'] or process.env['REDIS_PORT'] or "6379"
password: process.env["REAL_TIME_REDIS_PASSWORD"] or process.env["REDIS_PASSWORD"] or "" password: process.env["REAL_TIME_REDIS_PASSWORD"] or process.env["REDIS_PASSWORD"] or ""
key_schema: key_schema:
clientsInProject: ({project_id}) -> "clients_in_project:#{project_id}" clientsInProject: ({project_id}) -> "clients_in_project:{#{project_id}}"
connectedUser: ({project_id, client_id})-> "connected_user:#{project_id}:#{client_id}" connectedUser: ({project_id, client_id})-> "connected_user:{#{project_id}}:#{client_id}"
documentupdater: documentupdater:
host: process.env['DOC_UPDATER_REDIS_HOST'] or process.env['REDIS_HOST'] or "localhost" host: process.env['DOC_UPDATER_REDIS_HOST'] or process.env['REDIS_HOST'] or "localhost"
port: process.env['DOC_UPDATER_REDIS_PORT'] or process.env['REDIS_PORT'] or "6379" port: process.env['DOC_UPDATER_REDIS_PORT'] or process.env['REDIS_PORT'] or "6379"
password: process.env["DOC_UPDATER_REDIS_PASSWORD"] or process.env["REDIS_PASSWORD"] or "" password: process.env["DOC_UPDATER_REDIS_PASSWORD"] or process.env["REDIS_PASSWORD"] or ""
key_schema: key_schema:
pendingUpdates: ({doc_id}) -> "PendingUpdates:#{doc_id}" pendingUpdates: ({doc_id}) -> "PendingUpdates:{#{doc_id}}"
websessions: websessions:
host: process.env['WEB_REDIS_HOST'] or process.env['REDIS_HOST'] or "localhost" host: process.env['WEB_REDIS_HOST'] or process.env['REDIS_HOST'] or "localhost"

View file

@ -10,6 +10,8 @@ settings = require "settings-sharelatex"
redis = require "redis-sharelatex" redis = require "redis-sharelatex"
rclient = redis.createClient(settings.redis.websessions) rclient = redis.createClient(settings.redis.websessions)
redisSettings = settings.redis
describe "applyOtUpdate", -> describe "applyOtUpdate", ->
before -> before ->
@update = { @update = {
@ -48,7 +50,7 @@ describe "applyOtUpdate", ->
done() done()
it "should push the update into redis", (done) -> it "should push the update into redis", (done) ->
rclient.lrange "PendingUpdates:#{@doc_id}", 0, -1, (error, [update]) => rclient.lrange redisSettings.documentupdater.key_schema.pendingUpdates({@doc_id}), 0, -1, (error, [update]) =>
update = JSON.parse(update) update = JSON.parse(update)
update.op.should.deep.equal @update.op update.op.should.deep.equal @update.op
update.meta.should.deep.equal { update.meta.should.deep.equal {
@ -61,7 +63,7 @@ describe "applyOtUpdate", ->
async.series [ async.series [
(cb) => rclient.del "pending-updates-list", cb (cb) => rclient.del "pending-updates-list", cb
(cb) => rclient.del "DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}", cb (cb) => rclient.del "DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}", cb
(cb) => rclient.del "PendingUpdates:#{@doc_id}", cb (cb) => rclient.del redisSettings.documentupdater.key_schema.pendingUpdates(@doc_id), cb
], done ], done
describe "when authorized to read-only with an edit update", -> describe "when authorized to read-only with an edit update", ->
@ -102,7 +104,7 @@ describe "applyOtUpdate", ->
, 300 , 300
it "should not put the update in redis", (done) -> it "should not put the update in redis", (done) ->
rclient.llen "PendingUpdates:#{@doc_id}", (error, len) => rclient.llen redisSettings.documentupdater.key_schema.pendingUpdates({@doc_id}), (error, len) =>
len.should.equal 0 len.should.equal 0
done() done()
@ -142,7 +144,7 @@ describe "applyOtUpdate", ->
done() done()
it "should push the update into redis", (done) -> it "should push the update into redis", (done) ->
rclient.lrange "PendingUpdates:#{@doc_id}", 0, -1, (error, [update]) => rclient.lrange redisSettings.documentupdater.key_schema.pendingUpdates({@doc_id}), 0, -1, (error, [update]) =>
update = JSON.parse(update) update = JSON.parse(update)
update.op.should.deep.equal @comment_update.op update.op.should.deep.equal @comment_update.op
update.meta.should.deep.equal { update.meta.should.deep.equal {
@ -155,5 +157,5 @@ describe "applyOtUpdate", ->
async.series [ async.series [
(cb) => rclient.del "pending-updates-list", cb (cb) => rclient.del "pending-updates-list", cb
(cb) => rclient.del "DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}", cb (cb) => rclient.del "DocsWithPendingUpdates", "#{@project_id}:#{@doc_id}", cb
(cb) => rclient.del "PendingUpdates:#{@doc_id}", cb (cb) => rclient.del redisSettings.documentupdater.key_schema.pendingUpdates({@doc_id}), cb
], done ], done