Exemple #1
0
        public IQueryable <T> GetAll <T>(string hash, string value, Expression <Func <T, bool> > filter)
        {
            var filtered = _redisClient.GetAllEntriesFromHash(hash).Where(c => c.Value.Equals(value, StringComparison.InvariantCultureIgnoreCase));
            var ids      = filtered.Select(c => c.Key);

            var ret = _redisClient.As <T>().GetByIds(ids).AsQueryable()
                      .Where(filter);

            return(ret);
        }
Exemple #2
0
        public static T GetHashEntity <T>(this IRedisClient client, string key) where T : class, new()
        {
            var entity = new T();

            PropertyInfo[] properties = typeof(T).GetProperties();
            var            values     = client.GetAllEntriesFromHash(key);

            foreach (var property in properties)
            {
                if (property.IsDefined(typeof(HashAttribute), false) && values.ContainsKey(property.Name))
                {
                    var setter = ReappearMember.CreatePropertySetter(property);
                    //这里其实可能有很多类型需要判断
                    if (property.PropertyType.IsValueType)
                    {
                        setter(entity, Convert.ToInt32(values[property.Name]));
                    }
                    else
                    {
                        setter(entity, values[property.Name]);
                    }
                }
            }
            return(entity);
        }
Exemple #3
0
 /// <summary>
 /// 获取所有hashid数据集的key/value数据集合
 /// </summary>
 public Dictionary <string, string> GetAllEntriesFromHash(string hashid)
 {
     using (IRedisClient Core = CreateRedisClient())
     {
         return(Core.GetAllEntriesFromHash(hashid));
     }
 }
Exemple #4
0
        /// <summary>
        ///     获取指定Hash包含的所有子项集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hashKey"></param>
        /// <returns></returns>
        public static IDictionary<string, T> GetItemFormHash<T>(string hashKey)
        {
            IDictionary<string, T> result = new Dictionary<string, T>();
            using (IRedisClient client = GetClient())
            {
                if (!client.ContainsKey(hashKey))
                    return null;
                Dictionary<string, string> strValues = client.GetAllEntriesFromHash(hashKey);

                if (strValues == null || strValues.Count == 0)
                    return null;

                foreach (var item in strValues)
                {
                    try
                    {
                        result.Add(item.Key, TypeSerializer.DeserializeFromString<T>(item.Value));
                    }
                    catch
                    {

                    }
                }
                return result;
            }
        }
Exemple #5
0
 // 获取所有hashid数据集的key/value数据集合
 public static Dictionary <string, string> GetAllEntriesFromHash(string hashId)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         return(redis.GetAllEntriesFromHash(hashId));
     }
 }
Exemple #6
0
        private void btnReadAllItems_Click(object sender, EventArgs e)
        {
            using (IRedisClient client = getClient())
            {
                Dictionary <string, string> allItems = client.GetAllEntriesFromHash(txtHashName.Text);

                dgvEntries.DataSource = allItems.ToList();
            }
        }
Exemple #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public Dictionary <string, string> HGetAll(string key)
 {
     using (_redis = GetClient())
     {
         lock (AccessLock)
         {
             return(_redis.GetAllEntriesFromHash(ConvertKey(key)));
         }
     }
 }
        private static IReadOnlyDictionary <string, object> GetEntityFromContainer(IRedisClient client,
                                                                                   string rowKey, RepositoryEntityMetadata metadata)

        {
            try
            {
                var containerEntityProperties = client.GetAllEntriesFromHash(rowKey);
                if (containerEntityProperties == null || containerEntityProperties.Count == 0)
                {
                    return(default);
 /// <summary>
 /// 依据HashId获取数据
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="hashId">HashId</param>
 /// <param name="dataKey">关键码值</param>
 /// <returns>IQueryable</returns>
 public IQueryable <T> GetAll <T>(string hashId, string dataKey)
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         var _filtered = redisClient.GetAllEntriesFromHash(hashId).Where(c => c.Value.Equals(dataKey, StringComparison.InvariantCultureIgnoreCase));
         var _ids      = _filtered.Select(c => c.Key);
         return(redisClient.As <T>().GetByIds(_ids).AsQueryable());
     }
 }
        public NotificationMessageDto GetDataForMessage(string key)
        {
            var fullKey = key + ":" + MsgPostfix;
            Dictionary <String, String> data = _redis.GetAllEntriesFromHash(fullKey);

            return(new NotificationMessageDto
            {
                Message = data["message"],
                CreatedAt = DateTime.Parse(data["createdAt"]).ToUniversalTime(),
                Creator = data["creator"]
            });
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hashId"></param>
        /// <returns></returns>
        public static Dictionary <string, string> GetHash(string hashId)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            using (IRedisClient redis = RedisManager.GetClient())
            {
                dict = redis.GetAllEntriesFromHash(hashId);

                redis.Dispose();
            }
            return(dict);
        }
        void CheckIndex()
        {
            WithIndexLock(() =>
            {
                var map = client.GetAllEntriesFromHash(resourceIndexKey);

                foreach (var entry in map)
                {
                    if (!File.Exists(entry.Value))
                    {
                        Console.Error.WriteLine("Resource: " + entry.Key + " doesn't exist; Deleting from index.");
                        client.RemoveEntryFromHash(resourceIndexKey, entry.Key);
                    }
                }
            });
        }
    /// <summary>
    /// 鍙栦竴涓狧ash鐨勬墍鏈夊€?
    /// </summary>
    /// <param name="key"></param>
    /// <param name="poolType"></param>
    /// <returns></returns>
    public static Dictionary <string, string> HGetAll(string key, RedisPoolType poolType)
    {
        Dictionary <string, string> values = new Dictionary <string, string>();
        PooledRedisClientManager    pool   = GetRedisPool(poolType);
        IRedisClient redis = pool.GetReadOnlyClient();

        try
        {
            values = redis.GetAllEntriesFromHash(key);
        }
        catch { throw; }
        finally
        {
            if (redis != null)
            {
                redis.Dispose();
            }
        }
        return(values);
    }
Exemple #14
0
        public JobDetailsDto JobDetails(string jobId)
        {
            var job = _redis.GetAllEntriesFromHash(String.Format("hangfire:job:{0}", jobId));

            if (job.Count == 0)
            {
                return(null);
            }

            var hiddenProperties = new[]
            { "Type", "Method", "ParameterTypes", "Arguments", "State", "CreatedAt" };

            var historyList = _redis.GetAllItemsFromList(
                String.Format("hangfire:job:{0}:history", jobId));

            var history = historyList
                          .Select(JobHelper.FromJson <Dictionary <string, string> >)
                          .ToList();

            var stateHistory = new List <StateHistoryDto>(history.Count);

            foreach (var entry in history)
            {
                var dto = new StateHistoryDto
                {
                    StateName = entry["State"],
                    Reason    = entry.ContainsKey("Reason") ? entry["Reason"] : null,
                    CreatedAt = JobHelper.FromStringTimestamp(entry["CreatedAt"]),
                };

                // Each history item contains all of the information,
                // but other code should not know this. We'll remove
                // unwanted keys.
                var stateData = new Dictionary <string, string>(entry);
                stateData.Remove("State");
                stateData.Remove("Reason");
                stateData.Remove("CreatedAt");

                dto.Data = stateData;
                stateHistory.Add(dto);
            }

            // For compatibility
            if (!job.ContainsKey("Method"))
            {
                job.Add("Method", null);
            }
            if (!job.ContainsKey("ParameterTypes"))
            {
                job.Add("ParameterTypes", null);
            }

            return(new JobDetailsDto
            {
                Job = TryToGetJob(job["Type"], job["Method"], job["ParameterTypes"], job["Arguments"]),
                CreatedAt =
                    job.ContainsKey("CreatedAt") ? JobHelper.FromStringTimestamp(job["CreatedAt"]) : (DateTime?)null,
                Properties = job.Where(x => !hiddenProperties.Contains(x.Key)).ToDictionary(x => x.Key, x => x.Value),
                History = stateHistory
            });
        }
Exemple #15
0
 public IDictionary <string, string> HGetAll(string chave)
 {
     return(redisClient.GetAllEntriesFromHash(chave));
 }
 /// <summary>
 /// 获取所有hashid数据集的key/value数据集合
 /// </summary>
 public Dictionary <string, string> GetAllEntriesFromHash(string hashid)
 {
     return(RedisClient.GetAllEntriesFromHash(hashid));
 }
        public (string, string) GetCompanyBySymbol(string symbol)
        {
            var item = redisClient.GetAllEntriesFromHash(symbol);

            return(item.Values.ToList()[0], item.Values.ToList()[1]);
        }
        public void ProcessSession(string username)
        {
            //Prepare some data for the user
            Console.WriteLine("Processing Username: {0}", username);
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            byte[] image = redis.Get <byte[]>($"siege:{username}:icon");
            if (image == null || image.Length == 0)
            {
                return;
            }

            //The best operator
            Operator bestOperator = null;

            //Get the users current operator and image
            var currentOperator = GetCurrentOperator(username);

            Console.WriteLine("Current Operator:\t{0}", currentOperator?.Name);

            //Find the best operator
            using (var sourceImage = new MagickImage(image))
            {
                //Get all the other operators
                var allOperators = redis.GetAllEntriesFromHash("siege:cache");

                //Check the current operator
                if (currentOperator != null && allOperators.TryGetValue(currentOperator.Name, out var cacheByteString))
                {
                    bestOperator       = currentOperator;
                    bestOperator.Match = CompareSourceWithCache(sourceImage, cacheByteString);

                    //Make sure the match is actually valid.
                    if (bestOperator.Match < bestOperator.MinimumMatch)
                    {
                        bestOperator = null;
                    }
                }

                //If we already have a valid good operator, then skip the checks,
                //  otherise iterate over every value, and check if its better
                if (bestOperator == null)
                {
                    Console.WriteLine("- Check All");
                    foreach (var keypair in allOperators)
                    {
                        double minimum = Weights.GetWeight(keypair.Key);
                        double match   = CompareSourceWithCache(sourceImage, keypair.Value);

                        if (match >= minimum && (bestOperator == null || bestOperator.Match < match))
                        {
                            bestOperator = new Operator(keypair.Key, minimum)
                            {
                                Match = match
                            }
                        }
                        ;
                    }
                }
            }

            //Tada we found someone, maybe
            if (bestOperator != null)
            {
                Console.WriteLine("Best Operator:\t{0} at {1}% (min: {2})", bestOperator.Name, bestOperator.Match * 100, bestOperator.MinimumMatch);
                SetCurrentOperator(username, bestOperator);
            }

            Console.WriteLine("Completed:\t{0}ms", stopwatch.ElapsedMilliseconds);
            Console.WriteLine("=============================");
        }
        private void treeKeys_AfterSelect(object sender, TreeViewEventArgs e)
        {
            string key         = GetFullKey(e.Node);
            bool   containsKey = RedisClient.ContainsKey(key);

            if (containsKey)
            {
                this.table.Clear();
                this.txtHashKey.Text = this.txtHashValue.Text = string.Empty;

                RedisKeyType keyType = RedisClient.GetEntryType(key);
                this.lblKey.Text = keyType.ToString();
                this.txtKey.Text = key;
                int row = 0;
                switch (keyType)
                {
                case RedisKeyType.Hash:
                    this.gridHash.Visible   = true;
                    this.column_key.Visible = this.column_value.Visible = true;
                    var hash = RedisClient.GetAllEntriesFromHash(key);
                    foreach (var item in hash)
                    {
                        table.Rows.Add(row + 1, item.Key, item.Value);
                        row++;
                    }
                    break;

                case RedisKeyType.List:
                    this.gridHash.Visible     = true;
                    this.column_key.Visible   = false;
                    this.column_value.Visible = true;
                    var list = RedisClient.GetAllItemsFromList(key);
                    for (; row < list.Count; row++)
                    {
                        table.Rows.Add(row + 1, "", list[row]);
                    }
                    break;

                case RedisKeyType.None:
                    break;

                case RedisKeyType.Set:
                    this.gridHash.Visible     = true;
                    this.column_key.Visible   = true;
                    this.column_value.Visible = false;
                    var set = RedisClient.GetAllItemsFromSet(key);
                    foreach (var item in set)
                    {
                        table.Rows.Add(row + 1, item, "");
                        row++;
                    }
                    break;

                case RedisKeyType.SortedSet:
                    this.gridHash.Visible = true;
                    var sortedSet = RedisClient.GetAllWithScoresFromSortedSet(key);
                    foreach (var item in sortedSet)
                    {
                        table.Rows.Add(row + 1, item.Key, item.Value);
                        row++;
                    }
                    break;

                case RedisKeyType.String:
                    this.txtHashValue.Text = RedisClient.GetValue(key);
                    break;

                default:
                    break;
                }
            }
        }