Redis
{
"Caching": {
"Source": "Redis",
"Redis": {
"Hosts": [
"localhost:6379",
],
"Username": "admin",
"Password": "your+str0ng_Password!"
}
}
}// Program.cs (.NET5 and above)
public static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add with configuration instance
var cacheOptions = new RedisCacheOptions();
cacheOptions.Hosts = new [] { "localhost:6379" };
cacheOptions.UserName = "admin";
cacheOptions.Password = "your+str0ng_Password!";
builder.AddCaching(x => x.Redis(cacheOptions));
// Add with inline action method
builder.AddCaching(x => x.Redis(x => x.BacklogPolicy = StackExchange.Redis.BacklogPolicy.FailFast));
var app = builder.Build();
app.Run();
}Last updated