Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation to match latest client initialization #211

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
24 changes: 7 additions & 17 deletions docs/stack/get-started/om-clients/stack-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,20 @@ First things first, let's set up a **client**. The `Client` class is the thing t
Let's create our first file. In the `om` folder add a file called `client.js` and add the following code:

{{< highlight javascript >}}
import { Client } from 'redis-om'

/* pulls the Redis URL from .env */
import { createClient } from 'redis'
const url = process.env.REDIS_URL

/* create and open the Redis OM Client */
const client = await new Client().open(url)

export default client
const client = createClient({
url: url
})
client.on('error', (err) => console.log('Redis Client Error', err));
await client.connect();
export default client;
{{< / highlight >}}

> Remember that _top-level await_ stuff we mentioned earlier? There it is!

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.

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:

{{< highlight javascript >}}
/* create and open the Redis OM Client */
const client = new Client()
await client.open(url)
{{< / highlight >}}


## Entity, Schema, and Repository

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:
Expand Down