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

时间:2015-04-08 05:02:24

标签: asp.net-mvc caching azure redis

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

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

        IDatabase cache = connection.GetDatabase();

我在连接时遇到错误:

  

JIT Compiler遇到内部限制。

at StackExchange.Redis.ConfigurationOptions.OptionKeys.TryNormalize(String value)    at StackExchange.Redis.ConfigurationOptions.DoParse(String configuration,Boolean ignoreUnknown)在c:\ TeamCity \ buildAgent \ work \ 3ae0647004edff78 \ StackExchange.Redis \ StackExchange \ Redis \ ConfigurationOptions.cs:第501行    at StackExchange.Redis.ConfigurationOptions.Parse(String configuration)in c:\ TeamCity \ buildAgent \ work \ 3ae0647004edff78 \ StackExchange.Redis \ StackExchange \ Redis \ ConfigurationOptions.cs:line 279    at StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(Object configuration)in c:\ TeamCity \ buildAgent \ work \ 3ae0647004edff78 \ StackExchange.Redis \ StackExchange \ Redis \ ConnectionMultiplexer.cs:line 728    at StackExchange.Redis.ConnectionMultiplexer。&lt;&gt; c__DisplayClass24.b__23()in c:\ TeamCity \ buildAgent \ work \ 3ae0647004edff78 \ StackExchange.Redis \ StackExchange \ Redis \ ConnectionMultiplexer.cs:line 745    在StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func 1 multiplexerFactory, TextWriter log) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 761 at StackExchange.Redis.ConnectionMultiplexer.Connect(String configuration, TextWriter log) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 745 at App.Web.Controllers.HomeController.Index() in g:\Users\Workspaces\AlphaProject\App.Web\Controllers\HomeController.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个参数)    在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)    在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()    在System.Web.Mvc.Async.AsyncResultWrapper.End [TResult](IAsyncResult asyncResult,Object tag)    在System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)    在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3d()    在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters。&lt;&gt; c__DisplayClass46.b__3f()

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

提前致谢。

2 个答案:

答案 0 :(得分:0)

是否可以通过使用控制台应用程序尝试连接到Redis缓存来确定问题,看看是否有效? 您也可以参考此示例在MVC中使用Redis缓存http://azure.microsoft.com/blog/2014/06/05/mvc-movie-app-with-azure-redis-cache-in-15-minutes/

答案 1 :(得分:0)

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

  

&#34; ArgumentNullException:值不能为null。参数名称:   组态   StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(对象   ConnectionMultiplexer.cs,第844行和第34页

中的配置)

我查看了我的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,而且没有正确连接到那里。

干杯。