Using Redis cache with ASP.Net Core Web API (Both running inside Docker containers)

Опубликовано: 03 Октябрь 2024
на канале: DotNet Core Central
24,983
389

In this video, I will demonstrate how to use Redis as a distributed in-memory caching engine with ASP.Net Core and C# application.

#csharp #redis #aspdotnetcore

I am going to cover the following high-level topics:
1. What is Redis Cache
2. Key features provided by Redis Cache
3. Installing Redis Cache in a Docker container
4. Using Caching Redis in .Net Core Web API

For more detail, please visit my blog: https://dotnetcorecentral.com/blog/re...

Using a caching solution becomes important when we are building a high performant web-based application or micro-services system. And Redis is one of the most popular in-memory distributed caching solutions available out there.

Redis is an open-source distributed in-memory data store. We can use it as a distributed (no-SQL) database or as a distributed in-memory cache or a pub/sub messaging engine, and more recently streaming engine. The most popular use case I have encountered so far, is using it as a distributed in-memory caching engine. Hence in this video, I will implement using the caching feature of Redis in .Net Core application.

Redis supports multiple data structures. But the most frequently used one is a string. Though there are use cases for other data structures like Hashes and Sets.

Redis also supports a stream implementation starting from version 5.

For the ASP.Net Core Web API application, I have used StackExchange.Redis nuget package, which is an implementation of Redis client. This nuget package supports all the core features provided by Redis.

Redis also comes with redis-cli which is a command-line interface for Redis. And it supports all the commands of Redis. It is a very handy tool when debugging issues or even verifying/testing during the initial development process.

In conclusion, using Redis is very simple and straightforward. The redis-cli is very easy to use. The StackExchange.Redis nuget package is also very simple. As far as an in-memory distributed cache is concerned, its a very good tool. I am not user I will ever use it anything beyond just a caching platform. I am not sold into using it as a Pub/Sub engine or even a stream. But this is just my personal preference, since I use other product for these features.