You are developing a .NET application that will write data to a newly provisioned Azure Cache for Redis instance. You need to connect to the cache and write a test key-value pair using the StackExchange.Redis library. Which sequence of steps should you perform? To answer, arrange the actions in the correct order.
- 1Add the StackExchange.Redis NuGet package to your .NET project.
- 2Retrieve the primary connection string from the Access keys blade of the cache in the Azure portal.
- 3Call the ConnectionMultiplexer.Connect method with the connection string to establish the connection.
- 4Call the GetDatabase method on the ConnectionMultiplexer instance to get a reference to the logical database.
- 5Invoke the StringSet method on the database reference to save the key-value pair.
Answer
To connect to and write to Azure Cache for Redis using StackExchange.Redis, you must first add the StackExchange.Redis package to your project. Next, retrieve the connection string from the Azure portal. Third, initialize the ConnectionMultiplexer object by calling ConnectionMultiplexer.Connect. Fourth, get a database reference using the GetDatabase method. Finally, perform the write operation by calling StringSet.
Interacting with Azure Cache for Redis starts by installing the required StackExchange.Redis SDK package to make developer APIs available. Once installed, the application requires credentials, which are retrieved as a connection string from the Azure portal. Using this connection string, a ConnectionMultiplexer object is instantiated via ConnectionMultiplexer.Connect. This handles network socket multiplexing and configuration. A database instance is then obtained by calling GetDatabase, which provides the necessary context for commands. Finally, key-value operations like StringSet are executed on this database instance.
Step-by-Step Solution
Key Concept
Connecting to and interacting with Azure Cache for Redis via StackExchange.Redis in a .NET application.