page_type | languages | name | description | products | ||||
---|---|---|---|---|---|---|---|---|
sample |
|
Quickstart: Use Azure Cache for Redis in Node.js |
Learn how to incorporate Azure Cache for Redis into a Node.js app. |
|
This sample show you how to incorporate Azure Cache for Redis into a Node.js app. See the accompanying article on the documentation site for details, including best practices and how to create the sample code from scratch.
- Azure subscription - create one for free
- Azure Cache for Redis cache - create one
- node_redis, which you can install with the command
npm install redis
.
For examples of using other Node.js clients, see the individual documentation for the Node.js clients listed at Node.js Redis clients.
Add environment variables for your cache's HOST NAME and Primary access key. You will use these variables from your code instead of including the sensitive information directly in your code.
set AZURE_CACHE_FOR_REDIS_HOST_NAME=contosoCache.redis.cache.windows.net
set AZURE_CACHE_FOR_REDIS_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Download the sample code to your development PC.
Change directories to the folder containing this sample.
Run the script with Node.js.
node redistest.js