【redis】在dotnet core下的redis的使用

1.Install-Package Microsoft.Extensions.Caching.Redis -Version 2.2.0

2.注入

            services.AddDistributedRedisCache(opt =>
{
opt.Configuration = Configuration.GetConnectionString("RedisServer");
//opt.InstanceName = "db0";
});

3.在Action中读写;

  public ActionResult<string> Get(int id)
{
_distributedCache.SetString("key{id}", JsonConvert.SerializeObject(new object{}));
var obj = JsonConvert.DeserializeObject<object>(_distributedCache.GetStringAsync("key{id}").Result);
return Content(obj.ToString());
}

4.其他构造

上一篇:Docker 实战(二)——centos7镜像安装nginx,将安装nginx的centos容器生成新的镜像,并导出


下一篇:SpringBoot 源码解析 (八)----- Spring Boot 精髓:事务源码解析