/
Bitfield.js
55 lines (47 loc) · 977 Bytes
/
Bitfield.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
45
46
47
48
49
50
51
52
53
54
55
/*!
* Redback
* Copyright(c) 2011 Chris O'Hara <cohara87@gmail.com>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var Structure = require('../Structure');
/**
* Wrap the Redis bit commands.
*
* Usage:
* `redback.createBitfield(key);`
*
* Reference:
* http://redis.io/commands#string
*
* Redis Structure:
* `(namespace:)key = string`
*/
var Bitfield = exports.Bitfield = Structure.new();
/**
* Get a single bit
*
* @param {int} bit
* @param {Function} callback
* @return this;
* @api public
*/
Bitfield.prototype.get = function (bit, callback) {
this.client.getbit(this.key, bit, callback);
return this;
}
/**
* Set a single bit. The callback receives the previous value.
*
* @param {int} bit
* @param {bool} value
* @param {Function} callback
* @return this;
* @api public
*/
Bitfield.prototype.set = function (bit, value, callback) {
this.client.setbit(this.key, bit, value ? 1 : 0, callback);
return this;
}