-
Notifications
You must be signed in to change notification settings - Fork 5
/
redis-store.js
44 lines (35 loc) · 1 KB
/
redis-store.js
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
// redis-store.js - A redis-backed store for simple-acl
module.exports = (function() {
var RedisStore = function(client, prefix) {
// overloads
if (typeof client === 'string') {
prefix = client;
client = undefined;
}
// defaults
if (!client) client = require('redis').createClient();
if (!prefix) prefix = 'sacl:';
this.client = client;
this.prefix = prefix;
};
RedisStore.prototype =
{ 'grant':
function(grantee, resource, callback) {
var key = this.prefix + grantee;
this.client.sadd(key, resource, callback);
}
, 'assert':
function(grantee, resource, callback) {
var key = this.prefix + grantee;
this.client.sismember(key, resource, function(e, ismember) {
callback(e, !!ismember);
});
}
, 'revoke':
function(grantee, resource, callback) {
var key = this.prefix + grantee;
this.client.srem(key, resource, callback);
}
};
return RedisStore;
})();