【问题标题】:Azure Redis, How to scale in .NET, using the Microsoft Azure Management Libraries (MAML)Azure Redis,如何在 .NET 中扩展,使用 Microsoft Azure 管理库 (MAML)
【发布时间】:2017-02-01 10:31:44
【问题描述】:

谁能举例说明使用 Microsoft Azure 管理库 (MAML) 来扩展 Redis 缓存服务?

我必须使用旧版本的 Microsoft.Azure.Management.Redis.dll、v0.9.0.0,因此 RedisManagementClient 不接收令牌,而只接收凭据。这种情况会出现异常

"AuthenticationFailed: 身份验证失败。'Authorization' 标题丢失。”

这是我正在使用的代码:

  public static void ScaleRedis(eSubscriptionType subscriptionType)
    {

            RedisManagementClient client = new RedisManagementClient(AzureCredentials.GetCredentials(subscriptionType));


            var redisParams = new RedisCreateOrUpdateParameters()
            {
                Properties = new RedisProperties(version, new Sku(redisSKUName, redisSKUFamily, redisSKUCapacity), false),
                Location = redisCacheRegion
            };
            client.Redis.CreateOrUpdate(resourceGroupName, cacheName, redisParams);


    }

【问题讨论】:

  • 我已经更新了我的回复。有任何问题,请告诉我。
  • 这似乎是正确的答案,只有与 AD 的关系对我们来说是新的,现在我们尝试获取 clientId 和tenentId,当我们管理时,我会将其标记为最佳答案。我在代码中看到了 Redis 访问密钥的链接,但是访问密钥的使用在哪里?
  • access-keys 结合端点用作连接字符串,当您将 Azure Redis 缓存与客户端库(例如 StackExchange.Redis)连接时,您可以参考此 tutorial
  • 由于您使用 MAML 来管理(创建/更新)您的 Azure Redis 缓存,因此与 access-keys 没有任何关系。您只需要按照我的笔记中的资源来创建您的广告应用程序并检索令牌。有任何问题,请告诉我。

标签: azure redis azure-sdk-.net azure-redis-cache


【解决方案1】:

我必须使用旧版本 Microsoft.Azure.Management.Redis.dll、v0.9.0.0,因此 RedisManagementClient 不接收令牌,而只接收凭据。

据我所知,名为Microsoft.Azure.* 的库用于使用TokenCloudCredentials 调用ARM REST API,而Microsoft.WindowsAzure.* 可以使用CertificateCloudCredentials

如果您使用带有CertificateCloudCredentials 的 MAML 来管理 Redis 缓存,您将收到以下错误消息:

AuthenticationFailed: Authentication failed. The 'Authorization' header is missing.

利用Fiddler,可以发现详细错误如下:

考虑到您使用的是Microsoft.Azure.Management.Redis.dll (v0.9.0),用于管理 Redis 缓存的代码如下所示:

TokenCloudCredentials tokenCredential = new TokenCloudCredentials("{your-subscriptionId}", "{token}");
RedisManagementClient client = new RedisManagementClient(tokenCredential);
var redisParams = new RedisCreateOrUpdateParameters()
{
    Properties = new RedisProperties(version, new Sku(redisSKUName, redisSKUFamily, redisSKUCapacity)),
    Location = redisCacheRegion
};
client.Redis.CreateOrUpdate(resourceGroupName, cacheName, redisParams);

注意:

更新

这是我的packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Azure.Management.Redis" version="0.9.0-preview" targetFramework="net45" />
  <package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
  <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
  <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
  <package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.13.8" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Common" version="1.3.0" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.0" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
</packages>

结果:

【讨论】:

    【解决方案2】:

    要使用 Microsoft Azure Management Libraries (MAML) 扩展您的 Azure Redis 缓存实例,请调用 IRedisOperations.CreateOrUpdate 方法并传入新的大小 RedisProperties.SKU.Capacity

    static void Main(string[] args)
    {
        // For instructions on getting the access token, see
        // https://azure.microsoft.com/documentation/articles/cache-configure/#access-keys
        string token = GetAuthorizationHeader();
    
        TokenCloudCredentials creds = new TokenCloudCredentials(subscriptionId,token);
    
        RedisManagementClient client = new RedisManagementClient(creds);
        var redisProperties = new RedisProperties();
    
        // To scale, set a new size for the redisSKUCapacity parameter.
        redisProperties.Sku = new Sku(redisSKUName,redisSKUFamily,redisSKUCapacity);
        redisProperties.RedisVersion = redisVersion;
        var redisParams = new RedisCreateOrUpdateParameters(redisProperties, redisCacheRegion);
        client.Redis.CreateOrUpdate(resourceGroupName,cacheName, redisParams);
    }
    

    有关详细信息,请参阅Manage Redis Cache using MAML sample

    来源:How to Scale Azure Redis Cache # Scale using MAML

    【讨论】:

    • 我在问题中添加了更多信息,以便更具体地了解我正在使用的版本。
    • 您的 Redis 缓存是使用 Azure 资源管理器还是 Azure 服务管理创建的?您的 nuget 版本是 2014 年发布的,太旧,无法支持令牌身份验证。
    猜你喜欢
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 2020-10-05
    相关资源
    最近更新 更多