我正在连接redis服务器。然后说redis服务器。我正在用redis cli启动客户端。我有自己的MVC项目。产品控制器是这样的
public class ProductsController : Controller
{
private readonly IDistributedCache _distributedCache;
public ProductsController(IDistributedCache distributedCache)
{
_distributedCache = distributedCache;
}
public IActionResult Index()
{
DistributedCacheEntryOptions cacheEntryOptions = new DistributedCacheEntryOptions();
cacheEntryOptions.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
_distributedCache.SetString("name","Berkay",cacheEntryOptions);
return View();
}
}
针对持有错误类型值的键的错误类型操作
错误就在这里。
_distributedCache.SetString("name","Berkay",cacheEntryOptions);
另外,我的启动文件如下所示。我也在ConfigureService中做了定义
public void ConfigureServices(IServiceCollection services)
{
services.AddStackExchangeRedisCache(opt =>
{
opt.Configuration = "localhost:6379";
});
services.AddControllersWithViews();
}