HOW TO USE DISTRIBUTED REDIS CACHE BEHIND A LOAD BALANCER IN DOTNET CORE
29.04.2021What is redis?
Our Scenario
Configuring Redis
Configuring your dotnet core application
public void ConfigureStagingServices(IServiceCollection services) { services.AddDistributedRedisCache(options => { options.Configuration = "<REDIS URI>"; options.InstanceName = "SampleInstance"; }); }
services.AddSession(options => { options.CookieName = "My.Session.Cookie"; }); app.UseSession(); app.UseMvc()
public IActionResult Load() { ViewData["SessionData"] = HttpContext.Session.GetString("MySessionKey"); return View(); } public IActionResult Save() { HttpContext.Session.SetString("MySessionKey", "Hello World"); return View(); }
services.AddDataProtection().SetApplicationName("My Application Name");
var redis = ConnectionMultiplexer.Connect("<REDIS URI>"); services.AddDataProtection().PersistKeysToRedis(redis, "DataProtection-Keys");