intelligenthack / intelligentcache

A distributed cache backed by Redis
MIT License
18 stars 2 forks source link

[RedisCache] Exception throw when using ProtobufSerializer #29

Closed ianselmi closed 3 years ago

ianselmi commented 3 years ago

When we try to use ProtobufSerializer with GetSet method the library throws the exception "The magic number in Gzip header is not correct"

this is an example

using IntelligentHack.IntelligentCache;
using ProtoBuf;
using StackExchange.Redis;
using System;

namespace RedisCacheSample
{
      class Program
      {
          static void Main(string[] args)
          {        
              var redisCache = new RedisCache(ConnectionMultiplexer.Connect("redis_cns"), "rd") { Serializer = new ProtobufSerializer()};

              redisCache.GetSet("Key1", () => new Entity { Prop1="test" }, TimeSpan.FromMinutes(1));
              var secondTime = redisCache.GetSet("Key1", () => new Entity { Prop1="test" }, TimeSpan.FromMinutes(1));
          }
      }
      [ProtoContract]
      public class Entity
      {
          [ProtoMember(1)]
          public string Prop1 { get; set; }
      }
}

the problem occurred when the entity is on redis and not the first time. PR #28 is a possible fix

sklivvz commented 3 years ago

fix incoming in #30