如果还没有配置Azure Power shell 可以参照这里进行配置:
http://blog.csdn.net/lan_liang/article/details/46850221
打开Azure Power Shell
- 运行
1
2 1Add-AzureAccount
2
1
2 1 (如果已经添加就不用了)
2
- 运行
1
2 1New-AzureManagedCache -Name mycache -Location "South Central US" -Sku Basic -Memory 128MB
2
1
2 1进到Azure Cache页面,可以看到Cache正在创建
2
-
进入https://portal.azure.com/\#create/Microsoft.Cache.1.0.4创建Cache
-
点击菜单Redis Caches 可以看到redis已经创建好了:
-
安装nuget package
-
Console Application的代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 1static void Main(string[] args)
2 {
3 ConnectionMultiplexer connection =
4ConnectionMultiplexer.Connect("your_domain.redis.cache.windows.net,ssl=true,password=YourPrimaryKey");
5
6 IDatabase cache = connection.GetDatabase();
7
8 // Perform cache operations using the cache object...
9 // Simple put of integral data types into the cache
10 cache.StringSet("key1", "value");
11 cache.StringSet("key2", 25);
12
13 // Simple get of data types from the cache
14 string key1 = cache.StringGet("key1");
15 Console.WriteLine(key1);
16 int key2 = (int)cache.StringGet("key2");
17 Console.WriteLine(key2);
18
19 Console.Read();
20 }
21
1
2 1PrimaryKey在这里看:
2
将代码中的"your_domain"替换为你的DNS,password替换为你的PrimaryKey