ServiceStack.Redis: Unable to Connect: sPort:

757 views
Skip to first unread message

rioja

unread,
Dec 5, 2013, 6:16:46 PM12/5/13
to servic...@googlegroups.com

I regularly get ServiceStack.Redis: Unable to Connect: sPort: 0 or ServiceStack.Redis: Unable to Connect: sPort: 50071 (or another port number).

This appears to happen when our site is busier. Redis itself appears fine, no real increase in CPU or memory usage.

I'm using connection pooling and have tried changing the timeout values without success. Any ideas?

public sealed class RedisConnection
{
    // parameter values are:
    // Config.Settings.RedisPoolSize = 10000
    // Config.Settings.RedisPoolTimeoutSeconds = 2
    // Config.Settings.RemoteCacheServerName = 192.168.10.12
    private static readonly PooledRedisClientManager instance
        = new PooledRedisClientManager(Config.Settings.RedisPoolSize,
                                       Config.Settings.RedisPoolTimeoutSeconds,
                                       new string[] { Config.Settings.RemoteCacheServerName })
        {
            ConnectTimeout = 1500
        };

    static RedisConnection()
    {
    }

    public static PooledRedisClientManager Instance
    {
        get
        {
            return instance;
        }
    }
}

Usage is like this:

public sealed class Caching
{
    public static T GetCacheSingle<T>(string key)
    {
    using (var redisClient = RedisConnection.Instance.GetReadOnlyClient())
    {
            var value = redisClient.Get<byte[]>(key);
            ....
    }
    }
}

alle...@gmail.com

unread,
Mar 26, 2014, 12:18:48 AM3/26/14
to servic...@googlegroups.com
Hi,

I have similar issue before, it was my cache client use a new connection every time to connect to redis and screw up my beloved single thread redis server.

I didn't use the singleton class for my connection but after adjust my apphost code as below the problem gone.

  container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));
          
            //tell repository to resolve redis connection
            container.Register<IRepository>(c => new Repository(c.Resolve<IRedisClientsManager>()));

             // tell cacheclient to use same redis connection
            container.Register<ICacheClient>(c =>
                               (ICacheClient)c.Resolve<IRedisClientsManager>()
                               .GetCacheClient())
                               .ReusedWithin(Funq.ReuseScope.None);


For your singleton class you may want to use lock keyword in your method to see if you could reduce some causes but the error appears your app make redis calls while last call is still open. Maybe worth to check your code to see if your code actually call to redis from different connections.


Regards,
Allen  
Reply all
Reply to author
Forward
0 new messages