Chuyển đến nội dung
Skillpedia
Cơ sở dữ liệu48k · #3978

azure-resource-manager-redis-dotnet

Skill này làm gì

Đoạn mã này cho phép bạn quản lý tài nguyên Azure Cache for Redis bằng .NET. Bạn có thể tạo, cập nhật, xóa bộ nhớ đệm, cấu hình quy tắc tường lửa và quản lý khóa truy cập.

Khi nào nên dùng

  • ✓Khi tạo một bộ nhớ đệm Redis mới cho ứng dụng.
  • ✓Khi thay đổi cài đặt của một bộ nhớ đệm Redis hiện có.
  • ✓Khi quản lý ai được phép truy cập bộ nhớ đệm Redis qua quy tắc tường lửa.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-resource-manager-redis-dotnet/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-resource-manager-redis-dotnet/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo một bộ nhớ đệm Redis tên “my-cache” ở khu vực “EastUS” với cài đặt mặc định.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ dùng Azure SDK cho .NET để giao tiếp với Azure Resource Manager. Bạn định nghĩa chi tiết bộ nhớ đệm trong mã, còn SDK lo việc tạo và quản lý.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Azure.ResourceManager.Redis (.NET)

Management plane SDK for provisioning and managing Azure Cache for Redis resources via Azure Resource Manager.

⚠️ Management vs Data Plane

  • This SDK (Azure.ResourceManager.Redis): Create caches, configure firewall rules, manage access keys, set up geo-replication
  • Data Plane SDK (StackExchange.Redis): Get/set keys, pub/sub, streams, Lua scripts

Installation

dotnet add package Azure.ResourceManager.Redis
dotnet add package Azure.Identity

Current Version: 1.5.1 (Stable)
API Version: 2024-11-01
Target Frameworks: .NET 8.0, .NET Standard 2.0

Environment Variables

AZURE_SUBSCRIPTION_ID=<your-subscription-id>
# For service principal auth (optional)
AZURE_TENANT_ID=<tenant-id>
AZURE_CLIENT_ID=<client-id>
AZURE_CLIENT_SECRET=<client-secret>

Authentication

using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Redis;

// Always use DefaultAzureCredential
var credential = new DefaultAzureCredential();
var armClient = new ArmClient(credential);

// Get subscription
var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
var subscription = armClient.GetSubscriptionResource(
    new ResourceIdentifier($"/subscriptions/{subscriptionId}"));

Resource Hierarchy

ArmClient
└── SubscriptionResource
    └── ResourceGroupResource
        └── RedisResource
            ├── RedisFirewallRuleResource
            ├── RedisPatchScheduleResource
            ├── RedisLinkedServerWithPropertyResource
            ├── RedisPrivateEndpointConnectionResource
            └── RedisCacheAccessPolicyResource

Core Workflows

1. Create Redis Cache

using Azure.ResourceManager.Redis;
using Azure.ResourceManager.Redis.Models;

// Get resource group
var resourceGroup = await subscription
    .GetResourceGroupAsync("my-resource-group");

// Define cache configuration
var cacheData = new RedisCreateOrUpdateContent(
    location: AzureLocation.EastUS,
    sku: new RedisSku(RedisSkuName.Standard, RedisSkuFamily.BasicOrStandard, 1))
{
    EnableNonSslPort = false,
    MinimumTlsVersion = RedisTlsVersion.Tls1_2,
    RedisConfiguration = new RedisCommonConfiguration
    {
        MaxMemoryPolicy = "volatile-lru"
    },
    Tags =
    {
        ["environment"] = "production"
    }
};

// Create cache (long-running operation)
var cacheCollection = resourceGroup.Value.GetAllRedis();
var operation = await cacheCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-redis-cache",
    cacheData);

RedisResource cache = operation.Value;
Console.WriteLine($"Cache created: {cache.Data.HostName}");

2. Get Redis Cache

// Get existing cache
var cache = await resourceGroup.Value
    .GetRedisAsync("my-redis-cache");

Console.WriteLine($"Host: {cache.Value.Data.HostName}");
Console.WriteLine($"Port: {cache.Value.Data.Port}");
Console.WriteLine($"SSL Port: {cache.Value.Data.SslPort}");
Console.WriteLine($"Provisioning State: {cache.Value.Data.ProvisioningState}");

3. Update Redis Cache

var patchData = new RedisPatch
{
    Sku = new RedisSku(RedisSkuName.Standard, RedisSkuFamily.BasicOrStandard, 2),
    RedisConfiguration = new RedisCommonConfiguration
    {
        MaxMemoryPolicy = "allkeys-lru"
    }
};

var updateOperation = await cache.Value.UpdateAsync(
    WaitUntil.Completed,
    patchData);

4. Delete Redis Cache

await cache.Value.DeleteAsync(WaitUntil.Completed);

5. Get Access Keys

var keys = await cache.Value.GetKeysAsync();
Console.WriteLine($"Primary Key: {keys.Value.PrimaryKey}");
Console.WriteLine($"Secondary Key: {keys.Value.SecondaryKey}");

6. Regenerate Access Keys

var regenerateContent = new RedisRegenerateKeyContent(RedisRegenerateKeyType.Primary);
var newKeys = await cache.Value.RegenerateKeyAsync(regenerateContent);
Console.WriteLine($"New Primary Key: {newKeys.Value.PrimaryKey}");

7. Manage Firewall Rules

// Create firewall rule
var firewallData = new RedisFirewallRuleData(
    startIP: System.Net.IPAddress.Parse("10.0.0.1"),
    endIP: System.Net.IPAddress.Parse("10.0.0.255"));

var firewallCollection = cache.Value.GetRedisFirewallRules();
var firewallOperation = await firewallCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "allow-internal-network",
    firewallData);

// List all firewall rules

…
Câu hỏi thường gặp

Khác biệt giữa đoạn mã này và StackExchange.Redis là gì?

Đoạn mã này quản lý chính *bộ nhớ đệm* (tạo, cấu hình), còn StackExchange.Redis tương tác với *dữ liệu bên trong* bộ nhớ đệm (lưu và đọc giá trị).

Tôi có cần thiết lập đặc biệt để dùng không?

Có. Bạn cần cài Azure SDK cho .NET và thiết lập thông tin xác thực Azure, như mã đăng ký (subscription ID).

Tôi có thể quản lý mọi thứ của bộ nhớ đệm Redis bằng đoạn mã này không?

Bạn có thể quản lý việc tạo, cấu hình, quy tắc tường lửa, khóa truy cập và lịch vá lỗi (cho gói Premium). Với các thao tác dữ liệu (lưu/đọc), bạn cần dùng một SDK khác.

Chi tiết

Mô tả gốc của tác giả

Azure Resource Manager SDK for Redis in .NET.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#3978
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự