UNPKG

ioredis-mock

Version:

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

33 lines (26 loc) 867 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rpoplpush = rpoplpush; function rpoplpush(source, destination) { if (this.data.has(source) && !(this.data.get(source) instanceof Array)) { throw new Error("Key " + source + " does not contain a list"); } if (this.data.has(destination) && !(this.data.get(destination) instanceof Array)) { throw new Error("Key " + destination + " does not contain a list"); } if (!this.data.has(source) || this.data.get(source).length === 0) { return null; } if (!this.data.has(destination)) { this.data.set(destination, []); } var newSource = this.data.get(source); var item = newSource.pop(); var newDest = this.data.get(destination); newDest.unshift(item); this.data.set(source, newSource); this.data.set(destination, newDest); return item; }