1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

fix #1650 - add support for Buffer in some commands, add GET_BUFFER command

This commit is contained in:
leibale
2021-09-13 19:49:39 -04:00
parent 1413a69a6b
commit 08837c8648
65 changed files with 300 additions and 227 deletions

View File

@@ -91,10 +91,8 @@ export default class RedisSocket extends EventEmitter {
return this.#isOpen;
}
get chunkRecommendedSize(): number {
if (!this.#socket) return 0;
return this.#socket.writableHighWaterMark - this.#socket.writableLength;
get isSocketExists(): boolean {
return !!this.#socket;
}
constructor(initiator?: RedisSocketInitiator, options?: RedisSocketOptions) {
@@ -214,12 +212,12 @@ export default class RedisSocket extends EventEmitter {
.catch(err => this.emit('error', err));
}
write(encodedCommands: string): boolean {
write(toWrite: string | Buffer): boolean {
if (!this.#socket) {
throw new ClientClosedError();
}
return this.#socket.write(encodedCommands);
return this.#socket.write(toWrite);
}
async disconnect(ignoreIsOpen = false): Promise<void> {
@@ -251,4 +249,22 @@ export default class RedisSocket extends EventEmitter {
throw err;
}
}
#isCorked = false;
cork(): void {
if (!this.#socket) {
return;
}
if (!this.#isCorked) {
this.#socket.cork();
this.#isCorked = true;
queueMicrotask(() => {
this.#socket?.uncork();
this.#isCorked = false;
});
}
}
}