Azure Redis,如何使用 Microsoft Azure 管理库 (MAML) 在 .NET 中进行扩展
Azure Redis, How to scale in .NET, using the Microsoft Azure Management Libraries (MAML)
谁能给出使用 Microsoft Azure 管理库 (MAML) 扩展 Redis 缓存服务的示例?
我必须使用旧版本 Microsoft.Azure.Management.Redis.dll,v0.9.0.0,因此 RedisManagementClient 不接收令牌,而只接收凭据。在这种情况下出现异常
"AuthenticationFailed: Authentication failed. The 'Authorization'
header is missing."
这是我使用的代码:
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);
}
To scale your Azure Redis Cache instances using the Microsoft Azure
Management Libraries (MAML), call the
IRedisOperations.CreateOrUpdate method and pass in the new size for
the 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);
}
For more information, see the Manage Redis Cache using MAML
sample.
I must use older version Microsoft.Azure.Management.Redis.dll, v0.9.0.0, and so the RedisManagementClient do not receive token, but only credentials.
据我所知,名为Microsoft.Azure.*
的库用于调用ARM REST API with TokenCloudCredentials, while Microsoft.WindowsAzure.*
could work with 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);
注:
为了生成令牌,您可以重复使用 here 中的 GetAuthorizationHeader
函数。
设置您的应用以使用 Active Directory 验证 Azure 资源管理器
你需要set up an AD application and assign role (Contributor) to your application to manage your Redis Cache via MAML. For more details, you could refer to this official tutorial.
更新
这是我的 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>
结果:
谁能给出使用 Microsoft Azure 管理库 (MAML) 扩展 Redis 缓存服务的示例?
我必须使用旧版本 Microsoft.Azure.Management.Redis.dll,v0.9.0.0,因此 RedisManagementClient 不接收令牌,而只接收凭据。在这种情况下出现异常
"AuthenticationFailed: Authentication failed. The 'Authorization' header is missing."
这是我使用的代码:
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);
}
To scale your Azure Redis Cache instances using the Microsoft Azure Management Libraries (MAML), call the IRedisOperations.CreateOrUpdate method and pass in the new size for the 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);
}
For more information, see the Manage Redis Cache using MAML sample.
I must use older version Microsoft.Azure.Management.Redis.dll, v0.9.0.0, and so the RedisManagementClient do not receive token, but only credentials.
据我所知,名为Microsoft.Azure.*
的库用于调用ARM REST API with TokenCloudCredentials, while Microsoft.WindowsAzure.*
could work with 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);
注:
为了生成令牌,您可以重复使用 here 中的
GetAuthorizationHeader
函数。设置您的应用以使用 Active Directory 验证 Azure 资源管理器
你需要set up an AD application and assign role (Contributor) to your application to manage your Redis Cache via MAML. For more details, you could refer to this official tutorial.
更新
这是我的 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>
结果: