You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +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
|
```typescript
|
||||||
import { createClient } from 'redis';
|
import { createClient } from 'redis';
|
||||||
|
|
||||||
const client = createClient();
|
const client = await createClient()
|
||||||
|
.on('error', err => console.log('Redis Client Error', err))
|
||||||
client.on('error', err => console.log('Redis Client Error', err));
|
.connect();
|
||||||
|
|
||||||
await client.connect();
|
|
||||||
|
|
||||||
await client.set('key', 'value');
|
await client.set('key', 'value');
|
||||||
const value = await client.get('key');
|
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', () => {
|
describe('authentication', () => {
|
||||||
testUtils.testWithClient('Client should be authenticated', async client => {
|
testUtils.testWithClient('Client should be authenticated', async client => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
@@ -426,10 +426,11 @@ export default class RedisClient<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(): Promise<void> {
|
async connect() {
|
||||||
// see comment in constructor
|
// see comment in constructor
|
||||||
this.#isolationPool ??= this.#initiateIsolationPool();
|
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>(
|
async commandsExecutor<C extends RedisCommand>(
|
||||||
|
Reference in New Issue
Block a user