分享

Windows Azure 系列-- Azure Redis Cache的配置和使用


问题导读


1.如何配置Azure Power Shell?
2.Azure Power Shell如何添加账户?
3.New-AzureManagedCache -Name mycache -Location "South Central US" -Sku Basic -Memory 128MB命令的含义是什么?







配置Azure Power Shell

1.下载Azure Power shell
https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/#Install


7.png



2. 执行Add-AzureAccount,会提示输入Azure账号密码

8.png



3. 可以看到账号成功添加


9.png





打开Azure Power Shell

1. 运行

[mw_shl_code=bash,true]Add-AzureAccount  [/mw_shl_code]


(如果已经添加就不用了)


2. 运行


[mw_shl_code=bash,true]New-AzureManagedCache -Name mycache -Location "South Central US" -Sku Basic -Memory 128MB  [/mw_shl_code]

进到Azure Cache页面,可以看到Cache正在创建
1.png

2.png


3. 进入https://portal.azure.com/#create/Microsoft.Cache.1.0.4创建Cache

3.png



4. 点击菜单Redis Caches 可以看到redis已经创建好了:

4.png



5. 安装nuget package

5.png


6. Console Application的代码:


[mw_shl_code=bash,true]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();  
        }[/mw_shl_code]


PrimaryKey在这里看:
6.png


将代码中的"your_domain"替换为你的DNS,password替换为你的PrimaryKey


没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条