Skip to content

Commit 8965c11

Browse files
authored
Update documentation to match latest client initialization
1 parent 84a4006 commit 8965c11

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

docs/stack/get-started/om-clients/stack-node.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,20 @@ First things first, let's set up a **client**. The `Client` class is the thing t
9595
Let's create our first file. In the `om` folder add a file called `client.js` and add the following code:
9696

9797
{{< highlight javascript >}}
98-
import { Client } from 'redis-om'
99-
100-
/* pulls the Redis URL from .env */
98+
import { createClient } from 'redis'
10199
const url = process.env.REDIS_URL
102-
103-
/* create and open the Redis OM Client */
104-
const client = await new Client().open(url)
105-
106-
export default client
100+
const client = createClient({
101+
url: url
102+
})
103+
client.on('error', (err) => console.log('Redis Client Error', err));
104+
await client.connect();
105+
export default client;
107106
{{< / highlight >}}
108107

109108
> Remember that _top-level await_ stuff we mentioned earlier? There it is!
110109
111110
Note that we are getting our Redis URL from an environment variable. It was put there by Dotenv and read from our `.env` file. If we didn't have the `.env` file or have a `REDIS_URL` property in our `.env` file, this code would gladly read this value from the *actual* environment variables.
112111

113-
Also note that the `.open()` method conveniently returns `this`. This `this` (can I say *this* again? I just did!) lets us chain the instantiation of the client with the opening of the client. If this isn't to your liking, you could always write it like this:
114-
115-
{{< highlight javascript >}}
116-
/* create and open the Redis OM Client */
117-
const client = new Client()
118-
await client.open(url)
119-
{{< / highlight >}}
120-
121-
122112
## Entity, Schema, and Repository
123113

124114
Now that we have a client that's connected to Redis, we need to start mapping some persons. To do that, we need to define an `Entity` and a `Schema`. Let's start by creating a file named `person.js` in the `om` folder and importing `client` from `client.js` and the `Entity` and `Schema` classes from Redis OM:

0 commit comments

Comments
 (0)