RedisCacheBuilder Class OverviewThe RedisCacheBuilder class is designed to build and configure an Azure Redis Cache instance with specific configurations such as SKU, network settings, and secrets management.
Initializes the RedisCacheBuilder with the provided arguments and sets the instance name.
const redisBuilder = new RedisCacheBuilder({
name: 'myRedisCache',
group: { resourceGroupName: 'myResourceGroup' },
// other necessary arguments
});
withSkuSets the SKU properties for the Redis Cache.
redisBuilder.withSku({
name: 'Premium',
family: 'P',
capacity: 1,
});
withNetworkSets the network properties for the Redis Cache, including subnet ID and private link settings.
redisBuilder.withNetwork({
subnetId: 'subnet-id',
privateLink: {
// private link properties
},
ipAddresses: ['192.168.1.1', '192.168.1.2'],
});
lockEnables or disables the deletion guard on the Redis Cache instance.
isPrd — production stacks are guarded without the caller asking for it; other environments are not.protect: true and an Azure CanNotDelete management lock. Without the guard, dropping the builder call from a stack — or a rename that turns the diff into a delete-then-create — destroys the cache and its data..lock(false) opts out explicitly, including in production.pulumi state unprotect and removing the Azure lock first. That is the guard doing its job, not a bug.redisBuilder.lock(); // guard the cache explicitly
redisBuilder.lock(false); // opt out, even in a production stack
buildRedisCreates the Redis Cache instance with the specified configurations.
This method is called internally by the build method and is not typically called directly.
buildNetworkConfigures network settings for the Redis Cache, including firewall rules and private link.
This method is called internally by the build method and is not typically called directly.
buildSecretsStores Redis Cache connection details in Azure Key Vault.
This method is called internally by the build method and is not typically called directly.
buildBuilds the Redis Cache instance, configures network settings, and stores secrets.
const resourceInfo = redisBuilder.build();
console.log(resourceInfo);
Here is a full example demonstrating how to use the RedisCacheBuilder class:
import RedisCacheBuilder from './Builder/RedisCacheBuilder';
import { RedisCacheBuilderArgs } from './types';
const args: RedisCacheBuilderArgs = {
name: 'myRedisCache',
group: { resourceGroupName: 'myResourceGroup' },
// other necessary arguments
};
const redisBuilder = new RedisCacheBuilder(args);
redisBuilder
.withSku({
name: 'Premium',
family: 'P',
capacity: 1,
})
.withNetwork({
subnetId: 'subnet-id',
privateLink: {
// private link properties
},
ipAddresses: ['192.168.1.1', '192.168.1.2'],
})
.lock();
const resourceInfo = redisBuilder.build();
console.log(resourceInfo);
isPrd).This guideline should help developers understand and reuse the methods in the RedisCacheBuilder class effectively.