Test Read and Write Access to Cache
Start course

This course provides an overview of Redis Cache and how to create a Redis Cache instance in Azure. With Redis Cache deployed in Azure, we’ll then connect an application to the cache.
Next, we’ll walk through the process of storing and retrieving data in Redis Cache. After covering Redis Cache, we’ll walk through an overview of what CDN is and what it’s used for. We’ll then develop some code for leveraging CDN. As we wrap up the course, we’ll cover the process for invalidating data in both Redis Cache and in a CDN.

Intended Audience

This course is intended for IT professionals who are interested in earning Azure certification and those who need to incorporate Redis Cache or CDN into their solutions. To get the most from this course, you should have at least a moderate understanding of what caching is and why it’s used.

Learning Objectives

By the end of this course, you should have a good understanding of what Redis Cache and CDN are and what purposes they serve. You’ll also know how to connect to each from applications and how to purge or invalidate data in both.


- What we're going to do here is create a basic Python script or application in Visual Studio. What this script is going to do is connect to the cache, set a message into the cache, and then retrieve it and display it. 

To create our new project in Visual Studio, you can go up here and click file and then new project. We're going to select a Python application and we'll call it my Python app. We'll leave it in the default location and what this does is open an editor window. Now what I'm going to do is I'm going to copy some of the lines for this code into the window rather than just type everything out. Essentially what we're going to do is import the redis and then we're going to set two variables. The redis host name and the access key. The host name is the FQDN of the cache that we configured in Azure and the access key is the access key to access it. 

What we'll do is we'll open a connection to the cache we'll ping it to confirm it's accessible and then we'll set a message, confirm that the message was set and then we'll access and display that message. I'm going to start here by importing redis and then I'm going to pull in my two variables the redis host name is the FQDN of my cache and the access key is the key to access that cache. What I'm going to do now is open up the connection to the cache on port 6380 and then what I'm going to here is ping the cache we'll do the ping store it in result and then print the result so we can see it. What we'll then do is set a message in our cache we're essentially setting a string here in a message that says hi Tom. 

Python can access the cache and then what we're going to do is we'll print that result out and then what we'll do here I have one more command or two more commands I wanna paste in here and after we've set that message, what we're going to do is retrieve that message and display it. 

So what this simple little Python script does is verify that we can connect to the cache that we can ping the cache, that we can set data to the cache, and that we can retrieve data from the cache. So to run our little test Python application here, we can simply click debug and then start without debugging. And the basic feedback we get is that the ping returns a true statement so we were in fact able to ping the cache. We were able to set the message in the cache which means we can store data in it, and then we were able to retrieve that data which is represented by the message that's returned, Hi Tom, Python can access the cache. So we'll hit enter to continue and exit back out. 

So what we've done with 10 lines of code is confirm that we can connect to our cache and at the same time we've also demonstrated that we can store data in that cache as well as retrieve that data.

About the Author
Learning Paths

Tom is a 25+ year veteran of the IT industry, having worked in environments as large as 40k seats and as small as 50 seats. Throughout the course of a long an interesting career, he has built an in-depth skillset that spans numerous IT disciplines. Tom has designed and architected small, large, and global IT solutions.

In addition to the Cloud Platform and Infrastructure MCSE certification, Tom also carries several other Microsoft certifications. His ability to see things from a strategic perspective allows Tom to architect solutions that closely align with business needs.

In his spare time, Tom enjoys camping, fishing, and playing poker.