title | description | services | documentationcenter | author | manager | editor | ms.assetid | ms.service | ms.devlang | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
How to use Azure Redis Cache with Node.js | Microsoft Docs |
Get started with Azure Redis Cache using Node.js and node_redis. |
redis-cache |
steved0x |
douge |
v-lincan |
06fddc95-8029-4a8d-83f5-ebd5016891d9 |
cache |
nodejs |
hero-article |
cache-redis |
tbd |
02/10/2017 |
sdanie |
[!div class="op_single_selector"]
Azure Redis Cache gives you access to a secure, dedicated Redis cache, managed by Microsoft. Your cache is accessible from any application within Microsoft Azure.
This topic shows you how to get started with Azure Redis Cache using Node.js. For another example of using Azure Redis Cache with Node.js, see Build a Node.js Chat Application with Socket.IO on an Azure Website.
Install node_redis:
npm install redis
This tutorial uses node_redis. For examples of using other Node.js clients, see the individual documentation for the Node.js clients listed at Node.js Redis clients.
[!INCLUDE redis-cache-create]
[!INCLUDE redis-cache-create]
The latest builds of node_redis provide support for connecting to Azure Redis Cache using SSL. The following example shows how to connect to Azure Redis Cache using the SSL endpoint of 6380. Replace <name>
with the name of your cache and <key>
with either your primary or secondary key as described in the previous Retrieve the host name and access keys section.
var redis = require("redis");
// Add your cache name and access key.
var client = redis.createClient(6380,'<name>.redis.cache.windows.net', {auth_pass: '<key>', tls: {servername: '<name>.redis.cache.windows.net'}});
Note
The non-SSL port is disabled for new Azure Redis Cache instances. If you are using a different client that doesn't support SSL, see How to enable the non-SSL port.
The following example shows you how to connect to an Azure Redis Cache instance, and store and retrieve an item from the cache. For more examples of using Redis with the node_redis client, see http://redis.js.org/.
var redis = require("redis");
// Add your cache name and access key.
var client = redis.createClient(6380,'<name>.redis.cache.windows.net', {auth_pass: '<key>', tls: {servername: '<name>.redis.cache.windows.net'}});
client.set("key1", "value", function(err, reply) {
console.log(reply);
});
client.get("key1", function(err, reply) {
console.log(reply);
});
Output:
OK
value
- Enable cache diagnostics so you can monitor the health of your cache.
- Read the official Redis documentation.