admin管理员组文章数量:1394057
I'm adding a Redis token cache with data protection and also persisting the data protection keys to Redis (Propably a different Redis cache located somewhere other than the same token cache server). I'm just not sure if I should create and reuse the same 'ConnectionMultiplexer' here
services.AddStackExchangeRedisCache(redisCacheOptions =>
{
redisCacheOptions.ConnectionMultiplexerFactory = redis;
}
as I'm using here
services.AddDataProtection()
.SetApplicationName(appName)
.PersistKeysToStackExchangeRedis(redis, $"{appName}_DataProtection-Keys");
Or just have the AddStackExchangeRedisCache take care of it by itself?
If yes, how would I do that and still being able to dispose of it? And should I add a different name and endpoints each time it is used?
I'm new at this, so I would appreciate some help :)
I'm adding a Redis token cache with data protection and also persisting the data protection keys to Redis (Propably a different Redis cache located somewhere other than the same token cache server). I'm just not sure if I should create and reuse the same 'ConnectionMultiplexer' here
services.AddStackExchangeRedisCache(redisCacheOptions =>
{
redisCacheOptions.ConnectionMultiplexerFactory = redis;
}
as I'm using here
services.AddDataProtection()
.SetApplicationName(appName)
.PersistKeysToStackExchangeRedis(redis, $"{appName}_DataProtection-Keys");
Or just have the AddStackExchangeRedisCache take care of it by itself?
If yes, how would I do that and still being able to dispose of it? And should I add a different name and endpoints each time it is used?
I'm new at this, so I would appreciate some help :)
Share Improve this question edited Mar 17 at 6:42 Brando Zhang 28.7k6 gold badges42 silver badges70 bronze badges asked Mar 13 at 10:48 Super userSuper user 14 bronze badges1 Answer
Reset to default 0This is according to your actually requirement, normally, reuse the same ConnectionMultiplexer instance across different parts of your application is generally recommended to avoid the overhead of creating multiple connections.
The ConnectionMultiplexerFactory is design for reusing connections to caches.
Also the ConnectionMultiplexer is thread safe and for consideruing the dispose for it, I suggest you could consider register it as a singletion.
Like below:
IConnectionMultiplexer connectionMultiplexer =
ConnectionMultiplexer.Connect(connectionString);
builder.Services.AddSingleton(connectionMultiplexer);
builder.Services.AddStackExchangeRedisCache(options =>
{
options.ConnectionMultiplexerFactory =
() => Task.FromResult(connectionMultiplexer);
});
本文标签:
版权声明:本文标题:asp.net core - Same 'ConnectionMultiplexer' for 'AddDataProtection' and 'AddStackExchang 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744706671a2620879.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论