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
@@ -17,14 +17,121 @@ In this quickstart, you incorporate Azure Cache for Redis into a Node.js app to
17
17
## Prerequisites
18
18
19
19
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
20
-
-[node_redis](https://github.com/mranney/node_redis), which you can install with the command `npm install redis`.
21
-
22
-
For examples of using other Node.js clients, see the individual documentation for the Node.js clients listed at [Node.js Redis clients](https://redis.io/docs/connect/clients/nodejs/).
20
+
- Node.js installed, if you haven't done so already. See [Install Node.js on Windows](../../windows/dev-environment/javascript/nodejs-on-windows) for instructions on how to install Node and NPM on a Windows machine.
The [node-redis](https://github.com/redis/node-redis) library is the primary Node.js client for Redis. You can install the client with [npm](https://docs.npmjs.com/about-npm) by using the following command:
## Enable Microsoft EntraID and add a User or Service Principal
36
+
<--Fran, we probably need an include file on enabling EntraID-->
37
+
Blah blah blah, do the steps listed [here](cache-azure-active-directory-for-authentication)
38
+
39
+
## Install the JavaScript Azure Identity client library
40
+
The [Microsoft Authentication Library (MSAL)](../../entra/identity-platform/msal-overview) allows you to acquire security tokens from Microsoft identity to authenticate users. There's a [Javascript Azure identity client library](../../javascript/api/overview/azure/identity-readme) available that uses MSAL to provide token authentication support. Install this library using `npm`:
41
+
42
+
```bash
43
+
npm install @azure/identity
44
+
```
45
+
46
+
## Create a new Node.js app
47
+
48
+
1. Create a new script file named *redistest.js*.
49
+
1. Add the following example JavaScript to the file.
This code shows you how to connect to an Azure Cache for Redis instance using the cache host name and key environment variables. The code also stores and retrieves a string value in the cache. The `PING` and `CLIENT LIST` commands are also executed. For more examples of using Redis with the [node-redis](https://github.com/redis/node-redis) client, see [https://redis.js.org/](https://redis.js.org/).
105
+
106
+
1. Run the script with Node.js.
107
+
108
+
```bash
109
+
node redistest.js
110
+
```
111
+
112
+
1. Example the output.
113
+
114
+
```console
115
+
Cache command: PING
116
+
Cache response : PONG
117
+
118
+
Cache command: GET Message
119
+
Cache response : Hello! The cache is working from Node.js!
120
+
121
+
Cache command: SET Message
122
+
Cache response : OK
123
+
124
+
Cache command: GET Message
125
+
Cache response : Hello! The cache is working from Node.js!
Add environment variables foryour **HOST NAME** and **Primary** access key. Use these variables from your code instead of including the sensitive information directlyin your code.
@@ -36,17 +143,13 @@ set AZURE_CACHE_FOR_REDIS_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
36
143
37
144
## Connect to the cache
38
145
39
-
The latest builds of [node_redis](https://github.com/mranney/node_redis) provide support several connection options. Don't create a new connection for each operation in your code. Instead, reuse connections as much as possible.
146
+
>[!NOTE]
147
+
> Don't create a new connection for each operation in your code. Instead, reuse connections as much as possible.
148
+
>
40
149
41
150
## Create a new Node.js app
42
151
43
152
1. Create a new script file named *redistest.js*.
44
-
1. Use the command to install a redis package.
45
-
46
-
```bash
47
-
`npm install redis`
48
-
```
49
-
50
153
1. Add the following example JavaScript to the file.
51
154
52
155
```javascript
@@ -101,7 +204,7 @@ The latest builds of [node_redis](https://github.com/mranney/node_redis) provide
This code shows you how to connect to an Azure Cache forRedis instance using the cache host name and key environment variables. The code also stores and retrieves a string valuein the cache. The `PING` and `CLIENT LIST` commands are also executed. For more examples of using Redis with the [node_redis](https://github.com/mranney/node_redis) client, see [https://redis.js.org/](https://redis.js.org/).
207
+
This code shows you how to connect to an Azure Cache for Redis instance using the cache host name and key environment variables. The code also stores and retrieves a string value in the cache. The `PING` and `CLIENT LIST` commands are also executed. For more examples of using Redis with the [node_redis](https://github.com/redis/node-redis) client, see [https://redis.js.org/](https://redis.js.org/).
105
208
106
209
1. Run the script with Node.js.
107
210
@@ -129,6 +232,7 @@ The latest builds of [node_redis](https://github.com/mranney/node_redis) provide
0 commit comments