1

im using redis with servicestack.

i get client with this code :

        public RedisClient GetClient()
        {
            RedisManagerPool redisManager = new RedisManagerPool();
            RedisClient client = (RedisClient)redisManager.GetClient();
            client.Db = AppConst.RedisServer;
            return client;
        }

everything go fine but suddenly my clients grown up and i get some errors and look like redis-server proccess down, make me restart server :

max number of clients reached

Could not resolve master instance within 10000ms RetryTimeout

and i set maxclient more value but still get this error but max number of.... replaced with localhost:6379

stacktrace :

at ServiceStack.Redis.RedisResolver.CreateRedisClient(RedisEndpoint config, Boolean master) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Redis/src/ServiceStack.Redis/RedisResolver.cs:line 110 at ServiceStack.Redis.RedisManagerPool.GetClient(Boolean forAsync) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Redis/src/ServiceStack.Redis/RedisManagerPool.cs:line 222

at ServiceStack.Redis.RedisNativeClient.AssertConnectedSocket() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Redis/src/ServiceStack.Redis/RedisNativeClient_Utils.cs:line 292 at ServiceStack.Redis.RedisNativeClient.AssertServerVersionNumber() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Redis/src/ServiceStack.Redis/RedisNativeClient_Utils.cs:line 56 at ServiceStack.Redis.RedisClient.GetServerRole() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Redis/src/ServiceStack.Redis/RedisClient.cs:line 1119 at ServiceStack.Redis.RedisResolver.GetValidMaster(RedisClient client, RedisEndpoint config) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Redis/src/ServiceStack.Redis/RedisResolver.cs:line 118 at ServiceStack.Redis.RedisResolver.CreateRedisClient(RedisEndpoint config, Boolean master) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Redis/src/ServiceStack.Redis/RedisResolver.cs:line 96

i search many times and i try some ways like set maxclients or maxpoolsize even UseIpRateLimiting and... but dont work.

1 Answers1

0

You're using RedisManagerPool incorrectly, all Redis Client Managers need to either be registered as a singleton or maintained in a static variable so all client instances are resolved from the same Pool.

If you're not using an IOC, maintain a static instance of RedisManagerPool, e.g:

static RedisManagerPool redisManager = new RedisManagerPool();

public RedisClient GetClient()
{
    RedisClient client = (RedisClient)redisManager.GetClient();
    client.Db = AppConst.RedisServer;
    return client;
}

mythz
  • 141,670
  • 29
  • 246
  • 390
  • thank u, i do changes and upload it,im waiting to see result,It happened before that there was no problem for a few days, but the error appeared again. If I am sure that the problem is solved soon, I will put a green tick and you saved my life – Vahid Hossein Pour Feb 05 '23 at 15:46
  • :(( not work, its happend again – Vahid Hossein Pour Feb 05 '23 at 16:55
  • Make clients are always disposed after usage, e.g. whenever you can resolve it with: `using var redis = GetClient();` – mythz Feb 05 '23 at 22:34
  • i do this with using – Vahid Hossein Pour Feb 06 '23 at 03:50
  • See [troubleshooting](https://docs.servicestack.net/redis/troubleshooting) for avoiding common issues, e.g. I would add `RedisConfig.AssertAccessOnlyOnSameThread = true;` to ensure your clients are being properly disposed before being reused. If you still can't find the issue and can publish a standalone repro on GitHub I can take a look. – mythz Feb 06 '23 at 04:21
  • my problem not solved yet :((((( when this problem happening i open redis-cli and info clients i get this error "The disk is in use or locked by another process" its hang, until i recycle app pool – Vahid Hossein Pour Feb 22 '23 at 21:32