redis - 透明的 Redis Dal 与 serviceStack Redis

标签 redis servicestack

是的,我在这里有另一个奇怪的问题:)

我尝试实现透明的 Redis 数据访问层。

我将加载 N*1 和 1*1 关系 Eagerly,N*N 和 1*N 关系 Lazily。

public class User
{
   public long CityId {get;set;} 

   [EagerLoading]
   [IgnoreDataMember]
   public City {get;set;}
}

public class City
{
  public ICollection<long> UserIds {get;set;}

  [LazyLoading]
  [IgnoreDataMember] 
  public ICollection<User> Users{get;set;}
}

CUD操作(Create,Update,Delete)没有问题。我可以存储完整的对象层次结构。

但我需要非类型化的 Get 方法来检索对象。

public class GenericRedisRepository
{
     public object Get(string objectUrn)
     {
        using (var r = RedisManager.GetReadOnlyClient())
        {
            var pocoObject=r.GetObject(objectUrn); // I COULD NOT FIND THIS METHOD
            foreach (var property in ReflectionHelper.GetEagerLoadingProperties(pocoObject))
            {
                // Fixup relations and load all EagerLoading properties recursively
            } 
        }
     }
}

任何想法或替代方式..

最佳答案

抱歉来晚了。我想知道为什么您坚持使用属性而不是本质上未序列化/反序列化的方法:

public class User
{
   public long Id { get; set; }
}

public class City
{
  public IEnumerable<long> UserIds { get; set; }

  public IEnumerable<User> GetUsers()
  {
      using (var userData = redis.As<User>())
          return userData.GetByIds(UserIds);
  }
}

这样您就可以在真正需要用户时通过调用 GetUsers() 来延迟加载用户:

var city = redis.As<City>().GetById(id);
...
var users = city.GetUsers();

关于redis - 透明的 Redis Dal 与 serviceStack Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13522505/

相关文章:

node.js - NodeRedis client.multi() hgetall 性能

serialization - Redis 重组序列化字符串失败 - UTF-8

macos - 有更新redis的命令吗?

ServiceStack CORS 功能

servicestack - ServiceStack MiniProfiler 能否显示 SQL 参数值,而不仅仅是绑定(bind)的参数名称?

amazon-web-services - Redis 6 可以利用多核 CPU 吗?

ruby - resque 被 worker job 阻塞

c# - 使用 mvc4 Controller 调用 ServiceStack 服务时出错

c# - 在 Xamarin.iOS 上使用 ServiceStack.Client

ServiceStack.OrmLite - 如何从外键查找中包含字段?