bulk creating keys in Redis C# - SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
<p>I'm bulk creating keys in Redis dB under multi-threading environment for some reason in my ASP.NET MVC Web Application.<br />
And I'm using <a href="https://github.com/ServiceStack/ServiceStack.Redis" rel="nofollow noreferrer">ServiceStack.Redis</a> for redis client.</p>
<p>I created a static class for all required redis operations i.e. put,get..<br />
In that static class I'm creating a new instance for redis for each call  which is being disposed once the call finishes (using <em>using</em>)<br />
<strong>Code goes like this:</strong></p>
<pre><code>for (int i = 0; i &lt; 100000; i++)
                {
                    using (RedisClient Client = new RedisClient(_ReplicaHost))
                    {
                        Client.AddItemToSet(key, value);
                    } 
                }
</code></pre>
<p>However, after some time I get following error:</p>
<pre><code>ServiceStack.Redis.RedisException: could not connect to redis Instance at xxx-xxx.xxxx.0001.use1.cache.amazonaws.com:6379 ---&gt; System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted xxx.xx.x.xxx:6379
   at System.Net.Sockets.Socket.Connect(IPAddress[] addresses, Int32 port)
   at System.Net.Sockets.Socket.Connect(String host, Int32 port)
   at ServiceStack.Redis.RedisNativeClient.Connect()
</code></pre>
<p><strong>I looked over the net and found the possible reason is exhaustion of sockets</strong> (<a href="https://blogs.msdn.microsoft.com/dgorti/2005/09/18/only-one-usage-of-each-socket-address-protocolnetwork-addressport-is-normally-permitted/" rel="nofollow noreferrer">reference</a>)</p>
<p>Since the application is running under multi-threading environment I have to use either of the <code>PooledRedisClientManager</code>  or <code>BasicRedisClientManager</code> but I am not sure which one to pick in my case and how to implement that there shouldn't be any issue of exhaustion of sockets regardless of multiple operations.</p>
<p><em>What should be the correct approach/solution?</em></p>