当前位置: 首页>>代码示例>>C#>>正文


C# IDatabase.HashGetAll方法代码示例

本文整理汇总了C#中IDatabase.HashGetAll方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.HashGetAll方法的具体用法?C# IDatabase.HashGetAll怎么用?C# IDatabase.HashGetAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDatabase的用法示例。


在下文中一共展示了IDatabase.HashGetAll方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Restore

 public static void Restore(AddProductToOrder c, IDatabase db, Guid key)
 {
     db.HashGetAll(key).Tap(hash =>
         {
             c.OrderId = hash.GetInt("OrderId");
             c.ProductId = hash.GetInt("ProductId");
         });
 }
开发者ID:wallymathieu,项目名称:redis-studies,代码行数:8,代码来源:AddProductToOrderMap.cs

示例2: Restore

 public static void Restore(AddProductCommand c,IDatabase db, Guid key)
 {
     db.HashGetAll(key).Tap(hash =>
         {
             c.Id = hash.GetInt("Id");
             c.Version = hash.GetInt("Version");
             c.Cost = hash.GetFloat("Cost");
             c.Name = hash.GetString("Name");
         });
 }
开发者ID:wallymathieu,项目名称:redis-studies,代码行数:10,代码来源:AddProductCommandMap.cs

示例3: Restore

 public static void Restore(AddOrderCommand c,IDatabase db, Guid key)
 {
     db.HashGetAll(key).Tap(hash =>
         {
             c.Id = hash.GetInt("Id");
             c.Version = hash.GetInt("Version");
             c.Customer = hash.GetInt("Customer");
             c.OrderDate = new DateTime(hash.GetLong("OrderDate"));
         });
 }
开发者ID:wallymathieu,项目名称:redis-studies,代码行数:10,代码来源:AddOrderCommandMap.cs

示例4: Restore

 public static void Restore(AddCustomerCommand c, IDatabase db, Guid key)
 {
     db.HashGetAll(key).Tap(hash =>
         {
             c.Id = hash.GetInt("Id");
             c.Version = hash.GetInt("Version");
             c.Firstname = hash.GetString("Firstname");
             c.Lastname = hash.GetString("Lastname");
         });
 }
开发者ID:wallymathieu,项目名称:redis-studies,代码行数:10,代码来源:AddCustomerCommandMap.cs

示例5: Read

 public static Command Read(IDatabase db, Guid key)
 {
     var entries = db.HashGetAll(key);
     var type = entries.GetString("Type");
     var command = RedisExtensions.getCommand[type];
     var instance = (Command)Activator.CreateInstance(command);
     instance.SequenceNumber = entries.GetInt("SequenceNumber");
     Switch.On(instance)
         .Case((AddCustomerCommand c) => AddCustomerCommandMap.Restore(c, db, key))
         .Case((AddOrderCommand c) => AddOrderCommandMap.Restore(c, db, key))
         .Case((AddProductCommand c) => AddProductCommandMap.Restore(c, db, key))
         .Case((AddProductToOrder c) => AddProductToOrderMap.Restore(c, db, key))
         .ElseFail()
         ;
     return instance;
 }
开发者ID:wallymathieu,项目名称:redis-studies,代码行数:16,代码来源:AppendToRedis.cs

示例6: Create

            public static RedisSessionStateStore Create(IDatabase database, string id, int timeout)
            {
                var timeoutSpan = TimeSpan.FromMinutes(timeout);
                database.StringSet(id, JsonConvert.SerializeObject(new { Timeout = timeout }), timeoutSpan);

                var hashKey = GetHashKey(id);
                var entrys = database.HashGetAll(hashKey);
                foreach (var entry in entrys)
                    database.HashDelete(hashKey, entry.Name);

                return new RedisSessionStateStore(database, id, TimeSpan.FromMinutes(timeout), hashKey);
            }
开发者ID:jango2015,项目名称:Distributed,代码行数:12,代码来源:RedisSessionStateStoreProvider.cs

示例7: Read

        public override object Read(object obj, Type objType, IDatabase redisDatabase, string id, PropertyInfo basePropertyInfo, LimitObject limits = null)
        {
            if (id == null)
            {
                throw new Exception("Id can't be null");
            }
            var redisKey = new RedisKeyObject(objType, id);

            RedisObjectManager.RedisBackup?.RestoreHash(redisDatabase, redisKey);
            var ret = redisDatabase.HashGetAll(redisKey.RedisKey);

            // Attempt to set all given properties
            obj = RedisObjectManager.ConvertToObject(obj, ret);

            // Do we continue here if it is a base system class?
            if (!(obj is IRedisObject)) return obj;

            var props = obj.GetType().GetProperties();

            foreach (var prop in props)
            {
                // If value is virtual assume it is lazy
                if (!prop.GetMethod.IsVirtual) continue;
                // Create proxies here
                if (prop.PropertyType.IsSealed) continue;
                if (!prop.PropertyType.IsClass && !prop.PropertyType.IsInterface) continue;
                try
                {

                    // If the target is an IRedisObject we need to get the ID differently
                    string objectKey = null;
                    //RedisValue propKey = new RedisValue();
                    if (prop.PropertyType.GetInterfaces().Any(x => x == typeof(IRedisObject)))
                    {
                        // Try to get the property value from ret
                        RedisValue propKey;
                        if (ret.ToDictionary().TryGetValue(prop.Name, out propKey))
                        {
                            objectKey = propKey.ParseKey();
                            if (prop.GetValue(obj, null) == null)
                            {
                                var pr = RedisObjectManager.GetRedisObjectWithType(redisDatabase, (string)propKey, objectKey);
                                obj.GetType().GetProperty(prop.Name).SetValue(obj, pr);
                            }
                        }
                        else
                        {
                            if (prop.PropertyType.IsInterface)
                            {
                                throw new Exception("Properties of type Interface need to be populated first");
                            }
                            else
                            {
                                object baseObject = prop.GetValue(obj, null) ?? Activator.CreateInstance(prop.PropertyType);
                                var key = new RedisKeyObject(baseObject.GetType(), string.Empty);
                                redisDatabase.GenerateId(key, baseObject, null);
                                objectKey = key.Id;

                                if (!(baseObject is IProxyTargetAccessor))
                                {
                                    var pr = RedisObjectManager.RetrieveObjectProxy(prop.PropertyType, objectKey, redisDatabase,
                                        baseObject, obj);
                                    obj.GetType().GetProperty(prop.Name).SetValue(obj, pr);
                                }
                            }
                        }
                    }
                    else
                    {
                        // Here we try to handle NON redisObjects
                        object baseObject = prop.GetValue(obj, null) ?? Activator.CreateInstance(prop.PropertyType);

                        objectKey = id;

                        if (!(baseObject is IProxyTargetAccessor))
                        {
                            var pr = RedisObjectManager.RetrieveObjectProxy(prop.PropertyType, objectKey, redisDatabase,
                                baseObject, obj);
                            obj.GetType().GetProperty(prop.Name).SetValue(obj, pr);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }

            return obj;
        }
开发者ID:DemgelOpenSource,项目名称:DemgelRedis,代码行数:90,代码来源:RedisObjectHandler.cs

示例8: Read

        public override object Read(object obj, Type objType, IDatabase redisDatabase, string id, PropertyInfo basePropertyInfo, LimitObject limits = null)
        {
            var hashKey = new RedisKeyObject(basePropertyInfo, id);
            RedisObjectManager.RedisBackup?.RestoreHash(redisDatabase, hashKey);

            if (limits != null && limits.RestoreOnly)
            {
                return obj;
            }

            var targetType = GetTarget(obj).GetType();
            Type keyType = null;
            Type itemType = null;

            if (targetType.GetInterfaces().Any(interfaceType => interfaceType.IsGenericType &&
                      interfaceType.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
            {
                if (targetType.GetGenericArguments().Any())
                {
                    keyType = targetType.GetGenericArguments()[0];
                    itemType = targetType.GetGenericArguments()[1];
                }
            }

            var method = objType.GetMethod("Add", new []{keyType, itemType});

            // TODO working on this...

            if (itemType != null && (itemType.GetInterfaces().Contains(typeof(IRedisObject)) || typeof(IRedisObject) == itemType))
            {
                // TODO this all needs to be changed to handle IRedisObjects in a Dictionary, shouldn't be to hard
                List<HashEntry> retlist;

                if (limits != null)
                {
                    if (limits.KeyLimit != null && !limits.KeyLimit.IsNullOrEmpty())
                    {
                        retlist = new List<HashEntry>();
                        foreach (var item in limits.KeyLimit)
                        {
                            var ret = redisDatabase.HashGet(hashKey.RedisKey, (string) item);
                            if (!ret.IsNullOrEmpty)
                            {
                                retlist.Add(new HashEntry((string) item, ret));
                            }
                        }
                    } else if (limits.StartLimit != 0 || limits.TakeLimit != 0)
                    {
                        retlist =
                            redisDatabase.HashScan(hashKey.RedisKey, default(RedisValue), (int)limits.TakeLimit,
                                limits.StartLimit).ToList();
                    }
                    else
                    {
                        retlist = new List<HashEntry>();
                    }
                }
                else
                {
                    retlist = redisDatabase.HashGetAll(hashKey.RedisKey).ToList();
                }

                foreach (var ret in retlist)
                {
                    // We need to check to make sure the object exists (Overhead... it happens)
                    if (!redisDatabase.KeyExists((string) ret.Value))
                    {
                        redisDatabase.HashDelete(hashKey.RedisKey, ret.Name);
                        continue;
                    }

                    var key = ret.Value.ParseKey();

                    var newProxy = RedisObjectManager.GetRedisObjectWithType(redisDatabase, (string)ret.Value, key);

                    method.Invoke(obj, new[] { Convert.ChangeType(ret.Name, keyType), newProxy });
                }
                return obj;
            }

            var retList = redisDatabase.HashGetAll(hashKey.RedisKey);
            foreach (var ret in retList)
            {
                object convertedKey;
                object convertedValue;

                if (!RedisObjectManager.TryConvertFromRedisValue(keyType, ret.Name, out convertedKey)
                    || !RedisObjectManager.TryConvertFromRedisValue(itemType, ret.Value, out convertedValue))
                {
                    throw new Exception("There was an error converting the objects to key/value");
                }

                method.Invoke(obj, new[] {convertedKey, convertedValue});
            }
            return obj;
        }
开发者ID:DemgelOpenSource,项目名称:DemgelRedis,代码行数:96,代码来源:DictionaryHandler.cs


注:本文中的IDatabase.HashGetAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。