MCPcopy
hub / github.com/redis/node-redis / RedisClientPool

Class RedisClientPool

packages/client/lib/client/pool.ts:111–622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109type NamespaceProxyPool = { _self: ProxyPool };
110
111export class RedisClientPool<
112 M extends RedisModules = {},
113 F extends RedisFunctions = {},
114 S extends RedisScripts = {},
115 RESP extends RespVersions = 3,
116 TYPE_MAPPING extends TypeMapping = {}
117> extends EventEmitter {
118 static #createCommand(command: Command, resp: RespVersions) {
119 const transformReply = getTransformReply(command, resp);
120
121 return async function (this: ProxyPool, ...args: Array<unknown>) {
122 const parser = new BasicCommandParser(this._self._keyPrefix);
123 command.parseCommand(parser, ...args);
124
125 return this.execute(client => client._executeCommand(command, parser, this._commandOptions, transformReply))
126 };
127 }
128
129 static #createModuleCommand(command: Command, resp: RespVersions) {
130 const transformReply = getTransformReply(command, resp);
131
132 return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
133 const parser = new BasicCommandParser(this._self._keyPrefix);
134 command.parseCommand(parser, ...args);
135
136 return this._self.execute(client => client._executeCommand(command, parser, this._self._commandOptions, transformReply))
137 };
138 }
139
140 static #createFunctionCommand(name: string, fn: RedisFunction, resp: RespVersions) {
141 const prefix = functionArgumentsPrefix(name, fn);
142 const transformReply = getTransformReply(fn, resp);
143
144 return async function (this: NamespaceProxyPool, ...args: Array<unknown>) {
145 const parser = new BasicCommandParser(this._self._keyPrefix);
146 parser.push(...prefix);
147 fn.parseCommand(parser, ...args);
148
149 return this._self.execute(client => client._executeCommand(fn, parser, this._self._commandOptions, transformReply)) };
150 }
151
152 static #createScriptCommand(script: RedisScript, resp: RespVersions) {
153 const prefix = scriptArgumentsPrefix(script);
154 const transformReply = getTransformReply(script, resp);
155
156 return async function (this: ProxyPool, ...args: Array<unknown>) {
157 const parser = new BasicCommandParser(this._self._keyPrefix);
158 parser.pushVariadic(prefix);
159 script.parseCommand(parser, ...args);
160
161 return this.execute(client => client._executeScript(script, parser, this._commandOptions, transformReply))
162 };
163 }
164
165 // eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic cache, keys/values vary per call site
166 static #SingleEntryCache = new SingleEntryCache<any, any>();
167
168 static create<

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected