【问题标题】:What does IRedisClient.As<T>() do behind the scenes?IRedisClient.As<T>() 在幕后做了什么?
【发布时间】:2017-01-27 03:49:05
【问题描述】:

我目前正在通过以下方式使用 c# ServiceStack RedisClient

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

我想知道这在幕后会发生什么? Redis 如何知道哪种类型与哪个键相关?它不能检查每种类型的匹配,这太慢了。当我设置对象时,我自己将其序列化并将其添加为字符串 - 所以它也无法从那里知道。

它工作得非常好,我什至尝试更改类型的属性和命名空间,看看会发生什么,它只是处理它。有谁知道如何

【问题讨论】:

标签: c# redis servicestack.redis


【解决方案1】:

如果有疑问,您可以直接read the source code,即它实际上只是返回一个 Typed Generic RedisClient:

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

RedisTypedClient 的源代码显示了它的确切作用,this existing answer explains roughly how it works

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 2019-05-21
    • 2016-03-19
    • 1970-01-01
    • 2010-11-21
    相关资源
    最近更新 更多