forked from fanruan/demo-tabledata-redis
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
6 years ago
|
package com.fr.plugin.db.redis.action;
|
||
|
|
||
|
import com.fanruan.api.data.ConnectionKit;
|
||
|
import com.fr.base.ServerConfig;
|
||
|
import com.fr.data.impl.Connection;
|
||
|
import com.fr.decision.fun.impl.BaseHttpHandler;
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.plugin.db.redis.core.RedisDatabaseConnection;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
|
||
|
import com.fr.web.utils.WebUtils;
|
||
|
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
||
|
/**
|
||
|
* @author Elijah
|
||
|
* @version 10.0.4
|
||
|
* Created by Elijah on 2019/10/30
|
||
|
*/
|
||
|
public class SearchKeysAction extends BaseHttpHandler {
|
||
|
@Override
|
||
|
public RequestMethod getMethod() {
|
||
|
return RequestMethod.GET;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getPath() {
|
||
|
return "/redis/keys";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isPublic() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||
|
String[] keys = new String[0];
|
||
|
String pattern = request.getParameter("pattern");
|
||
|
String connectionName = request.getParameter("database");
|
||
|
if (StringUtils.isNotEmpty(pattern) && StringUtils.isNotEmpty(connectionName)) {
|
||
|
Connection connection = ConnectionKit.getConnection(connectionName);
|
||
|
if (connection instanceof RedisDatabaseConnection) {
|
||
|
keys = connection.summary(pattern);
|
||
|
}
|
||
|
}
|
||
|
WebUtils.printAsJSON(response, new JSONArray(keys));
|
||
|
response.setContentType("application/json;charset=" + ServerConfig.getInstance().getServerCharset());
|
||
|
}
|
||
|
}
|