「マイクロソフト系技術情報 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
目次 †
概要 †
昔で言う、StateServerやSQL Serverのモード。
詳細 †
Redis †
Redisが一般的
サンプル †
.NET Core 2.1以前のバージョンでは、AddDistributedRedisCache?を、
.NET Core 2.2以降のバージョンでは、AddStackExchangeRedisCache?を使う。
- NuGet
- StackExchange?.Redis
- Microsoft.Extensions.Caching.StackExchangeRedis?
- Microsoft.AspNetCore?.DataProtection?.StackExchangeRedis?
- コード
using StackExchange.Redis;
using Microsoft.AspNetCore.DataProtection;
...
var redis = ConnectionMultiplexer
.Connect(Environment.GetEnvironmentVariable("REDIS"));
services
.AddDataProtection()
.PersistKeysToStackExchangeRedis(redis, "DataProtectionKeys");
services.AddStackExchangeRedisCache(option =>
{
option.Configuration = Environment
.GetEnvironmentVariable("REDIS");
option.InstanceName = "RedisInstance";
});
config †
Connectメソッドの引数はconfigで、ココに、以下のように、
「,」区切りで、色々なオプションを設定可能であるもよう。
ConnectionMultiplexer connection =
ConnectionMultiplexer.Connect("endpoint,password=password,ConnectTimeout=10000");
- 昔で言う、machine.config の machineKeyの話。
- 前述のサンプル・コードのように、
- AddDataProtection?()
- SetApplicationName?()
- PersistKeysToStackExchangeRedis?()
を呼び出す。
参考 †
Microsoft Docs †
Medium †
銀の光と碧い空 †
Tags: :.NET開発, :.NET Core, :ASP.NET, :ASP.NET MVC