Skip to content

Commit

Permalink
增加console模式~
Browse files Browse the repository at this point in the history
  • Loading branch information
yswenli committed Mar 26, 2019
1 parent a1cfadc commit e48f4e2
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 36 deletions.
34 changes: 34 additions & 0 deletions SAEA.WebRedisManager/Controllers/ConsoleController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/****************************************************************************
*项目名称:SAEA.WebRedisManager.Controllers
*CLR 版本:4.0.30319.42000
*机器名称:WENLI-PC
*命名空间:SAEA.WebRedisManager.Controllers
*类 名 称:ConsoleController
*版 本 号:V1.0.0.0
*创建人: yswenli
*电子邮箱:wenguoli_520@qq.com
*创建时间:2019/3/26 11:05:29
*描述:
*=====================================================================
*修改时间:2019/3/26 11:05:29
*修 改 人: yswenli
*版 本 号: V1.0.0.0
*描 述:
*****************************************************************************/
using SAEA.MVC;
using SAEA.Redis.WebManager.Libs;

namespace SAEA.WebRedisManager.Controllers
{
public class ConsoleController : Controller
{
public ActionResult SendCmd(string name, string cmd)
{
if (!string.IsNullOrEmpty(cmd))
{
return Content(CurrentRedisClient.Send(name, cmd));
}
return Content("输入的命令不能为空~");
}
}
}
12 changes: 11 additions & 1 deletion SAEA.WebRedisManager/Controllers/RedisController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ public ActionResult GetInfo(string name, bool isCpu)
if (isCpu)
result = data.used_cpu_user.ToString();
else
result = (int.Parse(data.used_memory) / 1024 / 1024).ToString();
{
if (int.TryParse(data.used_memory, out int used_memory))
{
result = (used_memory / 1024 / 1024).ToString();
}
else
{
result = "0";
}
}


return Json(new JsonResult<string>() { Code = 1, Data = result, Message = "OK" });
}
Expand Down
51 changes: 41 additions & 10 deletions SAEA.WebRedisManager/Libs/CurrentRedisClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using SAEA.Redis.WebManager.Models;
using SAEA.RedisSocket;
using SAEA.RedisSocket.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SAEA.Redis.WebManager.Libs
{
Expand All @@ -17,6 +14,9 @@ public static class CurrentRedisClient

static Dictionary<string, RedisClient> _redisClients = new Dictionary<string, RedisClient>();


static object _locker = new object();

/// <summary>
/// 连接到redis
/// </summary>
Expand Down Expand Up @@ -65,19 +65,23 @@ public static string GetInfo(string name)
}




public static ServerInfo GetServerInfo(string name)
{
if (_redisClients.ContainsKey(name))
lock (_locker)
{
var redisClient = _redisClients[name];

if (redisClient.IsConnected)
if (_redisClients.ContainsKey(name))
{
return redisClient.ServerInfo;
var redisClient = _redisClients[name];

if (redisClient.IsConnected)
{
return redisClient.ServerInfo;
}
}
return null;
}
return null;

}


Expand Down Expand Up @@ -593,5 +597,32 @@ public static List<ClusterNode> GetClusterNodes(string name)
return null;
}
#endregion

#region Console

public static string Send(string name, string cmd)
{
if (_redisClients.ContainsKey(name))
{
var redisClient = _redisClients[name];

if (redisClient.IsConnected)
{
var @params = cmd.Split(new string[] { " " }, System.StringSplitOptions.RemoveEmptyEntries);

if (@params.Length > 0)
{
var cmdType = @params[0].ToUpper();

cmd = cmdType + cmd.Substring(cmdType.Length);

return redisClient.Console(cmd);
}
}
}
return $"操作失败,cmd:{cmd}";
}

#endregion
}
}
10 changes: 8 additions & 2 deletions SAEA.WebRedisManager/SAEA.WebRedisManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,18 @@
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SAEA.MVC" Version="4.2.5.6" />
<PackageReference Include="SAEA.RedisSocket" Version="4.2.5.6" />
<PackageReference Include="SAEA.MVC" Version="4.3.2.5" />
<PackageReference Include="SAEA.RedisSocket" Version="4.3.2.12" />
</ItemGroup>
<ItemGroup>
<None Update="wwwroot\Console.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="wwwroot\Content\img\6139455.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="wwwroot\Content\js\redis.console.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion SAEA.WebRedisManager/wwwroot/Chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="layui-row layui-col-space15" style="margin-top:15px;">
<div class="layui-card">
<div class="layui-card-header" style="font-size:18px;">
redis实例【<a href="javascript:;" id="redis_name" style="color:#0094ff;"></a>】资源使用情况
redis实例【<a href="javascript:;" id="redis_name" style="color:#0094ff;"></a>】资源使用情况 点击【<a href="javascript:;" id="redis_console" style="color:#0094ff;">这里</a>】进入命令行模式
</div>
<div class="layui-card-body layuiadmin-card-list" style="height:400px;">
<div class="layui-col-sm6 layui-col-md6">
Expand Down
40 changes: 40 additions & 0 deletions SAEA.WebRedisManager/wwwroot/Console.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>命令行</title>
<link href="/Content/css/layui.css" rel="stylesheet" />
<link href="/Content/css/global.css" rel="stylesheet" />
</head>
<body>
<div class="layui-fluid">
<div class="layui-row layui-col-space15" style="margin-top:15px;">
<div class="layui-card">
<div class="layui-card-header" style="font-size:18px;">
redis 命令行模式 <a href="http://doc.redisfans.com/" target="_blank" style="color:#0094ff;">更多redis命令</a>
</div>
<div class="layui-card-body layuiadmin-card-list" style="height:36px;">
<div class="layui-col-sm12 layui-col-md12">
<input type="text" id="cmdTxt" placeholder="请输入redis命令" class="layui-input" style="display:inline-block;width:800px;border-radius: 10px 0 0 10px;" />
<button id="runBtn" class="layui-btn layui-btn-normal" style="margin-left: -4px;margin-top: -1px;border-radius: 0 10px 10px 0px;">Run</button>
</div>
</div>
</div>
<div class="layui-card">
<div class="layui-card-header" style="font-size:18px;">
<button id="clearBtn" class="layui-btn layui-btn-xs layui-btn-normal">清空</button>
</div>
<div class="layui-card-body layuiadmin-card-list" style="height:400px;">
<div class="layui-col-sm12 layui-col-md12">
<textarea id="resultTxt" class="layui-textarea" style="height:533px;width:100%;resize:none;overflow:auto;background-color:#000;color:lawngreen;border-radius: 10px;" readonly="readonly"></textarea>
</div>
</div>
</div>
</div>
</div>
<script src="Content/js/layui.js"></script>
<script src="Content/js/requestpamars.js"></script>
<script src="Content/js/redis.console.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions SAEA.WebRedisManager/wwwroot/Content/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -1789,3 +1789,19 @@ body .site-demo-nav .layui-nav-item {
animation-name: site-anim-closeup;
overflow: hidden;
}
body::-webkit-scrollbar, textarea::-webkit-scrollbar {
width: 10px;
height: 1px;
}

body::-webkit-scrollbar-thumb, textarea::-webkit-scrollbar-thumb {
border-radius: 10px;
box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
background-image: radial-gradient(#fff,rgba(0,0,0,0.2));
}

body::-webkit-scrollbar-track, textarea::-webkit-scrollbar-track{
box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
border-radius: 10px;
background: #EDEDED;
}
23 changes: 19 additions & 4 deletions SAEA.WebRedisManager/wwwroot/Content/js/redis.chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
function LineChart1(eId, chart_title, redis_info_url, redis_name) {

var dom1 = document.getElementById(eId);
if (dom1 == undefined) return;
if (dom1 === undefined) return;
var myChart1 = echarts.init(dom1);
var app1 = {};
var option1 = null;
Expand Down Expand Up @@ -106,7 +106,7 @@
$.get(redis_info_url, "name=" + redis_name + "&isCpu=1", function (redis_info_data) {
//debugger;
var data0 = option1.series[0].data;
if (redis_info_data.Code == 2) {
if (redis_info_data.Code === 2) {
data0.shift();
data0.push(-1);
}
Expand Down Expand Up @@ -134,7 +134,7 @@

function LineChart2(eId, chart_title, redis_info_url, redis_name) {
var dom2 = document.getElementById(eId);
if (dom2 == undefined) return;
if (dom2 === undefined) return;
var myChart2 = echarts.init(dom2);
var app2 = {};
var option2 = null;
Expand Down Expand Up @@ -227,7 +227,7 @@
$.get(redis_info_url, "name=" + redis_name + "&isCpu=0", function (redis_info_data) {
//debugger;
var data0 = option2.series[0].data;
if (redis_info_data.Code == 2) {
if (redis_info_data.Code === 2) {
data0.shift();
data0.push(-1);
}
Expand Down Expand Up @@ -276,6 +276,21 @@
});
});

$("#redis_console").click(() => {
layer.full(layer.open({
title: '命令行模式',
type: 2,
area: ['580px', '318px'],
fixed: true,
resize: false,
move: false,
maxmin: true,
scrollbar: true,
time: 0,
content: [`/console.html?name=${name}`, 'no']
}));
});

//redis cluster
function getClusterNodes() {
var redis_nodes_url = "/api/RedisCluster/GetClusterNodes?name=" + name;
Expand Down
40 changes: 40 additions & 0 deletions SAEA.WebRedisManager/wwwroot/Content/js/redis.console.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
layui.use(['jquery', 'layer', 'form'], function () {

var layer = layui.layer, form = layui.form, $ = layui.$;

var redis_name = encodeURIComponent(GetRequest().name);

var layerIndex = -1;



$("#runBtn").click(function () {

var cmd = $("#cmdTxt").val();

if (cmd !== undefined && cmd !== "") {

cmd = encodeURIComponent(cmd);

layerIndex = layer.msg('加载中', {
icon: 16
, shade: 0.01
});

$.post("/console/sendcmd", `name=${redis_name}&cmd=${cmd}`, (result) => {
var v = `输入:\r\n ${decodeURIComponent(cmd)
}\r\n\r\n输出:\r\n${result}\r\n\r\n${$("#resultTxt").val()}`;
$("#resultTxt").val(v);
$("#resultTxt")[0].scrollTop = 0;
layer.close(layerIndex);
});
}

});


$("#clearBtn").click(() => {
$("#resultTxt").val("");
});

});
3 changes: 2 additions & 1 deletion SAEA.WebRedisManager/wwwroot/Content/js/redis.data.item.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ layui.use(['jquery', 'layer', 'form', 'laypage'], function () {
var item_type = GetRequest().type;
var item_id = GetRequest().id;

var item_typeStr = "hash"
var item_typeStr = "hash";

switch (item_type * 1) {
case 2:
item_typeStr = "hash";
Expand Down
4 changes: 2 additions & 2 deletions SAEA.WebRedisManagerForNet/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="SAEA.Sockets" publicKeyToken="01a82380791791ab" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.3.3" newVersion="3.3.3.3" />
<bindingRedirect oldVersion="0.0.0.0-4.3.1.2" newVersion="4.3.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="SAEA.Common" publicKeyToken="01a82380791791ab" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.5" newVersion="4.1.2.5" />
<bindingRedirect oldVersion="0.0.0.0-4.3.1.2" newVersion="4.3.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
Expand Down
Loading

0 comments on commit e48f4e2

Please sign in to comment.