UNPKG

@litert/redis

Version:

A redis protocol implement for Node.js.

103 lines (101 loc) 3.6 kB
"use strict"; /** * 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.CommandClient = void 0; /* eslint-disable @typescript-eslint/unbound-method */ const C = require("./Common"); const CMD = require("./Commands"); const PipelineClient_1 = require("./PipelineClient"); const WatchClient_1 = require("./WatchClient"); const ProtocolClient_1 = require("./ProtocolClient"); class CommandClient extends ProtocolClient_1.ProtocolClient { _createDecoder; _createEncoder; constructor(opts) { super({ mode: C.EClientMode.SIMPLE, ...opts }); this._createDecoder = opts.decoderFactory; this._createEncoder = opts.encoderFactory; } async pipeline() { const cli = new PipelineClient_1.PipelineClient({ 'host': this.host, 'port': this.port, 'decoderFactory': this._createDecoder, 'encoderFactory': this._createEncoder, 'commandTimeout': this._cfg.commandTimeout, 'connectTimeout': this._cfg.connectTimeout, 'queueSize': this._cfg.queueSize, 'actionOnQueueFull': this._cfg.actionOnQueueFull, }); await cli.connect(); if (this._passwd) { await cli.auth(this._passwd, this._aclUser); } if (this._db) { await cli.select(this._db); } return cli; } async multi() { const cli = new WatchClient_1.MultiClient({ 'host': this.host, 'port': this.port, 'decoderFactory': this._createDecoder, 'encoderFactory': this._createEncoder, 'commandTimeout': this._cfg.commandTimeout, 'connectTimeout': this._cfg.connectTimeout, 'queueSize': this._cfg.queueSize, 'actionOnQueueFull': this._cfg.actionOnQueueFull, }); await cli.connect(); if (this._passwd) { await cli.auth(this._passwd, this._aclUser); } if (this._db) { await cli.select(this._db); } return cli; } } exports.CommandClient = CommandClient; (function (c) { let name; for (name in CMD.COMMANDS) { if (name === 'auth' || name === 'select') { continue; } let process; const cmd = CMD.COMMANDS[name]; if (cmd.process === undefined) { process = 'return this._command(req.cmd, req.args);'; } else if (cmd.process === null) { process = 'this._command(req.cmd, req.args);'; } else { process = 'return process(await this._command(req.cmd, req.args), req.args, req.ctx);'; } c.prototype[name] = (new Function('process', 'command', `return async function(...args) { const req = command(...args); ${process} };`))(cmd.process, cmd.prepare); } })(CommandClient); //# sourceMappingURL=CommandClient.js.map