You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +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:
committed by
GitHub
parent
5a108265da
commit
fb255eb5d0
@@ -51,11 +51,9 @@ Looking for a high-level library to handle object mapping? See [redis-om-node](h
|
||||
```typescript
|
||||
import { createClient } from 'redis';
|
||||
|
||||
const client = createClient();
|
||||
|
||||
client.on('error', err => console.log('Redis Client Error', err));
|
||||
|
||||
await client.connect();
|
||||
const client = await createClient()
|
||||
.on('error', err => console.log('Redis Client Error', err))
|
||||
.connect();
|
||||
|
||||
await client.set('key', 'value');
|
||||
const value = await client.get('key');
|
||||
|
@@ -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(
|
||||
|
@@ -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>(
|
||||
|
Reference in New Issue
Block a user