UNPKG

@silverwind/ioredis-mock

Version:

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

33 lines (23 loc) 848 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zrange = zrange; var _lodash = require("lodash"); var _zrangeCommand = require("./zrange-command.common"); function zrange(key, s, e, withScores) { const map = this.data.get(key); if (!map) { return []; } // @TODO investigate a more stable way to detect sorted lists if (this.data.has(key) && !(this.data.get(key) instanceof Map)) { return []; } const start = parseInt(s, 10); const end = parseInt(e, 10); const ordered = (0, _zrangeCommand.slice)((0, _lodash.orderBy)(Array.from(map.values()), ['score', 'value']), start, end); if (typeof withScores === 'string' && withScores.toUpperCase() === 'WITHSCORES') { return (0, _lodash.flatMap)(ordered, it => [it.value, it.score]); } return ordered.map(it => it.value); }