redisoperate.jsp
11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<%@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>查询结果 <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>