適用於 Node.js 的 Azure 快取模組Azure Redis Cache modules for Node.js

Azure Redis 快取是以常用的開放原始碼 Redis 專案作為基礎。Azure Redis Cache is based on the popular open source Redis project. 它可讓您從 Azure 應用程式存取由 Microsoft 管理的安全、專用 Redis 執行個體。It gives you access to a secure, dedicated Redis instance, managed by Microsoft and accessible from your Azure apps.

Redis 是一種進階的索引鍵值存放區,其中的索引鍵可以包含類似字串、雜湊、清單、集合和排序的集合等資料結構。Redis is an advanced key-value store, where keys can contain data structures such as strings, hashes, lists, sets, and sorted sets. Redis 針對這些資料類型支援一組不可部分完成的操作。Redis supports a set of atomic operations on these data types.

深入了解 Azure Redis 快取Learn more about Azure Redis Cache.

用戶端封裝Client package

安裝 npm 模組Install the npm module

使用 npm 來安裝適用於 Node.js 的 Redis 模組Use npm to install the Redis module for Node.js

npm install redis

範例Example

此範例會連線到 Azure Redis 快取執行個體、儲存索引鍵/值組,然後依其索引鍵讀取所儲存的值。This example connects to an Azure Redis Cache instance, stores a key/value pair and then reads the stored value by its key.

const redis = require('redis');

const client = redis.createClient(6380, '<name>.redis.cache.windows.net', {
  auth_pass: '<key>',
  tls: { servername: '<name>.redis.cache.windows.net' }
});

client.set('key1', 'value', (err, reply) => {
  console.log(reply);
});

client.get('key1', (err, reply) => {
  console.log(reply);
});

管理封裝Management package

安裝 npm 模組Install the npm module

使用 npm 來安裝適用於 Node.js 的 Azure Redis 快取模組Use npm to install the Azure Redis Cache modules for Node.js

npm install azure-arm-rediscache

範例Example

此範例會向 Azure 驗證,並列出指定之源群組中的所有 Redis 快取執行個體。This example authenticates to Azure and lists all Redis Cache instances in a specified resource group.

const msRestAzure = require('ms-rest-azure');
const AzureMgmtRedisCache = require('azure-arm-rediscache');

msRestAzure.interactiveLogin().then(credentials => {
  const client = new AzureMgmtRedisCache(credentials, 'my-subscription-id');
  client.redis.listByResourceGroup('testResourceGroup').then(result => {
    console.log(result);
  });
});

範例Samples

深入探索可在應用程式中使用的 Node.js 程式碼範例Explore more sample Node.js code you can use in your apps.