ASP.NET Identity Redis Provider
Aguacongas.Identity.Redis |
---|
You setup Redis stores using one AddRedisStores
extension method
You can setup Redis stores with a redis configuration string:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddRedisStores("localhost")
.AddDefaultTokenProviders();
Or with an Action
receiving an instance of a StackExchange.Redis.ConfigurationOptions
:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddRedisStores(options =>
{
options.EndPoints.Add("localhost:6379");
})
.AddDefaultTokenProviders();
Both methods can take a int? database
parameter to specify the Redis database to use:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddRedisStores(Configuration.GetValue<string>("ConnectionStrings:DefaultConnection"), 1)
.AddDefaultTokenProviders();
Or, you can use AddRedisStores
with a Func<IdentityProvider, StackExchange.Redis.IDatabase>
:
var multiplexer = ConnectionMultiplexer.Connect("localhost");
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddRedisStores(provider => multiplexer.GetDatabase())
.AddDefaultTokenProviders();
A logger is automaticaly injected to the underlying StackExchange.Redis.ConnectionMultiplexer
by AddRedisStores
methods.
This logger write traces, (LogLevel = LogLevel.Trace
), to enable it add a filter to your logging configuration:
services.AddLogging(builder =>
{
builder.AddDebug()
.AddConsole()
.AddFilter("Aguacongas.Identity.Redis", LogLevel.Trace);
})
Obviously, if you use
AddRedisStores
with aFunc<IdentityProvider, StackExchange.Redis.IDatabase>
the logger is not injected automaticaly.
The sample is a copy of IdentitySample.Mvc sample using a Redis database.
This library is tested using Microsoft.AspNetCore.Identity.Specification.Tests, the shared test suite for Asp.Net Identity Core store implementations.