简体   繁体   English

我该如何解决这个错误 StackExchange.Redis.RedisConnectionException: UnableToConnect on redisaec.redis.cache.windows.net:6380/Interactive

[英]how can I solve this error StackExchange.Redis.RedisConnectionException: UnableToConnect on redisaec.redis.cache.windows.net:6380/Interactive

I have using Regis cache in my project after running the project I have got this error, I cannot find any solution for this problem.运行项目后,我在我的项目中使用了 Regis 缓存我遇到了这个错误,我找不到这个问题的任何解决方案。

here is my controller code这是我的控制器代码

public ActionResult Create(Guid orgId, Guid? workflowId, Guid? directoryId)
        {
            IDatabase cache = CacheExtensions.Connection.GetDatabase();

            var processFlowData = this.db.Workflows.Find(workflowId);
            List<WorkflowNode> nodeListBeforeUpdate = null;
            List<WorkflowLink> linkListBeforeUpdate = null;
            if (processFlowData != null)
            {
                nodeListBeforeUpdate = processFlowData.WorkflowNodes.ToList();
                linkListBeforeUpdate = processFlowData.WorkflowLinks.ToList();
                ViewBag.oldNodeList = nodeListBeforeUpdate.Count();
                ViewBag.oldLinkList = linkListBeforeUpdate.Count();
            }
            //var workflowData = this.DatabaseFactory.ProcessFlowUtils.GetWorkflowData(workflowId.GetValueOrDefault());
            var appuser = this.GetDefaultUser();
            ViewBag.AppuserName = appuser.AppUserFullName;
            ViewBag.DirectoryId = directoryId;
            ViewBag.OrgId = orgId;
            ViewBag.IsNew = !workflowId.HasValue;
            if (!workflowId.HasValue)
            {
                workflowId = Guid.NewGuid();
                ViewBag.IsAgentExists = false;
            }
            else
            {
                //Considering single deployment
                SetSubscriptionStatus(orgId);
                var agentIdentification = this.DatabaseFactory.AgentUtils.GetDeploymentAgentItem(workflowId, orgId);
                ViewBag.AgentIdentificationGuid = agentIdentification.AgentIdentificationGuid;
                ViewBag.DeploymentStatus = agentIdentification.DeployStatus ?? 1;
                ViewBag.CanExecute = agentIdentification.canExecute;

                if (agentIdentification != null && agentIdentification.AgentDeploymentId != Guid.Empty)
                {
                    var isAgentExists = this.DatabaseFactory.ProcessFlowUtils.IsAgentExist(agentIdentification.AgentIdentificationGuid, orgId);
                    ViewBag.IsAgentExists = isAgentExists;
                }
                else
                {
                    ViewBag.IsAgentExists = false;
                }
            }
           
            ViewBag.WorkFlowId = workflowId;
            cache.Set("WorkflowID", workflowId, TimeSpan.FromDays(1));
            return View();
        } 

here is the cache extension code.这是缓存扩展代码。

public static class CacheExtensions
    {
        private static Lazy<ConnectionMultiplexer> redisConnection = GetNewRedisConnection();
        public static LazyThreadSafetyMode LazyThreadSafetyMode = LazyThreadSafetyMode.None;
        private static Lazy<ConnectionMultiplexer> GetNewRedisConnection()
        {
            return new Lazy<ConnectionMultiplexer>(() =>
            {
                return ConnectionMultiplexer.ConnectAsync(ConfigurationManager.AppSettings["RedisConnection"]).ConfigureAwait(false).GetAwaiter().GetResult();
            }, LazyThreadSafetyMode);
        }

        public static ConnectionMultiplexer Connection
        {
            get
            {
                return redisConnection.Value;
            }
            set
            {
                if (value == null)
                    redisConnection = GetNewRedisConnection();
            }
        }

        public static T Get<T>(this IDatabase cache, string key)
        {
            return Deserialize<T>(cache.StringGet(key));
        }

        public static object Get(this IDatabase cache, string key)
        {
            return Deserialize<object>(cache.StringGet(key));
        }

        public static byte[] GetBytes(this IDatabase cache, string key)
        {
            return cache.StringGet(key);
        }
        public static void Set(this IDatabase cache, string key, object value)
        {
            int convertedVal;
            var expTimeSpan = ConfigurationManager.AppSettings["RedisExpiryTime"];
            bool isNumerical = int.TryParse(expTimeSpan, out convertedVal);
            cache.StringSet(key, Serialize(value),
                isNumerical == true ? TimeSpan.FromHours(convertedVal) : TimeSpan.FromHours(24));
        }
        public static void SetByteArray(this IDatabase cache, string key, byte[] value)
        {
            int convertedVal;
            var expTimeSpan = ConfigurationManager.AppSettings["RedisExpiryTime"];
            bool isNumerical = int.TryParse(expTimeSpan, out convertedVal);
            cache.StringSet(key, Serialize(value),
                isNumerical == true ? TimeSpan.FromHours(convertedVal) : TimeSpan.FromHours(24));
        }
        public static void Set(this IDatabase cache, string key, object value, TimeSpan timeToLive)
        {
            cache.StringSet(key, Serialize(value), timeToLive);
        }
        static byte[] Serialize(object o)
        {
            if (o == null)
            {
                return null;
            }
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            using (MemoryStream memoryStream = new MemoryStream())
            {
                binaryFormatter.Serialize(memoryStream, o);
                byte[] objectDataAsStream = memoryStream.ToArray();
                return objectDataAsStream;
            }
        }

        static T Deserialize<T>(byte[] stream)
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            if (stream == null)
                return default(T);

            using (MemoryStream memoryStream = new MemoryStream(stream))
            {
                T result = (T)binaryFormatter.Deserialize(memoryStream);
                return result;
            }
        }
    }

full details of issues is: UnableToConnect on redisaec.redis.cache.windows.net:6380/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 0s ago, last-write: 0s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.2.50.36290 Description: An unhandled exception occurred during the execution of the current web request.问题的完整细节是: Redisaec.redis.cache.windows.net 上的 UnableToConnect : 6380/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync,outstanding: 0, last-read: 0s ago, last-write: 0s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.2.50.36290 描述:执行当前 Web 请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code.请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

Exception Details: StackExchange.Redis.RedisConnectionException: UnableToConnect on redisaec.redis.cache.windows.net:6380/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 0s ago, last-write: 0s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.2.50.36290异常详细信息:StackExchange.Redis.RedisConnectionException: UnableToConnect on redisaec.redis.cache.windows.net:6380/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync,outstanding: 0, last-read: 0s ago, last-写入:0 秒前,保持活动状态:60 秒,状态:正在连接,管理器:10 个可用的 10 个,最后一次心跳:从不,全局:0 秒前,v:2.2.50.36290

I don't know what the format of RedisConnection in your peoject.我不知道您的项目中RedisConnection的格式是什么。

It should be like below:它应该如下所示:

yourredisname.redis.cache.windows.net:6380,password=13l***yt8=,ssl=True,abortConnect=False,allowAdmin=true

I saw your add asp.net core tag.我看到您添加了 asp.net 核心标签。 And previous I have created a sample code about azure cache for redis which use Lazy<ConnectionMultiplexer> .之前我为 redis 创建了一个关于 azure 缓存的示例代码,它使用Lazy<ConnectionMultiplexer> And you can refer it or download it from github .你可以参考它或从 github 下载它

在此处输入图片说明

在此处输入图片说明


If you still have problems, you need to check Firewall or Access keys on portal.如果仍有问题,则需要检查门户上的FirewallAccess keys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 StackExchange Redis - Net Framework - RedisConnectionException - 无法访问服务 HashSlot - StackExchange Redis - Net Framework - RedisConnectionException - Serving HashSlot Is Not Reachable StackExchange.Redis:没有可用的连接来服务这个操作。 UnableToConnect on HOST:PORT/Interactive - StackExchange.Redis: No connection is available to service this operation. UnableToConnect on HOST:PORT/Interactive stackexchange redis缓存性能 - stackexchange redis cache performance Redis StackExchange缓存性能 - Redis StackExchange cache performance 使用StackExchange.Redis将自定义.Net对象存储在Azure Redis缓存中 - Storing custom .Net objects in Azure Redis Cache with StackExchange.Redis 使用StackExchange.Redis与Azure Redis缓存的错误连接 - Error connection to Azure Redis Cache using StackExchange.Redis 如何使用StackExchange.Redis解决客户端的Redis超时问题? - How to solve a Redis timeout on client side with StackExchange.Redis? 如何使用 StackExchange.Redis 存储列表? - How can I store a list using StackExchange.Redis? 如何获取StackExchange.Redis的密钥数? - How can I get a key count for StackExchange.Redis? StackExchange.Redis - 如何在运行时更改配置? - StackExchange.Redis - How can I change configuration at runtime?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM