標籤:
如果還沒有配置Azure Power shell 可以參照這裡進行配置:
http://blog.csdn.net/lan_liang/article/details/46850221
開啟Azure Power Shell
1. 運行
Add-AzureAccount
(如果已經添加就不用了)
2. 運行
New-AzureManagedCache -Name mycache -Location "South Central US" -Sku Basic -Memory 128MB
進到Azure Cache頁面,可以看到Cache正在建立
3. 進入https://portal.azure.com/#create/Microsoft.Cache.1.0.4建立Cache
4. 點擊菜單Redis Caches 可以看到redis已經建立好了:
5. 安裝nuget package
6. Console Application的代碼:
static void Main(string[] args) { ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("your_domain.redis.cache.windows.net,ssl=true,password=YourPrimaryKey"); IDatabase cache = connection.GetDatabase(); // Perform cache operations using the cache object... // Simple put of integral data types into the cache cache.StringSet("key1", "value"); cache.StringSet("key2", 25); // Simple get of data types from the cache string key1 = cache.StringGet("key1"); Console.WriteLine(key1); int key2 = (int)cache.StringGet("key2"); Console.WriteLine(key2); Console.Read(); }
PrimaryKey在這裡看:
將代碼中的"your_domain"替換為你的DNS,password替換為你的PrimaryKey
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
Windows Azure 系列-- Azure Redis Cache的配置和使用