You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for [JSON]({{< relref "/develop/data-types/json" >}}) data and
21
-
run queries against the index.
20
+
for [JSON]({{< relref "/develop/data-types/json" >}}) documents and
21
+
run queries against the index. It then goes on to show the slight differences
22
+
in the equivalent code for [hash]({{< relref "/develop/data-types/hashes" >}})
23
+
documents.
22
24
23
-
Make sure that you have Redis Stack and `node-redis` installed.
25
+
## Initialize
24
26
25
-
Start by importing dependencies:
27
+
Make sure that you have [Redis Community Edition]({{< relref "/operate/oss_and_stack/" >}})
28
+
or another Redis server available. Also install the
29
+
[`node-redis`]({{< relref "/develop/clients/nodejs" >}}) client library if you
30
+
haven't already done so.
31
+
32
+
Add the following dependencies:
26
33
27
34
```js
28
35
import {
@@ -33,14 +40,10 @@ import {
33
40
} from'redis';
34
41
```
35
42
36
-
Connect to the database:
37
-
38
-
```js
39
-
constclient=awaitcreateClient();
40
-
awaitclient.connect();
41
-
```
43
+
## Create data
42
44
43
-
Create some test data to add to the database:
45
+
Create some test data to add to your database. The example data shown
46
+
below is compatible with both JSON and hash objects.
44
47
45
48
```js
46
49
constuser1= {
@@ -65,6 +68,18 @@ const user3 = {
65
68
};
66
69
```
67
70
71
+
## Add the index
72
+
73
+
Connect to your Redis database. The code below shows the most
74
+
basic connection but see
75
+
[Connect to the server]({{< relref "/develop/clients/nodejs/connect" >}})
76
+
to learn more about the available connection options.
77
+
78
+
```js
79
+
constclient=awaitcreateClient();
80
+
awaitclient.connect();
81
+
```
82
+
68
83
Create an index. In this example, only JSON documents with the key prefix `user:` are indexed. For more information, see [Query syntax]({{< relref "/develop/interact/search-and-query/query/" >}}).
0 commit comments