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


C# IDatabase.KeyExists方法代码示例

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


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

示例1: UpdateExpire

 public static void UpdateExpire(IDatabase database, string id, TimeSpan timeout)
 {
     var keys = new[] { id, GetHashKey(id) };
     foreach (var key in keys.Where(key => database.KeyExists(key)))
     {
         database.KeyExpire(key, timeout);
     }
 }
开发者ID:jango2015,项目名称:Distributed,代码行数:8,代码来源:RedisSessionStateStoreProvider.cs

示例2: Read

        public override object Read(object obj, Type objType, IDatabase redisDatabase, string id, PropertyInfo basePropertyInfo,
            LimitObject limits = null)
        {
            var setKey = new RedisKeyObject(basePropertyInfo, id);

            // TODO Workon RedisBackup

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

            var targetType = GetTarget(obj).GetType();

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

            //var method = objType.GetMethod("Add", BindingFlags.DeclaredOnly, null, new[] { itemType }, null);
            var method = objType.GetMethods()
                .SingleOrDefault(x => x.Name.Equals("Add") && x.ReturnType == typeof (bool));

            if (itemType != null && (itemType.GetInterfaces().Contains(typeof (IRedisObject)) || typeof (IRedisObject) == itemType))
            {
                List<RedisValue> retList;

                // TODO add limits to sets (for now we just grab everything)
                if (limits != null)
                {
                    retList = redisDatabase.SortedSetRangeByScore(setKey.RedisKey, limits.StartLimit, limits.EndLimit, Exclude.None, limits.Order, limits.SkipLimit, limits.TakeLimit).ToList();
                }
                else
                {
                    retList = redisDatabase.SortedSetRangeByRank(setKey.RedisKey).ToList();
                }

                foreach (var ret in retList)
                {
                    if (!redisDatabase.KeyExists((string) ret))
                    {
                        redisDatabase.SortedSetRemove(setKey.RedisKey, (string)ret);
                        continue;
                    }

                    var key = ret.ParseKey();

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

                    var t = method.Invoke(obj, new[] { newProxy as IRedisObject });
                }
            }
            return obj;
        }
开发者ID:DemgelOpenSource,项目名称:DemgelRedis,代码行数:59,代码来源:SetHandler.cs

示例3: Exists

 /// <summary>
 /// Determines if the key exists.
 /// </summary>
 /// <param name="database">
 /// The database where the query will be performed. This is passed so that we can reuse the same database to
 /// perform multiple bitwise operations. Doing this with the same connection will guarantee that performance
 /// is good.
 /// </param>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <returns>
 /// True if the key exists.
 /// </returns>
 public static bool Exists(IDatabase database, RedisKey key)
 {
     return database.KeyExists(key);
 }
开发者ID:JesseBuesking,项目名称:BB.Caching,代码行数:18,代码来源:BitwiseAnalytics.cs

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