Exemple #1
0
        /// <summary>
        /// 获取服务器响应状态
        /// </summary>
        /// <param name="serverId"></param>
        /// <returns></returns>
        public static RedisServerResponseModel GetRedisServerResponse(string serverId)
        {
            RedisServerResponseModel result = null;
            RedisServerModel         model  = RedisServerConfig.RedisServers.FirstOrDefault(p => p.ServerId == serverId);

            if (model != null)
            {
                result = new RedisServerResponseModel()
                {
                    ServerId = serverId
                };
                try
                {
                    var server   = GetRedisServer(model.ServerHost);
                    var pingTime = server.Ping();
                    result.IsConnection = true;
                    result.Status       = "连接成功";
                    result.ResponseTime = Math.Round(pingTime.TotalMilliseconds, 4);
                }
                catch (Exception ex)
                {
                    result.IsConnection = false;
                    result.Status       = $"连接失败,原因:{ex.Message}";
                }
            }
            return(result);
        }
        public ActionResult BaseRedisStatus(string serverId)
        {
            RedisServerModel model = RedisServerConfig.RedisServers.FirstOrDefault(p => p.ServerId == serverId);
            var serverResponse     = RedisServerHelp.GetRedisServerResponse(serverId);

            ViewBag.RedisServer    = model;
            ViewBag.ServerResponse = serverResponse;
            return(PartialView());
        }
Exemple #3
0
        public static IEnumerable <RedisKey> QueryKeys(string serverId)
        {
            RedisServerModel model = RedisServerConfig.RedisServers.FirstOrDefault(p => p.ServerId == serverId);

            if (model != null)
            {
                var        server = GetRedisServer(model.ServerHost);
                RedisValue value  = new RedisValue();
                return(server.Keys(1, value, 100, CommandFlags.None));
            }
            return(null);
        }
Exemple #4
0
 /// <summary>
 /// 获取服务器原始内容信息
 /// </summary>
 /// <param name="serverId"></param>
 /// <returns></returns>
 public static string GetRedisInfoRow(string serverId)
 {
     try
     {
         RedisServerModel model = RedisServerConfig.RedisServers.FirstOrDefault(p => p.ServerId == serverId);
         if (model != null)
         {
             var server       = GetRedisServer(model.ServerHost);
             var infoResponse = server.InfoRaw();
             return(WithInfoRaw(infoResponse));
         }
     }
     catch (Exception ex)
     {
         return($"请求失败,原因:{ex.Message}");
     }
     return("");
 }
Exemple #5
0
        public static Dictionary <RedisKey, RedisValue> QueryValues(string serverId)
        {
            Dictionary <RedisKey, RedisValue> returnDic = new Dictionary <RedisKey, RedisValue>();
            RedisServerModel model = RedisServerConfig.RedisServers.FirstOrDefault(p => p.ServerId == serverId);

            if (model != null)
            {
                IDatabase db   = GetRedisDatabase(model.ServerHost);
                var       keys = QueryKeys(serverId);
                foreach (var item in keys)
                {
                    var RedisValue = db.StringGet(item, CommandFlags.None);
                    returnDic.Add(item, RedisValue);
                }
            }

            return(returnDic);
        }
Exemple #6
0
        /// <summary>
        /// 获取客户端信息
        /// </summary>
        /// <param name="serverId"></param>
        /// <returns></returns>
        public static List <ClientInfoModel> GetClients(string serverId)
        {
            List <ClientInfoModel> clients = new List <ClientInfoModel>();

            try
            {
                RedisServerModel model = RedisServerConfig.RedisServers.FirstOrDefault(p => p.ServerId == serverId);
                if (model != null)
                {
                    var server = GetRedisServer(model.ServerHost);
                    clients = server.ClientList().Select(ConvertClientInfoModel).OrderBy(p => p.Host).ThenBy(p => p.Port).ToList();
                }
            }
            catch (Exception ex)
            {
                //_helper.Error("GetClients方法异常", ex);
            }
            return(clients);
        }
Exemple #7
0
        /// <summary>
        /// 获取服务器信息
        /// </summary>
        /// <param name="serverId"></param>
        /// <returns></returns>
        public static Dictionary <string, Dictionary <string, string> > GetRedisInfo(string serverId)
        {
            Dictionary <string, Dictionary <string, string> > infoResponse = null;

            try
            {
                RedisServerModel model = RedisServerConfig.RedisServers.FirstOrDefault(p => p.ServerId == serverId);
                if (model != null)
                {
                    var server = GetRedisServer(model.ServerHost);
                    infoResponse = server.Info().ToDictionary(p => p.Key, p => p.ToDictionary(x => x.Key, x => x.Value));
                }
            }
            catch (Exception ex)
            {
                //_helper.Error("GetRedisInfo方法异常", ex);
            }
            return(infoResponse);
        }
Exemple #8
0
        public ActionResult RedisServer_GetKeys()
        {
            //ViewBag.ServerName = ServerName;

            var redisServerModel = new RedisServerModel {
                Name = "Redis"
            };

            //ConnectionMultiplexer con = ConnectionMultiplexer.Connect(GetRedisConfigurationString(ServerName));
            //IDatabase cache = con.GetDatabase();

            //ConnectionMultiplexer con = GetRedisConnectionMultiplexer(ServerName);

            IDatabase cache = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetDatabase();

            var endpoints = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetEndPoints(true);
            var server    = CoreServices.RedisConnectionMultiplexers.RedisMultiplexer.GetServer(endpoints[0]);


            foreach (RedisKey key in server.Keys(0))
            {
                RedisType redisKeyType = cache.KeyType(key);

                if (redisKeyType.ToString().ToLower() == "string")
                {
                    redisServerModel.StringKeys.Add(key);
                }
                else if (redisKeyType.ToString().ToLower() == "hash")
                {
                    redisServerModel.HashKeys.Add(key);
                }
            }

            //con.Close();

            return(View(redisServerModel));
        }