Py学习  »  Redis

RedisServerException:运行脚本时出错

Berkay Kulak • 2 年前 • 333 次点击  

我正在连接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();
        }
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129203
 
333 次点击  
文章 [ 1 ]  |  最新文章 2 年前