Redis unable to connect in busy load

2019-07-10 14:29发布

问题:

I get this error. What is the work around ?

Could not connect to redis Instance at 127.0.0.1:6379 >> Stack trace : at ServiceStack.Redis.RedisNativeClient.Connect() at ServiceStack.Redis.RedisNativeClient.AssertConnectedSocket()
at ServiceStack.Redis.RedisNativeClient.SendCommand(Byte[][] cmdWithBinaryArgs) at ServiceStack.Redis.RedisNative Client.SendExpectLong(Byte[][] cmdWithBinaryArgs) at ServiceStack.Redis.RedisClientList.GetEnumerator() a t Common.Tools.RedisDBHelper.checkListInt(String myKey, Int32 id) >> Inner exception :message : No connection cou ld be made because the target machine actively refused it 127.0.0.1:6379 >> Inner exception :stacktrace : at S ystem.Net.Sockets.Socket.Connect(IPAddress[] addresses, Int32 port) at System.Net.Sockets.Socket.Connect(Stri ng host, Int32 port) at ServiceStack.Redis.RedisNativeClient.Connect()CurrentStack : at System.Environment. GetStackTrace(Exception e, Boolean needFileInfo) at System.Environment.get_StackTrace() at Common.Tools.E xtensionHelper.saveAsDebug(Exception myEx, String aciklama) at Common.Tools.RedisDBHelper.checkListInt(String myKey, Int32 id)

回答1:

I thought it may be that Redis had a busy load. Then I thought it was ServiceStack. But ultimately, it was that the TCP in Windows was not released fast enough. TCP does not release closed connections until the value of the entry expires. I set TcpTimeWaitDelay to 45 seconds. http://technet.microsoft.com/en-us/library/cc938217.aspx and set MaxUserPort http://mashijie.blogspot.com/2009/05/change-default-setting-of-tcp-ports.html

Adjust the port range to 1025-64511

Make sure you restart Windows

See also: Redis connection/buffer-size limit exceeded



回答2:

This is what happens when the RedisClient is unable to create a TCP connection. Throwing an exception is the correct behavior here.



回答3:

I had this problem myself. What binaries of Redis are you using (from what source, GitHub, unofficial build)?

The reason I found was: This is actually Redis's way to say that it can't create a connection. (as the trace provided also explains) Should be a more clear exception that explains that this is coming from Redis and not the firewall or anything IMHO.

My guess is that you're running a 32-bit built binary on a x64 architecture.

If you download the version from link: MsOpenTech Group and build it using an MS C compiler like the free VS 2012 Express you should be able to run the resulting binaries without this problem.

Can't make any promises, but this is what worked for me.

EDIT: Also, make sure to start the redis-server (as administrator) and give the neccesary permissions in the firewall, or you won't have a server to connect your redis-cli client to!