3

I'm curently using the c# ServiceStack RedisClient in the following way

   using (var cache = new BasicRedisClientManager(readWriteHosts).ClientFactory.GetClient())
   {
        var r = cache.As<Foo>();
        var myItem = r.GetById(123);
   }

I want to know what happens behind the scenes with this? How does Redis know which type relates to which key? It can't be inspecting each type for a match, that would be too slow. When I set the object, I'm serialising it myself and adding it as string - so it can't know from there either.

It works fantastically, I even tried changing properties and namespaces of the type to see what happens and it just handles it. Does anyone know How?

MartinM
  • 1,736
  • 5
  • 20
  • 33
  • 1
    Well, see for yourself - https://github.com/ServiceStack/ServiceStack.Redis/blob/2b833b6e574067bc94dd5a504cf2fd5d6e7ce12c/src/ServiceStack.Redis/RedisClient.cs – eocron Jan 26 '17 at 17:33

1 Answers1

1

When in doubt you can just read the source code, i.e. it's effectively just returning a Typed Generic RedisClient:

public IRedisTypedClient<T> As<T>()
{
    return new RedisTypedClient<T>(this);
}

Whilst the source code for RedisTypedClient shows exactly what it does, this existing answer explains roughly how it works.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390