@litert/redis
Version:
A redis protocol implement for Node.js.
77 lines (75 loc) • 2.5 kB
JavaScript
;
/**
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.PipelineClient = void 0;
/* eslint-disable @typescript-eslint/unbound-method */
const C = require("./Common");
const CMD = require("./Commands");
const ProtocolClient_1 = require("./ProtocolClient");
class PipelineClient extends ProtocolClient_1.ProtocolClient {
_queue;
constructor(opts) {
super({
mode: C.EClientMode.PIPELINE,
...opts
});
this._queue = [];
}
abort() {
this._queue = [];
}
async exec() {
if (!this._queue.length) {
return [];
}
const queue = this._queue;
this._queue = [];
const ret = new Array(queue.length);
const data = await this._bulkCommands(queue);
for (let i = 0; i < queue.length; i++) {
const item = queue[i];
if (item.process === undefined) {
ret[i] = data[i];
}
else if (item.process === null) {
ret[i] = null;
}
else {
ret[i] = item.process(data[i], item.args, item.ctx);
}
}
return ret;
}
command(cmd, args) {
this._queue.push({ args, process: undefined, cmd });
}
}
exports.PipelineClient = PipelineClient;
(function (c) {
let name;
for (name in CMD.COMMANDS) {
if (name === 'auth' || name === 'select') {
continue;
}
const cmd = CMD.COMMANDS[name];
c.prototype[name] = (new Function('process', 'command', `return function(...args) {
const req = command(...args);
this._queue.push({ args: req.args, process: process, cmd: req.cmd, ctx: req.ctx });
};`))(cmd.process, cmd.prepare);
}
})(PipelineClient);
//# sourceMappingURL=PipelineClient.js.map