コード例 #1
0
        public RedisRepositoryBase(ConnectionMultiplexer redisConnectionMultiplexer)
        {
            _redisConnectionMultiplexer = redisConnectionMultiplexer;
            _redisDatabase = _redisConnectionMultiplexer.GetDatabase();

            _branches = new List <IRedisBranch <T> >();
            IRedisBranch <T> dataBranch = new RedisBranch <T>();

            dataBranch.SetBranchId(BRANCH_DATA);
            dataBranch.SetEntityType(typeof(T));
            _branches.Add(dataBranch.GroupBy());

            CreateBranches();
        }
 /// <summary>
 /// Creates branches for each property. These branches are used by query providers. For now, supported types: string, double, bool, DateTime
 /// </summary>
 private void CreateQueryBranches()
 {
     Type[] validPropertyTypes = { typeof(bool), typeof(char),  typeof(byte),  typeof(short),  typeof(ushort),  typeof(int),      typeof(uint),
                                   typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(decimal), typeof(DateTime), typeof(string),
                                   typeof(Enum) };
     if (Attribute.IsDefined(typeof(T), typeof(RedisQueryableAttribute)))
     {
         foreach (PropertyInfo property in typeof(T).GetProperties())
         {
             IBranch <T> queryBranch = new RedisBranch <T>();
             queryBranch.SetBranchId($"{BRANCH_QUERY_PREFIX}_{property.Name}");
             if ((validPropertyTypes.Contains(property.PropertyType) || property.PropertyType.IsEnum) &&
                 !property.IsDefined(typeof(IgnoreDataMemberAttribute), true) &&
                 property.Name != "Id")
             {
                 ((IBranchInternal <T>)queryBranch).QueryBy(property.Name);
                 AddBranch(queryBranch);
             }
         }
     }
 }