.net/c# memcached缓存获取所有缓存键的方法步骤(2)


/// <summary>
        /// 获取服务器端缓存的数据信息
        /// </summary>
        /// <param>要访问的服务列表</param>
        /// <param>此参数的功能暂时无效</param>
        /// <param>此参数的功能暂时无效</param>
        /// <returns>返回信息</returns>
        public static IList<string> GetStats(IList<string> serverArrayList, MemcachedStats statsCommand, string param)
        {
            IList<string> statsArray = new List<string>();
            if (param == null)
                param = "";
            else
            {
                param = param.Trim().ToLower();
            }

            string commandstr = "stats";
            //转换stats命令参数
            switch (statsCommand)
            {
                case MemcachedStats.Reset: { commandstr = "stats reset"; break; }
                case MemcachedStats.Malloc: { commandstr = "stats malloc"; break; }
                case MemcachedStats.Maps: { commandstr = "stats maps"; break; }
                case MemcachedStats.Sizes: { commandstr = "stats sizes"; break; }
                case MemcachedStats.Slabs: { commandstr = "stats slabs"; break; }
                case MemcachedStats.Items: { commandstr = "stats items"; break; }//此处原先是返回stats
                case MemcachedStats.CachedDump:
                    {
                        string[] statsparams = param.Split(' ');
                        if (statsparams.Length == 2)
                            if (param.IsIntArr(' '))// Utils.IsNumericArray(statsparams)
                                commandstr = "stats cachedump  " + param;

                        break;
                    }
                case MemcachedStats.Detail:
                    {
                        if (string.Equals(param, "on") || string.Equals(param, "off") || string.Equals(param, "dump"))
                            commandstr = "stats detail " + param.Trim();

                        break;
                    }
                default: { commandstr = "stats"; break; }
            }

            ArrayList arr = new ArrayList(serverArrayList.ToArray());

            Hashtable stats = MemcachedManager.CacheClient.Stats(arr, commandstr);

            foreach (string key in stats.Keys)
            {
                statsArray.Add("server:__:" + key);//此处也改了
                Hashtable values = (Hashtable)stats[key];
                foreach (string key2 in values.Keys)
                {
                    statsArray.Add(key2 + ":" + values[key2]);
                }
            }
            return statsArray;
        }

3.最后增加如下方法

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgyjy.html