jsql-neo 5.2.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -358,25 +358,34 @@ class RedisServer {
358
358
 
359
359
  /* ---------- RESP protocol ---------- */
360
360
  listen() {
361
- this.server = net.createServer((socket) => {
362
- let buf = Buffer.alloc(0);
363
- this._authedSockets.set(socket, false);
364
- socket.setEncoding('utf8');
365
- socket.on('data', (chunk) => {
366
- buf += chunk;
367
- for (;;) {
368
- const msg = this._parse(buf);
369
- if (!msg) break;
370
- buf = buf.slice(msg.consumed);
371
- this._handle(socket, msg.cmd, msg.args);
372
- }
373
- });
374
- socket.on('error', () => {});
375
- });
361
+ this.server = net.createServer((socket) => this._handleSocket(socket));
376
362
  this.server.listen(this.port, this.host);
377
363
  return this;
378
364
  }
379
365
 
366
+ /** 供多协议嗅探复用:把 socket 交给 Redis 处理,可携带已缓冲的首包 */
367
+ _handleSocket(socket, existing = '') {
368
+ let buf = String(existing || '');
369
+ this._authedSockets.set(socket, false);
370
+ socket.setEncoding('utf8');
371
+ socket.on('data', (chunk) => {
372
+ buf += chunk;
373
+ for (;;) {
374
+ const msg = this._parse(buf);
375
+ if (!msg) break;
376
+ buf = buf.slice(msg.consumed);
377
+ this._handle(socket, msg.cmd, msg.args);
378
+ }
379
+ });
380
+ socket.on('error', () => {});
381
+ for (;;) {
382
+ const msg = this._parse(buf);
383
+ if (!msg) break;
384
+ buf = buf.slice(msg.consumed);
385
+ this._handle(socket, msg.cmd, msg.args);
386
+ }
387
+ }
388
+
380
389
  _parse(buf) {
381
390
  if (buf[0] !== '*') {
382
391
  const i = buf.indexOf('\r\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "5.2.0",
3
+ "version": "5.2.1",
4
4
  "description": "JSQL-NEO — Rust-powered embedded database with WASM, REST API, B-Tree indexes, WAL, crash recovery",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",