Adding Redis

microservices csharp aspnetcore

This is the third post in the microservices architecture series.

The goal of this post is to add Redis to the sample application and make a simple call to verify that it works.

Sample Application

Download the sample app from here and walkthrough the changes in the next section.

Source Code Changes

  • SampleApi2.csproj - Added the AspNetCore.HealthChecks.Redis package to the project.

  • Product.cs - It is the model that is saved to Redis.

  • ProductRepository.cs - Simple crud operations that connect to the Redis instance.

  • Program.cs - Two AddSingleton methods. One adds the ProductRepository and the other adds the ConnectionMultiplexer for Redis.

  • ProductController.cs - Has simple crud actions that test the Redis connection.

Verification

  • F5 should start debugging the docker compose file.

  • You should be able to see the swagger file for SampleApi2 project using the /swagger link.

  • Test the ProductController.