无法在MVC应用程序中配置Redis缓存



我是Azure Redis缓存的新手。我刚刚在Azure Portal中配置了Redis缓存。我已经通过nuget在我的项目中安装了StackExchange.RRedis。以下是连接Redis 的代码

ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("server.redis.cache.windows.net,ssl=true,password=primary access key");
        IDatabase cache = connection.GetDatabase();

连接时出现以下错误:

JIT Compiler encountered an internal limitation.
at StackExchange.Redis.ConfigurationOptions.OptionKeys.TryNormalize(String value)
at StackExchange.Redis.ConfigurationOptions.DoParse(String configuration, Boolean ignoreUnknown) in c:TeamCitybuildAgentwork3ae0647004edff78StackExchange.RedisStackExchangeRedisConfigurationOptions.cs:line 501
at StackExchange.Redis.ConfigurationOptions.Parse(String configuration) in c:TeamCitybuildAgentwork3ae0647004edff78StackExchange.RedisStackExchangeRedisConfigurationOptions.cs:line 279
at StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(Object configuration) in c:TeamCitybuildAgentwork3ae0647004edff78StackExchange.RedisStackExchangeRedisConnectionMultiplexer.cs:line 728
at StackExchange.Redis.ConnectionMultiplexer.<>c__DisplayClass24.<Connect>b__23() in c:TeamCitybuildAgentwork3ae0647004edff78StackExchange.RedisStackExchangeRedisConnectionMultiplexer.cs:line 745
at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func`1 multiplexerFactory, TextWriter log) in c:TeamCitybuildAgentwork3ae0647004edff78StackExchange.RedisStackExchangeRedisConnectionMultiplexer.cs:line 761
at StackExchange.Redis.ConnectionMultiplexer.Connect(String configuration, TextWriter log) in c:TeamCitybuildAgentwork3ae0647004edff78StackExchange.RedisStackExchangeRedisConnectionMultiplexer.cs:line 745
at App.Web.Controllers.HomeController.Index() in g:UsersWorkspacesAlphaProjectApp.WebControllersHomeController.cs:line 42
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.ActionInvocation.InvokeSynchronousActionMethod()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()

请给我一些连接Redis服务器的解决方案。

提前谢谢。

你能通过尝试使用控制台应用程序连接到Redis Cache来隔离问题吗?您也可以参考此示例在MVC中使用Redis缓存http://azure.microsoft.com/blog/2014/06/05/mvc-movie-app-with-azure-redis-cache-in-15-minutes/

我不知道这是否有帮助。我为Long打了一个类似的错误,说

"ArgumentNullException:值不能为null。参数名称:配置StackExchange.Ris.ConnectionMultiplexer.CreateMultiplexer(对象ConnectionMultiplexer.cs,第844"行

我查看了我的Startup.cs,并像这样重写了以下行,现在它起作用了:

services.AddDistributedRedisCache(option =>
            {
                option.Configuration = "pretzelcache.redis.cache.windows.net:6380,password=qD+cdEMf5SI+2Psi7zUXdGSwjKCZnhwLvb3tmi3i6O8=,ssl=True,abortConnect=False";
            });

早些时候,Option.Configuration直接尝试从appsettings.json文件中读取connectionString,但有些东西没有正确连接。

干杯。

最新更新