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

35 lines
1,011 B
CoffeeScript
Raw Normal View History

2016-07-05 05:24:24 -04:00
Settings = require('settings-sharelatex')
redis = require('redis-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 05:24:24 -04:00
module.exports =
getUserSessions: (user, callback=(err, sessionsSet)->) ->
rclient.smembers UserSessionsRedis.sessionSetKey(user), (err, result) ->
2016-09-06 10:55:34 -04:00
return callback(err, result)
2016-07-05 05:24:24 -04:00
clearUserSessions: (user, callback=(err)->) ->
sessionSetKey = UserSessionsRedis.sessionSetKey(user)
2016-07-05 05:24:24 -04: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)
)