summaryrefslogtreecommitdiffstats
path: root/protoype/activeusers.js
blob: 64df0d99a303f7e97b0aa37b58128ae4e0f75e8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * activeusers.js
 *
 * list of active users, maps tag/user to a status string
 */

var redis = require('redis');
var client = redis.createClient();
var util = require('util');

client.on('error', function(e) {
    util.log('[activeusers] redis ' + e);
});

function isactive(tag) {
    client.get(tag, function(err, reply) {
        if (err || !reply)
            return false;
        else
            return true;
    });
}

function setstatus(tag, status) {
    client.set(tag, status, redis.print);
}

function list() {
    client.keys('*', function(err, replies) {
        if (err || !replies)
            util.log('[activeusers] could not get a list of users');
        else
        {
            replies.forEach(function(reply, i) {
                util.log('key ' + i + ': ' + reply);
            });
        }
    });
}

exports.isactive = isactive;
exports.setstatus = setstatus;
exports.list = list;