ServiceStack Redis Error

We have a problem with ServiceStack Redis which sometime it thows Exception

"ServiceStack.Redis.RedisResponseException: Unknown reply on integer response: 123"ChannelId":154258,"ChannelType":3,"ChannelBranch":49296,"RetailerId":686325,"BasePriceBookId":0,"Id":240528,"NextRun":"\/Date(1597277234486+0700)\/","LastSync":"\/Date(1597985428021+0700)\/","IsRunning":true,"Type":1}
   at ServiceStack.Redis.RedisNativeClient.ReadLong()
   at ServiceStack.Redis.RedisNativeClient.SendReceive[T](Byte[][] cmdWithBinaryArgs, Func`1 fn, Action`1 completePipelineFn, Boolean sendWithoutRead)
   at ServiceStack.Redis.RedisClient.RegisterTypeId(String typeIdsSetKey, String id)
   at ServiceStack.Redis.Generic.RedisTypedClient`1.Store(T entity)
   at KiotViet.OmniChannel.ScheduleService.Impls.ScheduleService.AddOrUpdate(Byte channelType, Byte scheduleType, ScheduleDto dto, Boolean isUpdateLastSync) in /src/Shared/xxx.OmniChannel.ScheduleService/Impls/ScheduleService.cs:line 149"

The code is below

method AddOrUpdate

GetById method

public T GetById(object id, IRedisTypedClient<T> client)
    return client.GetById(id);

AddOrUpdate method

public virtual void AddOrUpdate(T t, IRedisTypedClient<T> client)

AddItemToSet method

public void AddItemToSet(string key, string value, IRedisClient redisClient)
      if (!redisClient.SetContainsItem(key, value))
      redisClient.AddItemToSet(key, value);

ClientManager is an IRedisClientsManager which is thread safe
protected IRedisClientsManager ClientsManager;

The Exception seems happen due to use RedisClient in multiple threads. However look at the code it is not possible though

Please help me on this. we get quite a lot of this issue on our production.

See the docs on Debugging Data Corruption Issues which is the result of using the same redis client connection concurrently on multiple threads. The callstack of the Exception generally isn’t where the client is improperly used. See Avoiding Concurrent Usage issues for things to look out for.

Of course if you can provide a stand-alone repro I can run locally to repro the issue I’ll be able to identify the cause.

thank you,

I think I found the cause. there is a method which create a RedisLock then dispose the RedisClient which return to the pool and available for another request.

public IDisposable AcquireLock(string key, TimeSpan timeOut)
    using (var cli = _redisClients.GetClient())
        return cli.AcquireLock(key, timeOut);
    return null;
1 Like