You've already forked node-redis
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:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user