Search code examples
c#redisservicestackservicestack.redis

ServiceStack.Redis Service availability


I am trying to figure out how check the availability of the Redis Client. The simple action of calling the client, will give me this information? Is there a better method?

private RedisManagerPool redisPool;
public RedisCacheProviderStatus ServiceStatus()
{
    try
    {
        using (IRedisClient client = redisPool.GetClient())
        {
        }
        return RedisCacheProviderStatus.Available;
    }
    catch (Exception)
    {
        return RedisCacheProviderStatus.NotAvailable;
    }
}

Solution

  • Call a Redis Operation like Ping():

    using (var redis = redisPool.GetClient())
    {
        return ((IRedisNativeClient)redis).Ping()
            ? RedisCacheProviderStatus.Available
            : RedisCacheProviderStatus.NotAvailable;
    }