redisclear.jsp 9.94 KB
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@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>

<!-- 头部 -->
<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" style="background-color: #efefef">

      <div class="widget-content nopadding" >
        <%--<div class="widget-title"></div>--%>
        <div class="widget-body " >
          <div id="redisTypeDiv">

          </div>

        <div class="form-inline" role="form" style="margin: 12px; ;">
          <div class="input-group">
            <span class="input-group-addon">prefix:</span>
            <input id="prefixInput" class="form-control">
            </input>
          </div>
          <button id="btnSearch" class="btn btn-danger" style="margin-left: 10px" onclick="btnClear()">
            清除缓存
          </button>
        </div>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="<%=basePath %>script/common/genarate_left_panel.js?v=20171127"></script>
<script>
  $("#li_manager").addClass("active open");
  $("#li_redisClear").addClass("active");
</script>
<script type="text/javascript">
  var _PAGE_REDIS_INFO_MAPS=null;
  var _PAGE_REDIS_SOURCE="";

  function btnClear() {
      var pre=$.trim($("#prefixInput").val());
      if(pre==null||pre.length<=0){
          localAlert('提示', '请求参数prefix不允许为空!');
          return ;
      }
      if(!checkRate(pre.substr(0,1))){
          localAlert('提示', '请求参数prefix必须以数字或字母开头!');
          return ;
      }

      var dialog = $("<div>").appendTo($("body"));
      dialog.dialog({
          title: "清除确定",
          backdrop: "static",
          content: "确认清除缓存?",
          buttons: [{
              text: "否",
              className: "btn-danger",
              onclick: function () {
                  $(dialog).dialog("hide");
              }
          }, {
              text: "是",
              className: "btn-success",
              onclick: function () {
                  $(dialog).dialog("hide");
                  goClear(pre);
              }
          }]
      });


  }

  function goClear(pre){
      var frontParam={};
      frontParam.dataSourceInfo=_PAGE_REDIS_SOURCE;
      frontParam.keyPrefix=pre;

      $.post({
          url: contextPath + "redisClear/clear",
          data: frontParam,
          dataType: "json",
          success: function (resp) {
              if (resp!=null&&resp.code == 200) {
                  localAlert('清除缓存成功', resp.data);
              } else {
                  localAlert('清除缓存失败', resp.message);
              }
          },
          error: function (e) {
              localAlert('清除缓存失败', resp.message);
              console.log(e);
          }
      });
  }

  function checkRate(nubmer)
  {
      var re =  /^[0-9a-zA-Z]*$/g;  //判断字符串是否为数字和字母组合     //判断正整数 /^[1-9]+[0-9]*]*$/
      if (!re.test(nubmer))
      {
          return false;
      }else{
          return true;
      }
  }


  $(document).ready(function () {
    //查询redis配置信息
    $.ajax({
      url: contextPath  +"redisClear/queryNoSyncRedisList",
      dataType: "json",
      success: function (resp) {
        if(resp.code == 200){
          _PAGE_REDIS_INFO_MAPS=resp.data;
            resetRedisType();
        }else{
          alert("查询redis配置信息报错");
          return;
        }
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert("error");
      }
    });
  });


  function resetRedisType(){
      var count=0;
      _PAGE_REDIS_SOURCE=""; //重新置空
      var currValue;
      for (var prop in _PAGE_REDIS_INFO_MAPS) {
          var html='<div class="form-inline" role="form" style="margin:12px;">';
          html += '<div class="input-group" >';
          html += '<span style="width:135px;" class="input-group-addon">'+prop+'</span>';
          html += '<input style="width:600px;" readonly disabled type="text"  id="redis_type_'+prop+'" ';
          html += ' class="form-control" placeholder="" ';
          currValue=resetRedisInfo(prop);
          html += ' value = "'+currValue+'"';
          html += "/>";
          html += '</div></div>';
          $("#redisTypeDiv").append(html);
          count++;

          //记录redis源的values
          if(_PAGE_REDIS_SOURCE.length>0){
              _PAGE_REDIS_SOURCE += ",";
          }
          _PAGE_REDIS_SOURCE += currValue;
      }
  }

  function resetRedisInfo(prop){
     var val='';
      for(var i =0;i<_PAGE_REDIS_INFO_MAPS[prop].length;i++){
          if(val.length>0){
              val += ",";
          }
          val += (_PAGE_REDIS_INFO_MAPS[prop][i].ip+":"+ _PAGE_REDIS_INFO_MAPS[prop][i].port );
      }
      return val;
  }

/*  function resetRedisType(){
      var count=0;
      for (var prop in _PAGE_REDIS_INFO_MAPS) {
          if(count>0){
              $("#redisTypeDiv").append("<br/><br/>");
          }
          // $("#redisTypeDiv").append("<input style='margin-left:10px;' type='checkbox' disabled checked value="+prop+">" + prop + "</input>");
          $("#redisTypeDiv").append("<label style='margin-left:10px;'  disabled   value="+prop+">" + prop + "</label>");
          resetRedisInfo(prop);
          count++;
      }
  }

  function resetRedisInfo(prop){
    _PAGE_SELECT_DB_INDEX=0;
    var styleMargin="";
    for(var i =0;i<_PAGE_REDIS_INFO_MAPS[prop].length;i++){
        if(i%4==0){
            $("#redisTypeDiv").append("<br/>");
            styleMargin =" style='margin-left:20px;' ";
        }
      $("#redisTypeDiv").append("<input type='checkbox' disabled checked name="+prop+styleMargin+"   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 + "</input>");
    }
  }*/
  


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