redisoperate.jsp 11.7 KB
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@page import="com.ui.contants.ProjectConstant"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/bootstrap-datetimepicker.css"/>
  <link href="<%=basePath %>js/bootstrap-plugin/css/bootstrap.table.css" rel="stylesheet" media="screen"/>
  <link rel="stylesheet" href="<%=basePath %>css/bootstrap-responsive.min.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/fullcalendar.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/jquery-ui.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/uniform.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
  <link rel="stylesheet" href="<%=basePath %>js/jstree/themes/proton/style.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
  <link rel="stylesheet" href="<%=basePath %>css/yoho.css"/>
  <script src="<%=basePath %>js/excanvas.min.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/jquery-1.12.0.min.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/jquery-ui.custom.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>/js/bootstrap.min.js"></script>
  <script src="<%=basePath %>/js/unicorn.js"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/moment-with-locales.js" charset="UTF-8"
          type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"
          type="text/javascript"></script>
  <script src="<%=basePath %>js/global.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.pagination.js" charset="UTF-8"
          type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.table.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.panel.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.alerts.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.accordion.js" charset="UTF-8"
          type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.breadcrumb.js" charset="UTF-8"
          type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js" charset="UTF-8"
          type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/layer/layer.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/bootstrap-plugin/bootstrap.select.js" charset="UTF-8" type="text/javascript"></script>
  <script src="<%=basePath %>js/jstree/jstree.min.js"></script>
  <script src="<%=basePath %>js/jquery.toaster.js"></script>
  <script src="<%=basePath %>js/jquery-plugin/jquery.cookies.js" charset="UTF-8" type="text/javascript"></script>
  <script>
    var contextPath = '<%=basePath %>';
  </script>
  <title>redis command</title>
</head>
<body style="background-color: #444444;font-size: 14px">

<!-- 头部 -->
<div id="head">
</div>
<!-- 右侧具体内容 -->
<div id="content">
  <div id="breadcrumb">
    <a href="#" title="Go to Home" class="tip-bottom"><i
            class="icon-home"></i> Home</a> <a href="#" class="current">redis命令</a>
  </div>

  <div class="container-fluid">
    <div class="widget-box">

      <div class="widget-content nopadding">
        <div class="widget-title" style="height: 53px;">
          <div>
            <div class="form-inline" role="form" style="margin-top: 12px;margin-left: 25px;">
              <div class="input-group">
                <span class="input-group-addon">类别:</span>
                <select id="redisTypeSelect" class="form-control" onChange = "resetRedisInfo(this.options[this.selectedIndex].value)">

                </select>
              </div>
              <div class="input-group">
                <span class="input-group-addon">redis源:</span>
                <select id="dataSourceInfo" class="form-control">

                </select>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div style="height:30px;">
    <span>支持命令:  get,hget,lrange,smembers,hmget,ttl</span>
      </div>
    <div style="min-height:600px;">

      <!--search form-->
      <div class="form-inline">

        <div class="form-group">
          <textarea id="queryContent" type="text" class="form-control" style="width:1000px" rows="4" placeholder="请输入查询命令,自动过滤/* */和--注释内容,[Ctrl+Enter]提交查询" onKeyDown="ctlSubmit(event);"></textarea>
        </div>

        <div class="form-group">
          <div class="col-sm-offset-2 col-sm-10">
            <button class="btn btn-primary" onclick="query()" style="margin-top: 50px;">提交查询</button>
          </div>
        </div>
      </div>


      <!-- result form-->
      <div class="widget-box">
        <div class="widget-title">
          <h5>查询结果&nbsp;<a href="#" onclick="$('#resultDiv').html('');">clear</a></h5>
        </div>
        <div class="widget-content nopadding">

          <div id="resultDiv">

          </div>
        </div>
      </div>





    </div>
  </div>
</div>

<script src="<%=basePath %>script/common/genarate_left_panel.js?v=<%=ProjectConstant.MENU_VERSION %>"></script>
<script>
  $("#li_other").addClass("active open");
  $("#li_redis_operate").addClass("active");
</script>
<script type="text/javascript">
  var _PAGE_REDIS_INFO_MAPS=null;
  var _PAGE_SELECT_DB_INDEX=0;
  $(document).ready(function () {
    $("#queryContent").focus();

    //查询redis配置信息
    $.ajax({
      url: contextPath  +"redisOperate/queryRedisList",
      dataType: "json",
      success: function (resp) {
        if(resp.code == 200){
          _PAGE_REDIS_INFO_MAPS=resp.data;
          var count=0;
          for (var prop in _PAGE_REDIS_INFO_MAPS) {
            if(count==0){
              $("#redisTypeSelect").append("<option selected = 'selected' value="+prop+">" + prop + "</option>");
              resetRedisInfo(prop);
            }else{
              $("#redisTypeSelect").append("<option value="+prop+">" + prop + "</option>");
            }
            count++;
          }
        }else{
          alert("查询redis配置信息报错");
          return;
        }
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert("error");
      }
    });
  });

  /**
   * 去掉sql注释 --类型
   */
  function removeAnnotateTypeOne(sql){
    var arry = sql.split("\n");//以换行符为分隔符将内容分割成数组
    var newArry = new Array();
    for(var i=0;i<arry.length;i++){
      var rowContent= $.trim(arry[i]);
      if(rowContent){
        var annoteTypeNum=rowContent.indexOf("--");
        if(annoteTypeNum>0){
          newArry.push(rowContent.substr(0,annoteTypeNum));
        }else if(annoteTypeNum==0){
          //去掉
        }else{
          newArry.push(rowContent);
        }
      }
    }
    return newArry.join(" ");
  }

  /**
   * 去掉sql注释 /*类型
   */
  function removeAnnotateTypeTwo(sql){
    var whileFlag=false;
    do{
      var beginAnnoteTypeNum = sql.indexOf("/*");
      var endAnnoteTypeNum=0;
      var headAnoteTypeOneStr='';
      var tailAnoteTypeOneStr='';
      if(beginAnnoteTypeNum>0){
        headAnoteTypeOneStr=sql.substr(0,beginAnnoteTypeNum);
        var otherSql=sql.substr(beginAnnoteTypeNum+2);
        endAnnoteTypeNum= otherSql.indexOf("*/");
        if(endAnnoteTypeNum<0){
          alert("注释不符合规范:/*和*/必须成对出现");
          return "";
        }
        tailAnoteTypeOneStr=otherSql.substr(endAnnoteTypeNum+2);
        sql=headAnoteTypeOneStr+" "+tailAnoteTypeOneStr;
        whileFlag=true;
      }else if(beginAnnoteTypeNum==0){
        headAnoteTypeOneStr="";
        var otherSql=sql.substr(beginAnnoteTypeNum+2);
        endAnnoteTypeNum= otherSql.indexOf("*/");
        if(endAnnoteTypeNum<0){
          alert("注释不符合规范:/*和*/必须成对出现");
          return "";
        }
        tailAnoteTypeOneStr=otherSql.substr(endAnnoteTypeNum+2);
        sql=headAnoteTypeOneStr+" "+tailAnoteTypeOneStr;
        whileFlag=true;
      }else{
        whileFlag=false;
      }
    }while(whileFlag);
    return sql;
  }

  function resetRedisInfo(prop){
    _PAGE_SELECT_DB_INDEX=0;
    $("#dataSourceInfo").empty();
    for(var i =0;i<_PAGE_REDIS_INFO_MAPS[prop].length;i++){
      $("#dataSourceInfo").append("<option   value="+_PAGE_REDIS_INFO_MAPS[prop][i].ip+" data-sign="+_PAGE_REDIS_INFO_MAPS[prop][i].port+">" + _PAGE_REDIS_INFO_MAPS[prop][i].ip+":"+ _PAGE_REDIS_INFO_MAPS[prop][i].port + "</option>");
    }
  }

  /**
   * ctrl+enter,事件
   */
  function ctlSubmit(event) {
    if (event.ctrlKey && event.keyCode == 13) {
      query();
    }
  }

  function query(){
    var queryThings=$.trim($("#queryContent").val());
    queryThings=removeAnnotateTypeOne(queryThings);
    queryThings=removeAnnotateTypeTwo(queryThings);
    queryThings= $.trim(queryThings);
    if(queryThings==null||queryThings==''){
      alert("参数错误,请输入查询条件");
      $("#queryContent").focus();
      return;
    }
    var param={};
    param.dataSourceInfo=$.trim($("#dataSourceInfo option:selected").text());
    param.cmdContent=queryThings;
    var select_tmp=queryThings.toLowerCase();
    if(queryThings.toLowerCase().indexOf("select")>=0){
     /* var select_index_tmp= $.trim(select_tmp.substr(queryThings.toLowerCase().indexOf("select")+6));
      var array_select_index_tmp=select_index_tmp.split(" ");
      if(array_select_index_tmp==null||array_select_index_tmp.length<=0){
        alert("select index 语法错误:"+array_select_index_tmp);
        return;
      }
      var int_select_index=$.trim(array_select_index_tmp[0]);
      _PAGE_SELECT_DB_INDEX=int_select_index;*/
      alert("语法错误,twemproxy不支持select");
      return;
    }
    param.selectIndex=_PAGE_SELECT_DB_INDEX;

   if(param.dataSourceInfo==null||param.dataSourceInfo==''){
      alert("参数错误,请选择redis数据源");
      return;
    }

    if(param.cmdContent==null||param.cmdContent==''){
      alert("参数错误,请输入查询条件");
      $("#queryContent").focus();
      return;
    }
//alert(param.selectIndex);
    //查询redis配置信息
    $.ajax({
      url: contextPath  + "redisOperate/query",
      dataType: "json",
      data: param,
      success: function (resp) {
        if(resp.code == 200){
          $("#resultDiv").append(resp.data);
        }else{
          alert("查询报错,请检查语法!");
          return;
        }
      },
      error: function () {
        alert("错误, 请求发生错误!");
        return;
      }
    });
  }

</script>
</body>
</html>