Azure Cache for Redis Cheatsheets
Azure Cache for Redis Cheatsheets
By Saeed Salehi
3 min read
- Authors
- Name
- Saeed Salehi
- linkedinSaeed Salehi
- twitter@1saeedsalehi
- Github
- github1saeedsalehi
- Website
- websiteBlog
Part of series
Developing Solutions for Microsoft Azure (AZ-204) certification exam Cheatsheets
- Part 1:
Introduction to (AZ-204) certification exam Cheatsheets
- Part 2:
Implement IaaS in Azure Cheatsheets
- Part 3:
Azure Functions Cheatsheets
- Part 4:
Azure App Service Cheatsheets
- Part 5:
Develop solutions that use Blob storage Cheatsheets
- Part 6:
Develop solutions that use Azure Cosmos DB Cheatsheets
- Part 7:
Implement Azure Security Cheatsheet
- Part 8:
Microsoft Identity platform Cheatsheet
- Part 9:
Monitoring And logging in Azure Cheatsheets
- Part 10:
Azure Cache for Redis Cheatsheets
- Part 11:
Develop message-based solutions Cheatsheets
- Part 12:
Develop event-based solutions Cheatsheets
- Part 13:
API Management in Azure Cheatsheets
Common patterns:
- Data cache
- Content cache
- Session store
- Job and message queuing
- Distributed transactions
Service tiers
- Basic: OSS Redis cache running on a single VM.
- Standard: OSS Redis cache running on two VMs in a replicated configuration.
- Premium: High-performance OSS Redis caches.
- Enterprise: Redis Enterprise software. This tier supports Redis modules including RediSearch, RedisBloom, and RedisTimeSeries.
- Enterprise Flash: Cost-effective large caches powered by Redis Labs' Redis Enterprise software (it reduces the overall per-GB memory cost.).
Pricing tier
- Basic: Basic cache ideal for development/testing. Is limited to a single server, 53 GB of memory, and 20,000 connections. There is no SLA for this service tier.
- Standard: Production cache which supports replication and includes an SLA. It supports two servers, and has the same memory/connection limits as the Basic tier.
- Premium: (Virtual Network support, Clustering support) Enterprise tier which builds on the Standard tier and includes persistence, clustering, and scale-out cache support. This is the highest performing tier with up to 530 GB of memory and 40,000 simultaneous connections. Data persistence:
- RDB persistence takes a periodic snapshot.
- AOF persistence saves every write operation to a log that is saved at least once per second.
Accessing the Redis instance
common Commands:
ping
set [key] [value]
get [key]
exists [key]
type [key]
incr [key]
incrby [key] [amount]
del [key]
flushdb
Create an Azure Cache for Redis instance
az redis create --location <myLocation> \
--resource-group az204-redis-rg \
--name $redisName \
--sku Basic --vm-size c0
Sample Clieny with C#
static async Task Main(string[] args)
{
// The connection to the Azure Cache for Redis is managed by the ConnectionMultiplexer class.
using (var cache = ConnectionMultiplexer.Connect(connectionString))
{
IDatabase db = cache.GetDatabase();
// Snippet below executes a PING to test the server connection
var result = await db.ExecuteAsync("ping");
Console.WriteLine($"PING = {result.Type} : {result}");
// Call StringSetAsync on the IDatabase object to set the key "test:key" to the value "100"
bool setValue = await db.StringSetAsync("test:key", "100");
Console.WriteLine($"SET: {setValue}");
// StringGetAsync takes the key to retrieve and return the value
string getValue = await db.StringGetAsync("test:key");
Console.WriteLine($"GET: {getValue}");
}
}
Develop for storage on CDNs
Limitations:
- The number of CDN profiles that can be created.
- The number of endpoints that can be created in a CDN profile.
- The number of custom domains that can be mapped to an endpoint.
caching behavior
- Caching rules. Caching rules can be either global (apply to all content from a specified endpoint) or custom. Custom rules apply to specific paths and file extensions.
- Query string caching. Query string caching enables you to configure how Azure CDN responds to a query string. Query string caching has no effect on files that can't be cached.
Caching rules
- Ignore query strings. This option is the default mode. A CDN POP simply passes the request and any query strings directly to the origin server on the first request and caches the asset. New requests for the same asset will ignore any query strings until the TTL expires.
- Bypass caching for query strings. Each query request from the client is passed directly to the origin server with no caching.
- Cache every unique URL. Every time a requesting client generates a unique URL, that URL is passed back to the origin server and the response cached with its own TTL. This final method is inefficient where each request is a unique URL, as the cache-hit ratio becomes low.
Caching and time to live
Default TTL values are as follows:
- Generalized web delivery optimizations: seven days
- Large file optimizations: one day
- Media streaming optimizations: one year
purge content
You can purge content in several ways.
- On an endpoint by endpoint basis
- Specify a file, by including the path to that file
- Based on wildcards (*) or using the root (/)
using Azure CLI
az cdn endpoint purge \
--content-paths '/css/*' '/js/app.js' \
--name ContosoEndpoint \
--profile-name DemoProfile \
--resource-group ExampleGroup
prepopulating cahce
az cdn endpoint load \
--content-paths '/img/*' '/js/module.js' \
--name ContosoEndpoint \
--profile-name DemoProfile \
--resource-group ExampleGroup
Azure Content Delivery Networks by using .NET
// Create CDN client
CdnManagementClient cdn = new CdnManagementClient(new TokenCredentials(authResult.AccessToken))
{ SubscriptionId = subscriptionId };
List CDN profiles and endpoints
private static void ListProfilesAndEndpoints(CdnManagementClient cdn)
{
// List all the CDN profiles in this resource group
var profileList = cdn.Profiles.ListByResourceGroup(resourceGroupName);
foreach (Profile p in profileList)
{
Console.WriteLine("CDN profile {0}", p.Name);
if (p.Name.Equals(profileName, StringComparison.OrdinalIgnoreCase))
{
// Hey, that's the name of the CDN profile we want to create!
profileAlreadyExists = true;
}
//List all the CDN endpoints on this CDN profile
Console.WriteLine("Endpoints:");
var endpointList = cdn.Endpoints.ListByProfile(p.Name, resourceGroupName);
foreach (Endpoint e in endpointList)
{
Console.WriteLine("-{0} ({1})", e.Name, e.HostName);
if (e.Name.Equals(endpointName, StringComparison.OrdinalIgnoreCase))
{
// The unique endpoint name already exists.
endpointAlreadyExists = true;
}
}
Console.WriteLine();
}
}
Create CDN profiles and endpoints
//Create the new profile
ProfileCreateParameters profileParms =
new ProfileCreateParameters() { Location = resourceLocation, Sku = new Sku(SkuName.StandardVerizon) };
cdn.Profiles.Create(profileName, profileParms, resourceGroupName);
create an endpoint
private static void CreateCdnEndpoint(CdnManagementClient cdn)
{
if (endpointAlreadyExists)
{
//Check to see if the endpoint already exists
}
else
{
//Create the new endpoint
EndpointCreateParameters endpointParms =
new EndpointCreateParameters()
{
Origins = new List<DeepCreatedOrigin>() { new DeepCreatedOrigin("Contoso", "www.contoso.com") },
IsHttpAllowed = true,
IsHttpsAllowed = true,
Location = resourceLocation
};
cdn.Endpoints.Create(endpointName, endpointParms, profileName, resourceGroupName);
}
}
Purge an endpoint
cdn.Endpoints.PurgeContent(resourceGroupName, profileName, endpointName, new List<string>() { "/*" });
Upcoming events
The Test Automation Meetup
PLEASE RSVP SO THAT WE KNOW HOW MUCH FOOD WE WILL NEED Test automation is a cornerstone of effective software development. It's about creating robust, predictable test suites that enhance quality and reliability. By diving into automation, you're architecting systems that ensure consistency and catch issues early. This expertise not only improves the development process but also broadens your skillset, making you a more versatile team member. Whether you're a developer looking to enhance your testing skills or a QA professional aiming to dive deeper into automation, RSVP for an evening of learning, delicious food, and the fusion of coding and quality assurance! 🚀🚀 18:00 – 🚪 Doors open to the public 18:15 – 🍕 Let’s eat 19:00 – 📢 First round of Talks 19:45 – 🍹 Small break 20:00 – 📢 Second round of Talks 20:45 – 🙋♀️ drinks 21:00 – 🍻 See you next time? First Round of Talks: The Power of Cross-browser Component Testing - Clarke Verdel, SR. Front-end Developer at iO How can you use Component Testing to ensure consistency cross-browser? Second Round of Talks: Omg who wrote this **** code!? - Erwin Heitzman, SR. Test Automation Engineer at Rabobank How can tests help you and your team? Beyond the Unit Test - Christian Würthner, SR. Android Developer at iO How can you do advanced automated testing for, for instance, biometrics? RSVP now to secure your spot, and let's explore the fascinating world of test automation together!
| Coven of Wisdom - Amsterdam
Go to page for The Test Automation MeetupCoven of Wisdom - Herentals - Winter `24 edition
Worstelen jij en je team met automated testing en performance? Kom naar onze meetup waar ervaren sprekers hun inzichten en ervaringen delen over het bouwen van robuuste en efficiënte applicaties. Schrijf je in voor een avond vol kennis, heerlijk eten en een mix van creativiteit en technologie! 🚀 18:00 – 🚪 Deuren open 18:15 – 🍕 Food & drinks 19:00 – 📢 Talk 1 20:00 – 🍹 Kleine pauze 20:15 – 📢 Talk 2 21:00 – 🙋♀️ Drinks 22:00 – 🍻 Tot de volgende keer? Tijdens deze meetup gaan we dieper in op automated testing en performance. Onze sprekers delen heel wat praktische inzichten en ervaringen. Ze vertellen je hoe je effectieve geautomatiseerde tests kunt schrijven en onderhouden, en hoe je de prestaties van je applicatie kunt optimaliseren. Houd onze updates in de gaten voor meer informatie over de sprekers en hun specifieke onderwerpen. Over iO Wij zijn iO: een groeiend team van experts die end-to-end-diensten aanbieden voor communicatie en digitale transformatie. We denken groot en werken lokaal. Aan strategie, creatie, content, marketing en technologie. In nauwe samenwerking met onze klanten om hun merken te versterken, hun digitale systemen te verbeteren en hun toekomstbestendige groei veilig te stellen. We helpen klanten niet alleen hun zakelijke doelen te bereiken. Samen verkennen en benutten we de eindeloze mogelijkheden die markten in constante verandering bieden. De springplank voor die visie is talent. Onze campus is onze broedplaats voor innovatie, die een omgeving creëert die talent de ruimte en stimulans geeft die het nodig heeft om te ontkiemen, te ontwikkelen en te floreren. Want werken aan de infinite opportunities van morgen, dat doen we vandaag.
| Coven of Wisdom Herentals
Go to page for Coven of Wisdom - Herentals - Winter `24 editionMastering Event-Driven Design
PLEASE RSVP SO THAT WE KNOW HOW MUCH FOOD WE WILL NEED Are you and your team struggling with event-driven microservices? Join us for a meetup with Mehmet Akif Tütüncü, a senior software engineer, who has given multiple great talks so far and Allard Buijze founder of CTO and founder of AxonIQ, who built the fundaments of the Axon Framework. RSVP for an evening of learning, delicious food, and the fusion of creativity and tech! 🚀 18:00 – 🚪 Doors open to the public 18:15 – 🍕 Let’s eat 19:00 – 📢 Getting Your Axe On Event Sourcing with Axon Framework 20:00 – 🍹 Small break 20:15 – 📢 Event-Driven Microservices - Beyond the Fairy Tale 21:00 – 🙋♀️ drinks 22:00 – 🍻 See you next time? Details: Getting Your Axe On - Event Sourcing with Axon Framework In this presentation, we will explore the basics of event-driven architecture using Axon Framework. We'll start by explaining key concepts such as Event Sourcing and Command Query Responsibility Segregation (CQRS), and how they can improve the scalability and maintainability of modern applications. You will learn what Axon Framework is, how it simplifies implementing these patterns, and see hands-on examples of setting up a project with Axon Framework and Spring Boot. Whether you are new to these concepts or looking to understand them more, this session will provide practical insights and tools to help you build resilient and efficient applications. Event-Driven Microservices - Beyond the Fairy Tale Our applications need to be faster, better, bigger, smarter, and more enjoyable to meet our demanding end-users needs. In recent years, the way we build, run, and operate our software has changed significantly. We use scalable platforms to deploy and manage our applications. Instead of big monolithic deployment applications, we now deploy small, functionally consistent components as microservices. Problem. Solved. Right? Unfortunately, for most of us, microservices, and especially their event-driven variants, do not deliver on the beautiful, fairy-tale-like promises that surround them.In this session, Allard will share a different take on microservices. We will see that not much has changed in how we build software, which is why so many “microservices projects” fail nowadays. What lessons can we learn from concepts like DDD, CQRS, and Event Sourcing to help manage the complexity of our systems? He will also show how message-driven communication allows us to focus on finding the boundaries of functionally cohesive components, which we can evolve into microservices should the need arise.
| Coven of Wisdom - Utrecht
Go to page for Mastering Event-Driven Design