CacheResponse RedisResponseException: Zero length response

On a Windows Service with selfhosting
ServiceStack 5.0.2

Thre is Service that is cached with [CacheResponse(Duration = 5)] that transform data from another Service that has [CacheResponse(Duration = 3)]

2018-06-08 10:43:53,438 ERROR [80] ServiceStack.ServiceStackHost - ServiceBase<TRequest>::Service Exception
ServiceStack.Redis.RedisResponseException: Zero length response
   at ServiceStack.Redis.RedisNativeClient.ParseSingleLine(String r)
   at ServiceStack.Redis.RedisNativeClient.SendReceive[T](Byte[][] cmdWithBinaryArgs, Func`1 fn, Action`1 completePipelineFn, Boolean sendWithoutRead)
   at ServiceStack.Redis.RedisNativeClient.SendExpectData(Byte[][] cmdWithBinaryArgs)
   at ServiceStack.Redis.RedisClient.<>c__DisplayClass130_0`1.<Get>b__0(RedisClient r)
   at ServiceStack.Redis.RedisClient.Exec[T](Func`2 action)
   at ServiceStack.Redis.RedisClientManagerCacheClient.Get[T](String key)
   at ServiceStack.CacheResponseExtensions.<HandleValidCache>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ServiceStack.CacheResponseAttribute.<ExecuteAsync>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at ServiceStack.Host.ServiceRunner`1.<ExecuteAsync>d__13.MoveNext()

Both services uses the same redis for caching

The redis connection:

string[] redisSentinelHosts = AppSettings.RedisSentinelHosts();
string masterName = AppSettings.RedisSentinelMasterName();

var sentinel = new RedisSentinel(redisSentinelHosts, masterName);
sentinel.HostFilter = (host) => $$"{host}?db={database}";

// Auto-Register Redis
container.Register<IRedisClientsManager>(c => sentinel.Start());

I have no specific configuration for cache

container.RegisterAs<MemoryCacheClient, ICacheClient>("memory");

If you register Redis it assumes you also want to use that as a cache. If you want to use the In Memory for cached responses you can annotate your attributes with:

[CacheResponse(Duration = 5, LocalCache = true)]

ServiceStack doesn’t use named dependencies, if you want to get ServiceStack to use a local memory cache for ICacheClient you can register it with:

container.Register<ICacheClient>(new MemoryCacheClient());

As for the error that could be due to the Redis Clients not being properly disposed all shared across threads. The RedisClient instances aren’t thread safe and should only be used in the thread that retrieved it from the pool and disposed immediately after use, e.g:

using (var redis = redisManager.GetClient())
{
    // Use redis
}

Using base.Redis in your Services is ok as well as the RedisClient instance is disposed immediately after the Service is executed.

I will try setting the LocalCache property.

I never use the Redis property of the Service, whenever we use redis I have a IRedisClientsManager RedisClientsManager { get; set; } in each service that uses redis and it is done inside a using scope

using (var redis = RedisClientsManager.GetClient()) { ... }

or readonly client with

using (var redis = RedisClientsManager.GetReadOnlyClient()) { ... }

The named ICacheClient registered is used to specific code that retrieve it with a container.ResolveNamed<ICacheClient>("memory").

The CacheResponse will use the RedisCacheClient without explicit registration?
Because I registered a RedisClientManager?

Yes, it’s assumed when registering an IRedisClientsManager you want to use it as a cache, it can be overridden by registering an explicit ICacheClient:

container.Register<ICacheClient>(new MemoryCacheClient());