Skip to content

Commit 1e51680

Browse files
authored
simplify example (#2072)
top level await is supported in modules
1 parent 432a7e3 commit 1e51680

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ npm install redis
3636
```typescript
3737
import { createClient } from 'redis';
3838

39-
(async () => {
40-
const client = createClient();
39+
const client = createClient();
4140

42-
client.on('error', (err) => console.log('Redis Client Error', err));
41+
client.on('error', (err) => console.log('Redis Client Error', err));
4342

44-
await client.connect();
43+
await client.connect();
4544

46-
await client.set('key', 'value');
47-
const value = await client.get('key');
48-
})();
45+
await client.set('key', 'value');
46+
const value = await client.get('key');
4947
```
5048

5149
The above code connects to localhost on port 6379. To connect to a different host or port, use a connection string in the format `redis[s]://[[username][:password]@][host][:port][/db-number]`:

0 commit comments

Comments
 (0)