diff --git a/redis.ts b/redis.ts index a5da7b6d..b4ed6519 100644 --- a/redis.ts +++ b/redis.ts @@ -112,6 +112,7 @@ export interface Redis extends RedisCommands { ): Promise; connect(): Promise; close(): void; + [Symbol.dispose](): void; } class RedisImpl implements Redis { @@ -142,7 +143,11 @@ class RedisImpl implements Redis { } close(): void { - this.executor.close(); + return this.executor.close(); + } + + [Symbol.dispose](): void { + return this.close(); } async execReply( diff --git a/tests/commands/connection.ts b/tests/commands/connection.ts index 22846c7a..081a0f74 100644 --- a/tests/commands/connection.ts +++ b/tests/commands/connection.ts @@ -143,6 +143,14 @@ export function connectionTests( client.close(); }); }); + + describe("using", () => { + it("implements `Symbol.dispose`", async () => { + using client = await connect(getOpts()); + assert(client.isConnected); + assert(!client.isClosed); + }); + }); } function parseCommandStats(