Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 13 additions & 0 deletions packages/client/lib/client/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ describe('Client', () => {
});
});

describe('connect', () => {
testUtils.testWithClient('connect should return the clietn instance', async client => {
try {
assert.equal(await client.connect(), client);
} finally {
if (client.isOpen) await client.disconnect();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much cleaner test, thanks for the update!

}, {
...GLOBAL.SERVERS.PASSWORD,
disableClientSetup: true
});
});

describe('authentication', () => {
testUtils.testWithClient('Client should be authenticated', async client => {
assert.equal(
Expand Down
5 changes: 3 additions & 2 deletions packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down