1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-01 16:46:54 +03:00

simplify example (#2072)

top level await is supported in modules
This commit is contained in:
Mikael Finstad
2022-04-25 13:54:59 -07:00
committed by GitHub
parent 432a7e3ebb
commit 1e51680205

View File

@ -36,16 +36,14 @@ npm install redis
```typescript
import { createClient } from 'redis';
(async () => {
const client = createClient();
const client = createClient();
client.on('error', (err) => console.log('Redis Client Error', err));
client.on('error', (err) => console.log('Redis Client Error', err));
await client.connect();
await client.connect();
await client.set('key', 'value');
const value = await client.get('key');
})();
await client.set('key', 'value');
const value = await client.get('key');
```
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]`: