overleaf/services/web/test/acceptance/coffee/helpers/redis.coffee

34 lines
975 B
CoffeeScript
Raw Normal View History

2016-07-05 09:24:24 +00:00
Settings = require('settings-sharelatex')
logger = require("logger-sharelatex")
Async = require('async')
UserSessionsRedis = require('../../../../app/js/Features/User/UserSessionsRedis')
# rclient = redis.createClient(Settings.redis.web)
rclient = UserSessionsRedis.client()
2016-07-05 09:24:24 +00:00
module.exports =
getUserSessions: (user, callback=(err, sessionsSet)->) ->
rclient.smembers UserSessionsRedis.sessionSetKey(user), (err, result) ->
2016-09-06 14:55:34 +00:00
return callback(err, result)
2016-07-05 09:24:24 +00:00
clearUserSessions: (user, callback=(err)->) ->
sessionSetKey = UserSessionsRedis.sessionSetKey(user)
2016-07-05 09:24:24 +00:00
rclient.smembers sessionSetKey, (err, sessionKeys) ->
if err
return callback(err)
if sessionKeys.length == 0
return callback(null)
actions = sessionKeys.map (k) ->
(cb) ->
rclient.del k, (err) ->
cb(err)
Async.series(
actions, (err, results) ->
rclient.srem sessionSetKey, sessionKeys, (err) ->
if err
return callback(err)
callback(null)
)