redis-type
Version:
Redis type wrapper
95 lines (94 loc) • 2.76 kB
JavaScript
/**
* Redis SET wrapper
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Set = void 0;
var base_1 = require("./base");
/**
* Class to handle Redis SET type
*
* @extends Wrapper
*/
var Set = /** @class */ (function (_super) {
__extends(Set, _super);
function Set() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Add element(s) to the set
* Command: SADD
*
* @param {String[]|String} el Element or elements to add
*/
Set.prototype.add = function () {
var el = [];
for (var _i = 0; _i < arguments.length; _i++) {
el[_i] = arguments[_i];
}
return this.call("SADD").apply(void 0, el);
};
/**
* Get size of the set (number of elements in it)
* Command: SCARD
*/
Set.prototype.size = function () {
return this.call("SCARD")();
};
/**
* Check whether element is present in a set
* Command: SISMEMBER
*
* @param {String} el Element to check for
*/
Set.prototype.has = function (el) {
return this.call("SISMEMBER")(el);
};
/**
* Get all members of set as array
* Command: SMEMBERS
*
*/
Set.prototype.values = function () {
return this.call("SMEMBERS")();
};
/**
* Remove random element or number of elements from a set
* Command: SPOP
*
* @param {Number} count Number of elements to remove
*/
Set.prototype.pop = function (count) {
return this.call("SPOP")(count || 1);
};
/**
* Delete element(s) from a set
* Command: SREM
*
* @param {String} [...el] Element(s) to remove
*/
Set.prototype.delete = function () {
var el = [];
for (var _i = 0; _i < arguments.length; _i++) {
el[_i] = arguments[_i];
}
return this.call("SREM")(el);
};
return Set;
}(base_1.Base));
exports.Set = Set;
;