1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Have client.connect() return a Promise<RedisClient> (#2602)

* Connect returns the instance of the client

* Added a test

* No auto setup

* Added a bit of docs

* fix the return type, test, and the docs

* fix return type

* Update packages/client/lib/client/index.spec.ts

Co-authored-by: Francisco Presencia <franciscop@users.noreply.github.com>

---------

Co-authored-by: Leibale Eidelman <me@leibale.com>
This commit is contained in:
Francisco Presencia
2023-09-19 06:40:08 +09:00
committed by GitHub
parent 5a108265da
commit fb255eb5d0
3 changed files with 19 additions and 7 deletions

View File

@@ -107,6 +107,19 @@ describe('Client', () => {
});
});
describe('connect', () => {
testUtils.testWithClient('connect should return the client instance', async client => {
try {
assert.equal(await client.connect(), client);
} finally {
if (client.isOpen) await client.disconnect();
}
}, {
...GLOBAL.SERVERS.PASSWORD,
disableClientSetup: true
});
});
describe('authentication', () => {
testUtils.testWithClient('Client should be authenticated', async client => {
assert.equal(

View File

@@ -426,10 +426,11 @@ export default class RedisClient<
});
}
connect(): Promise<void> {
async connect() {
// see comment in constructor
this.#isolationPool ??= this.#initiateIsolationPool();
return this.#socket.connect();
await this.#socket.connect();
return this as unknown as RedisClientType<M, F, S>;
}
async commandsExecutor<C extends RedisCommand>(