Skip to content

Commit

Permalink
Merge 10b411e into 294cbf8
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscop committed Aug 29, 2023
2 parents 294cbf8 + 10b411e commit b4b5fa8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
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 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(
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

0 comments on commit b4b5fa8

Please sign in to comment.