UNPKG

@silverwind/ioredis-mock

Version:

This library emulates ioredis by performing all operations in-memory.

25 lines (19 loc) 651 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zpopmax = zpopmax; var _lodash = require("lodash"); var _zrangeCommand = require("./zrange-command.common"); function zpopmax(key, count = 1) { const map = this.data.get(key); if (map == null || !(map instanceof Map)) { return []; } const ordered = (0, _lodash.reverse)((0, _zrangeCommand.slice)((0, _lodash.orderBy)(Array.from(map.values()), ['score', 'value']), -count, -1)); (0, _lodash.forEach)(ordered, it => { map.delete(it.value); }); this.data.set(key, map); return (0, _lodash.flatMap)(ordered, it => [it.value, it.score]); }