@silverwind/ioredis-mock
Version:
This library emulates ioredis by performing all operations in-memory.
17 lines (15 loc) • 509 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.sunion = sunion;
function sunion(...keys) {
keys.forEach(key => {
if (this.data.has(key) && !(this.data.get(key) instanceof Set)) {
throw new Error(`Key ${key} does not contain a set`);
}
});
const sets = keys.map(key => this.data.has(key) ? this.data.get(key) : new Set());
const union = new Set(sets.reduce((combined, set) => [...combined, ...Array.from(set)], []));
return Array.from(union);
}