You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-cache-for-redis/cache-development-faq.yml
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -51,15 +51,18 @@ sections:
51
51
### Timeout values
52
52
* Consider your workload and set the values to match. If you're storing large values, set the timeout to a higher value.
53
53
* 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).
55
55
* Set the `ConnectionMultiplexer.ClientName` property to an app instance unique name for diagnostic purposes.
56
56
* 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
+
58
60
* You can have one multiplexer for dealing with large keys.
59
61
* 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.
61
63
* 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`.
#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.
11
12
---
12
-
# Quickstart: Use Azure Cache for Redis in .NET Core
13
13
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
15
15
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.
17
17
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.
19
23
20
24
## Prerequisites
21
25
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/)
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.
32
36
33
37
## Add a local secret for the connection string
34
38
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>`):
36
40
37
41
```dos
38
42
dotnet user-secrets set CacheConnection "<cache name>.redis.cache.windows.net,abortConnect=false,ssl=true,allowAdmin=true,password=<primary-access-key>"
39
43
```
40
44
41
-
## Connect to the cache with RedisConnection
45
+
## Connect to the cache by using RedisConnection
42
46
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*:
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.
51
55
52
56
```csharp
53
57
usingStackExchange.Redis;
54
58
55
59
```
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.
58
60
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).
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.
108
114
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.
110
116
111
117
### Work with .NET objects in the cache
112
118
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.
114
120
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.
116
122
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.
118
124
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:
120
126
121
127
```csharp
122
128
classEmployee
@@ -136,42 +142,25 @@ class Employee
136
142
137
143
## Run the sample
138
144
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:
140
146
141
147
```dos
142
148
dotnet build
143
149
```
144
150
145
-
Run the app with the following command to test serialization of .NET objects:
151
+
To test serialization of .NET objects, run this command:
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**.
:::image type="content" source="media/cache-dotnet-core-quickstart/cache-console-app-complete.png" alt-text="Screenshot that shows a console test completed.":::
169
158
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 -->
171
160
172
-
After a few moments, the resourcegroup and all of its contained resources are deleted.
0 commit comments