Py学习  »  Redis

RedisServerException:运行脚本时出错

Berkay Kulak • 2 年前 • 328 次点击  

我正在连接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
 
328 次点击  
文章 [ 1 ]  |  最新文章 2 年前
Marc Gravell
Reply   •   1 楼
Marc Gravell    2 年前

我怀疑您在这里使用的库使用的脚本假定给定的密钥是“散列”类型,尤其是:仅通过同一个库和脚本创建的散列(使用存储值的不同子值、滚动过期细节等)。但你的密钥似乎不是——也许是原始的“字符串”类型。您可以使用各种redis工具(“例如,调试对象”)来调查密钥,但如果这是一个缓存服务器,则从orbit中直接将其核化可能更容易,并假设只有当前库选项使用的是一块空白板。