Use ASP. NET 5 on Linux to connect to the Redis server, asp. netredis
Recently, I am working on a Linux platform based on the ASP. Net 5 middleware + Redis + Mysql architecture.
StackExchange. Redis is used as a tool for connecting asp. net5 to redis. The author opened a new branch "CoreCLR" a few days ago to start upgrading asp. net5. There is also a problem related to pull request tracking. Test everything on a Windows development machine. After being migrated to the Docker container on Linux, we found that the asp. net5 middleware program encountered the following error when connecting to the local Redis service through StackExchange. redis:
System.PlatformNotSupportedException: Operation is not supported on this platform.at System.Net.Sockets.SocketPal.Ioctl(SafeCloseSocket handle, Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue, Int32& optionLength)at System.Net.Sockets.SocketPal.Ioctl(SafeCloseSocket handle, Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue, Int32& optionLength)at System.Net.Sockets.Socket.IOControl(Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue)at StackExchange.Redis.SocketManager.SetFastLoopbackOption(Socket socket)
After research, we found that the. Net code hosted on Github contains the following section:
public static SocketError Ioctl(SafeCloseSocket handle, int ioControlCode, byte[] optionInValue, byte[] optionOutValue, out int optionLength){ // TODO: can this be supported in some reasonable fashion? throw new PlatformNotSupportedException();}
OK. It seems that although the implementation is prepared, it is not implemented yet. Now, you can start and modify the StackExchange. Redis code on your own. Changed:
... internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log) { var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { SetFastLoopbackOption(socket); } catch { } socket.NoDelay = true; try { ...
This is a temporary bypass solution, so that the asp. net5 program that you can run on Linux at least can smoothly connect to Redis. The disadvantage is that Loopback is not used to connect to the local Redis service, which makes the performance improvement of the local connection not reflected. I believe that net5's Sockets basic class will be further improved. This performance improvement will continue. Technorati Tag: ASP. NET5,. NET cross-platform, Redis, Corefx, StackExchange. Redis