Skip to content

Commit 19eaec5

Browse files
authored
Merge pull request #286557 from ktoliver/304195
[AQ] edit pass: Azure Cache for Redis quickstarts (work item 304195)
2 parents eef8769 + c6ba83c commit 19eaec5

38 files changed

+613
-643
lines changed

articles/azure-cache-for-redis/cache-development-faq.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ sections:
5151
### Timeout values
5252
* Consider your workload and set the values to match. If you're storing large values, set the timeout to a higher value.
5353
* Set `AbortOnConnectFail` to false and let StackExchange.Redis reconnect for you.
54-
* Use a single, long-lived `ConnectionMultiplexer` instance rather than creating a new connection for each request. For an example of how to manage a connection, see the `RedisConnection`` class in [Connect to the cache with RedisConnection](cache-dotnet-how-to-use-azure-redis-cache.md#connect-to-the-cache-with-redisconnection).
54+
* Use a single, long-lived `ConnectionMultiplexer` instance rather than creating a new connection for each request. For an example of how to manage a connection, see the `RedisConnection` class in [Connect to the cache by using RedisConnection](cache-dotnet-how-to-use-azure-redis-cache.md#connect-to-the-cache-by-using-redisconnection).
5555
* Set the `ConnectionMultiplexer.ClientName` property to an app instance unique name for diagnostic purposes.
5656
* Use multiple `ConnectionMultiplexer` instances for custom workloads.
57-
* You can follow this model if you have varying load in your application. For example:
57+
58+
You can follow this model if you have varying loads in your application. For example:
59+
5860
* You can have one multiplexer for dealing with large keys.
5961
* You can have one multiplexer for dealing with small keys.
60-
* You can set different values for connection timeouts and retry logic for each ConnectionMultiplexer that you use.
62+
* You can set different values for connection timeouts and retry logic for each `ConnectionMultiplexer` that you use.
6163
* Set the `ClientName` property on each multiplexer to help with diagnostics.
62-
* This guidance might lead to more streamlined latency per `ConnectionMultiplexer`.
64+
65+
Following this guidance might lead to more streamlined latency per `ConnectionMultiplexer`.
6366
6467
- question: |
6568
What Azure Cache for Redis clients can I use?
Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
---
2-
title: 'Quickstart: Use Azure Cache for Redis in .NET Core'
3-
description: In this quickstart, learn how to access Azure Cache for Redis in your .NET Core apps
2+
title: 'Quickstart: Use Azure Cache for Redis with .NET Core'
3+
description: Modify a sample .NET Core app and connect the app to Azure Cache for Redis.
44

55

66

77
ms.devlang: csharp
88
ms.custom: devx-track-csharp, mvc, mode-other, devx-track-dotnet
99
ms.topic: quickstart
1010
ms.date: 03/25/2022
11+
#Customer intent: As a .NET Core developer who is new to Azure Cache for Redis, I want to create a new .NET Core app that uses Azure Cache for Redis.
1112
---
12-
# Quickstart: Use Azure Cache for Redis in .NET Core
1313

14-
In this quickstart, you incorporate Azure Cache for Redis into a .NET Core app to have access to a secure, dedicated cache that is accessible from any application within Azure. You specifically use the [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis) client with C# code in a .NET Core console app.
14+
# Quickstart: Use Azure Cache for Redis with a .NET Core app
1515

16-
## Skip to the code on GitHub
16+
In this quickstart, you incorporate Azure Cache for Redis into a .NET Core app for access to a secure, dedicated cache that is accessible from any application in Azure. You specifically use the [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis) client with C# code in a .NET Core console app.
1717

18-
Clone the repo [https://github.com/Azure-Samples/azure-cache-redis-samples/tree/main/quickstart/dotnet-core](https://github.com/Azure-Samples/azure-cache-redis-samples/tree/main/quickstart/dotnet-core) on GitHub.
18+
## Skip to the code
19+
20+
This article describes how to modify the code for a sample app to create a working app that connects to Azure Cache for Redis.
21+
22+
If you want to go straight to the sample code, see the [.NET Core quickstart sample](https://github.com/Azure-Samples/azure-cache-redis-samples/tree/main/quickstart/dotnet-core) on GitHub.
1923

2024
## Prerequisites
2125

22-
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
26+
- An Azure subscription. [Create one for free](https://azure.microsoft.com/free/)
2327
- [.NET Core SDK](https://dotnet.microsoft.com/download)
2428

2529
## Create a cache
@@ -28,42 +32,44 @@ Clone the repo [https://github.com/Azure-Samples/azure-cache-redis-samples/tree/
2832

2933
[!INCLUDE [redis-cache-access-keys](includes/redis-cache-access-keys.md)]
3034

31-
Make a note of the **HOST NAME** and the **Primary** access key. You'll use these values later to construct the *CacheConnection* secret.
35+
Make a note of the values for **HOST NAME** and the **Primary** access key. You use these values later to construct the `CacheConnection` secret.
3236

3337
## Add a local secret for the connection string
3438

35-
In your command window, execute the following command to store a new secret named *CacheConnection*, after replacing the placeholders (including angle brackets) for your cache name and primary access key:
39+
In your Command Prompt window, execute the following command to store a new secret named `CacheConnection`. Replace the placeholders (including angle brackets) with your cache name (`<cache name>`) and primary access key (`<primary-access-key>`):
3640

3741
```dos
3842
dotnet user-secrets set CacheConnection "<cache name>.redis.cache.windows.net,abortConnect=false,ssl=true,allowAdmin=true,password=<primary-access-key>"
3943
```
4044

41-
## Connect to the cache with RedisConnection
45+
## Connect to the cache by using RedisConnection
4246

43-
The connection to your cache is managed by the `RedisConnection` class. The connection is first made in this statement from `Program.cs`:
47+
The connection to your cache is managed by the `RedisConnection` class. First, make the connection in this statement in *Program.cs*:
4448

4549
```csharp
4650
_redisConnection = await RedisConnection.InitializeAsync(connectionString: configuration["CacheConnection"].ToString());
4751

4852
```
4953

50-
In `RedisConnection.cs`, you see the `StackExchange.Redis` namespace has been added to the code. This is needed for the `RedisConnection` class.
54+
In *RedisConnection.cs*, the StackExchange.Redis namespace is added to the code. The namespace is required for the `RedisConnection` class.
5155

5256
```csharp
5357
using StackExchange.Redis;
5458

5559
```
56-
<!-- Is this right Philo -->
57-
The `RedisConnection` code ensures that there is always a healthy connection to the cache by managing the `ConnectionMultiplexer` instance from `StackExchange.Redis`. The `RedisConnection` class recreates the connection when a connection is lost and unable to reconnect automatically.
5860

59-
For more information, see [StackExchange.Redis](https://stackexchange.github.io/StackExchange.Redis/) and the code in a [GitHub repo](https://github.com/StackExchange/StackExchange.Redis).
61+
The `RedisConnection` class code ensures that there's always a healthy connection to the cache. The connection is managed by the `ConnectionMultiplexer` instance from StackExchange.Redis. The `RedisConnection` class re-creates the connection when a connection is lost and can't reconnect automatically.
62+
63+
For more information, see [StackExchange.Redis](https://stackexchange.github.io/StackExchange.Redis/) and the code in the [StackExchange.Redis GitHub repo](https://github.com/StackExchange/StackExchange.Redis).
6064

6165
<!-- :::code language="csharp" source="~/samples-cache/quickstart/dotnet-core/RedisConnection.cs"::: -->
6266

63-
## Executing cache commands
67+
## Execute cache commands
68+
69+
In *Program.cs*, you can see the following code for the `RunRedisCommandsAsync` method in the `Program` class for the console application:
6470

65-
In `program.cs`, you can see the following code for the `RunRedisCommandsAsync` method in the `Program` class for the console application:
6671
<!-- Replaced this code with lines 57-81 from dotnet-core/Program.cs -->
72+
6773
```csharp
6874
private static async Task RunRedisCommandsAsync(string prefix)
6975
{
@@ -104,19 +110,19 @@ private static async Task RunRedisCommandsAsync(string prefix)
104110

105111
```
106112

107-
Cache items can be stored and retrieved by using the `StringSetAsync` and `StringGetAsync` methods.
113+
You can store and retrieve cache items by using the `StringSetAsync` and `StringGetAsync` methods.
108114

109-
In the example, you can see the `Message` key is set to value. The app updated that cached value. The app also executed the `PING` and command.
115+
In the example, you can see the `Message` key is set to a value. The app updated that cached value. The app also executed the `PING` and command.
110116

111117
### Work with .NET objects in the cache
112118

113-
The Redis server stores most data as strings, but these strings can contain many types of data, including serialized binary data, which can be used when storing .NET objects in the cache.
119+
The Redis server stores most data in string format. The strings can contain many types of data, including serialized binary data. You can use serialized binary data when you store .NET objects in the cache.
114120

115-
Azure Cache for Redis can cache both .NET objects and primitive data types, but before a .NET object can be cached it must be serialized.
121+
Azure Cache for Redis can cache both .NET objects and primitive data types, but before a .NET object can be cached, it must be serialized.
116122

117-
This .NET object serialization is the responsibility of the application developer, and gives the developer flexibility in the choice of the serializer.
123+
The .NET object serialization is the responsibility of the application developer. The object serialization gives the developer flexibility in their choice of the serializer.
118124

119-
The following `Employee` class was defined in *Program.cs* so that the sample could also show how to get and set a serialized object :
125+
The following `Employee` class was defined in *Program.cs* so that the sample could also show how to get and set a serialized object:
120126

121127
```csharp
122128
class Employee
@@ -136,42 +142,25 @@ class Employee
136142

137143
## Run the sample
138144

139-
If you have opened any files, save them and build the app with the following command:
145+
If you opened any files, save the files. Then, build the app by using the following command:
140146

141147
```dos
142148
dotnet build
143149
```
144150

145-
Run the app with the following command to test serialization of .NET objects:
151+
To test serialization of .NET objects, run this command:
146152

147153
```dos
148154
dotnet run
149155
```
150156

151-
:::image type="content" source="media/cache-dotnet-core-quickstart/cache-console-app-complete.png" alt-text="Console app completed":::
152-
153-
## Clean up resources
154-
155-
If you continue to use this quickstart, you can keep the resources you created and reuse them.
156-
157-
Otherwise, if you're finished with the quickstart sample application, you can delete the Azure resources created in this quickstart to avoid charges.
158-
159-
> [!IMPORTANT]
160-
> Deleting a resource group is irreversible and that the resource group and all the resources in it are permanently deleted. Make sure that you do not accidentally delete the wrong resource group or resources. If you created the resources for hosting this sample inside an existing resource group that contains resources you want to keep, you can delete each resource individually on the left instead of deleting the resource group.
161-
>
162-
### To delete a resource group
163-
164-
1. Sign in to the [Azure portal](https://portal.azure.com) and select **Resource groups**.
165-
166-
1. In the **Filter by name...** textbox, type the name of your resource group. The instructions for this article used a resource group named *TestResources*. On your resource group in the result list, select **...** then **Delete resource group**.
167-
168-
:::image type="content" source="media/cache-dotnet-core-quickstart/cache-delete-resource-group.png" alt-text="Delete":::
157+
:::image type="content" source="media/cache-dotnet-core-quickstart/cache-console-app-complete.png" alt-text="Screenshot that shows a console test completed.":::
169158

170-
1. You'll be asked to confirm the deletion of the resource group. Type the name of your resource group to confirm, and select **Delete**.
159+
<!-- Clean up include -->
171160

172-
After a few moments, the resource group and all of its contained resources are deleted.
161+
[!INCLUDE [cache-delete-resource-group](includes/cache-delete-resource-group.md)]
173162

174-
## Next steps
163+
## Related content
175164

176-
- [Connection resilience](cache-best-practices-connection.md)
177-
- [Best Practices Development](cache-best-practices-development.md)
165+
- [Connection resilience best practices for your cache](cache-best-practices-connection.md)
166+
- [Development best practices for your cache](cache-best-practices-development.md)

0 commit comments

Comments
 (0)