1.NuGet安装StackExchange.Redis,如果已经用了Microsoft.Extensions.Caching.Redis的话,就安装StackExchange.Redis.StrongName
StartUp.cs注入服务:services.AddSingleton<IConnectionMultiplexer>(ConnectionMultiplexer.Connect("localhost"));
2.依赖注入IConnectionMultiplexer connectionMultiplexer
var _db = _connectionMultiplexer.GetDatabase();
3.使用:
public IActionResult RedisTest()
{
_db.StringSet("name", "jay123456");
string name = _db.StringGet("name");
return View("RedisTest", name);
}