RedisManager.coffee 815 B

123456789101112131415161718192021
  1. Settings = require "settings-sharelatex"
  2. redis = require('redis')
  3. redisConf = Settings.redis?.web or {host: "localhost", port: 6379}
  4. rclient = redis.createClient(redisConf.port, redisConf.host)
  5. rclient.auth(redisConf.password)
  6. buildRawUpdatesKey = (doc_id) -> "UncompressedHistoryOps:#{doc_id}"
  7. module.exports = RedisManager =
  8. getOldestRawUpdates: (doc_id, batchSize, callback = (error, rawUpdates) ->) ->
  9. key = buildRawUpdatesKey(doc_id)
  10. rclient.lrange key, 0, batchSize - 1, (error, jsonUpdates) ->
  11. try
  12. rawUpdates = ( JSON.parse(update) for update in jsonUpdates or [] )
  13. catch e
  14. return callback(e)
  15. callback null, rawUpdates
  16. deleteOldestRawUpdates: (doc_id, batchSize, callback = (error, rawUpdates) ->) ->
  17. key = buildRawUpdatesKey(doc_id)
  18. rclient.ltrim key, batchSize, -1, callback