Notiz
Zougrëff op dës Säit erfuerdert Autorisatioun. Dir kënnt probéieren, Iech unzemellen oder Verzeechnesser ze änneren.
Zougrëff op dës Säit erfuerdert Autorisatioun. Dir kënnt probéieren, Verzeechnesser ze änneren.
This quickstart shows you how to create a simple Python app that:
- Connects to Azure Cache for Redis
- Writes the current date and time to Redis
- Reads the value back
- Prints the result to the console
You use GitHub Copilot to generate most of the code and provisioning steps.
Prerequisites
For complete setup instructions, see the Get started article. Make sure that you have the following items:
An Azure account and access to an Azure subscription. For details on how to set them up, see the pricing page for Azure accounts.
A GitHub account and a GitHub Copilot subscription. For details on how to set them up, see Creating an account on GitHub and Quickstart for GitHub Copilot, respectively.
Visual Studio Code. For details on how to download and install it, see Setting up Visual Studio Code.
The GitHub Copilot extension and the GitHub Copilot Chat extension. For instructions on how to install these extensions, see Set up GitHub Copilot in VS Code and Getting started with GitHub Copilot Chat in VS Code, respectively.
Important
GitHub Copilot is a separate subscription managed by GitHub. For questions regarding GitHub Copilot subscriptions and Support, see Getting started with a GitHub Copilot plan.
An Azure account and access to an Azure subscription. For details on how to set them up, see the pricing page for Azure accounts.
A GitHub account and a GitHub Copilot subscription. For details on how to set them up, see Creating an account on GitHub and Quickstart for GitHub Copilot, respectively.
Visual Studio 2022 (Any edition). For details on how to download and install it, see Install Visual Studio.
Important
GitHub Copilot is a separate subscription managed by GitHub. For questions regarding GitHub Copilot subscriptions and Support, see Getting started with a GitHub Copilot plan.
An Azure account and access to an Azure subscription. For details on how to set them up, see the pricing page for Azure accounts.
A GitHub account and a GitHub Copilot subscription. For details on how to set them up, see Creating an account on GitHub and Quickstart for GitHub Copilot, respectively.
Visual Studio 2026 (Any edition). For details on how to download and install it, see Install Visual Studio.
Important
GitHub Copilot is a separate subscription managed by GitHub. For questions regarding GitHub Copilot subscriptions and Support, see Getting started with a GitHub Copilot plan.
Building the app
Follow these steps described in this article:
- Create a
.envfile in your workspace to store Azure deployment information as environment variables. - Write a prompt to create an instance of Azure Cache for Redis in your subscription. The Redis connection information is also stored in the
.envfile. - Validate that the resource and the
.envfile are created correctly. - Write a prompt to create a Python app to retrieve, write, and read from the cache by using environment variables.
- Validate the app works.
- Clean up the resources in Azure.
Ensure you have the right tools selected
You must have both Azure MCP Server installed and GitHub Copilot for Azure installed.
- Select the Configure tools... icon in the chat pane.
- Configure tools is displayed in the Command Palette. Make sure the top nodes for "Azure MCP" and "GitHub Copilot for Azure" are both selected.
- Select the Select tools... icon in the chat pane.
- Select tools menu is displayed. Make sure the "Azure MCP Server" top node is selected.
- Select the Select tools icon in the chat pane.
- The Select tools menu is displayed. Make sure the top nodes for "Azure" and "Azure MCP" are both selected.
Create local environment variables
A common development practice is to store important keys and other settings as environment variables in a .env file in your workspace folder. This keeps all configuration self-contained within the project.
Important
Make sure your .gitignore file includes .env so you don't accidentally commit secrets to source control.
In this step, create a .env file in your workspace by using a prompt like the following:
Create a .env file in this workspace with the following environment variables filled in:
AZURE_SUBSCRIPTION_ID
AZURE_TENANT_ID
AZURE_LOCATION
AZURE_RESOURCE_GROUP
AZURE_RESOURCE_PREFIX
Use my <your-subscription-name> subscription and I want to put everything in eastus.
Replace <your-subscription-name> with the name of your Azure subscription. Copilot looks up the subscription and tenant IDs for you, generates a resource group name and prefix, and creates the .env file.
After the file is created, open it and verify the values look correct:
AZURE_SUBSCRIPTION_ID=<your-azure-subscription-id>
AZURE_TENANT_ID=<your-azure-tenant-id>
AZURE_LOCATION=eastus
AZURE_RESOURCE_GROUP=<resource-group>
AZURE_RESOURCE_PREFIX=<resource-prefix>
Create Azure Cache for Redis
Open GitHub Copilot Chat and paste the following prompt:
You have access to Azure MCP tools.
Use the variables in the `.env` file in this workspace to create an Azure Cache for Redis instance.
Tasks:
1. Ensure the resource group exists.
2. Create Azure Cache for Redis:
- Name: {AZURE_RESOURCE_PREFIX}-redis
- SKU: Basic C0
- TLS enabled (port 6380)
3. Write the following values into the `.env` file:
REDIS_HOST
REDIS_PORT=6380
REDIS_PASSWORD (primary key)
REDIS_SSL=true
Important:
- Use Azure MCP to create resources and fetch keys.
Copilot creates the Redis resource, and then creates a .env file containing the hostname, primary key, and the other environment variables.
Validate that the .env file has the Redis settings
Open the
.envfile in your project folder and validate that it has values.REDIS_HOST=<your-cache-name>.redis.cache.windows.net REDIS_PORT=6380 REDIS_PASSWORD=<primary-key> REDIS_SSL=trueValidate that the Azure Cache for Redis instance is running by using the following prompt.
Use the values in the `.env` file in this workspace to validate that an instance of Azure Cache for Redis is running and ready to be used.
Prompt to write the Python app
Use the following prompt to create the Python app that writes and reads from the new instance of Azure Cache for Redis.
Create a minimal Python console app in this workspace.
Important:
- Do ALL work directly by editing files.
- Do NOT ask me to copy/paste code.
- Create files if they do not exist.
Goal:
Build a simple app that writes the current date/time to Azure Cache for Redis, reads it back, and prints results to the console.
Project requirements:
1. Create or update these files:
- main.py
- requirements.txt
- .gitignore
2. requirements.txt must include:
- redis
- python-dotenv
3. .gitignore must include:
- .venv/
- __pycache__/
- .env
4. main.py must:
- Load environment variables using python-dotenv
- Read:
REDIS_HOST
REDIS_PORT
REDIS_PASSWORD
REDIS_SSL
- Connect to Azure Cache for Redis using TLS (ssl=True when REDIS_SSL=true)
- Use decode_responses=True
- Test connection with PING and print:
Connected to Redis
- Write current datetime (ISO format) to key:
demo:timestamp
- Read the value back
- Print exactly:
WROTE: <value>
READ : <value>
- Wrap connection logic in a try/except and print a helpful error message.
5. Keep the code simple and beginner-friendly:
- Single file
- No classes
- About 40–60 lines
After editing the files:
- Show a summary of what you changed.
- Do NOT print the full file contents unless I ask.
Validate the Python app
Make sure the files you requested in the prompt exist. Visually inspect the files to see if they have values that seem reasonable.
Inspect the
main.pyfile to ensure that it retrieves values from the.envfile, imports theredispackage, and connects to Azure Cache for Redis. Check that it writes and reads the cache. You might see code that resembles the following code:import os from datetime import datetime from dotenv import load_dotenv import redis # Load local environment variables load_dotenv() host = os.getenv("REDIS_HOST") port = int(os.getenv("REDIS_PORT", "6380")) password = os.getenv("REDIS_PASSWORD") ssl_enabled = os.getenv("REDIS_SSL", "true").lower() == "true" try: client = redis.Redis( host=host, port=port, password=password, ssl=ssl_enabled, decode_responses=True ) # Verify connection client.ping() print("Connected to Redis") # Write current time now = datetime.now().isoformat() client.set("demo:timestamp", now) print(f"WROTE: {now}") # Read value back value = client.get("demo:timestamp") print(f"READ : {value}") except Exception as ex: print("Connection failed.") print(ex)Important
AI-assisted software development is non-deterministic, meaning you don't get the same code generated twice. However, in a simple application like this one, the basic approach, syntax, and end result should be close though not exactly the same.
Run the app
In the terminal, run the app:
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python main.py
You should see output similar to this:
Connected to Redis
WROTE: 2026-03-01T10:22:11.452331
READ : 2026-03-01T10:22:11.452331
Clean up resources
Use the following prompt:
I am finished with this instance. Please remove the Azure Cache for Redis that you created earlier by using the values in the `.env` file. ONLY remove this resource and nothing else.
Related content
- Understand what GitHub Copilot for Azure is and how it works.
- Follow the quickstart to understand how to include GitHub Copilot for Azure in your software development workflow. The quickstart describes how to deploy services to Azure, monitor their status, and troubleshoot problems.
- See example prompts for learning more about Azure and understanding your Azure account, subscription, and resources.
- See example prompts for designing and developing applications for Azure.
- See example prompts for deploying your application to Azure.
- See example prompts for troubleshooting your Azure resources.