|
|
|
package com.fr.plugin.db.redis.action;
|
|
|
|
|
|
|
|
import com.fanruan.api.data.ConnectionKit;
|
|
|
|
import com.fanruan.api.util.StringKit;
|
|
|
|
import com.fanruan.api.web.FlushKit;
|
|
|
|
import com.fr.base.ServerConfig;
|
|
|
|
import com.fr.data.impl.Connection;
|
|
|
|
import com.fr.decision.fun.impl.BaseHttpHandler;
|
|
|
|
import com.fr.json.JSONFactory;
|
|
|
|
import com.fr.plugin.db.redis.core.RedisDatabaseConnection;
|
|
|
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 (StringKit.isNotEmpty(pattern) && StringKit.isNotEmpty(connectionName)) {
|
|
|
|
Connection connection = ConnectionKit.getConnection(connectionName);
|
|
|
|
if (connection instanceof RedisDatabaseConnection) {
|
|
|
|
keys = connection.summary(pattern);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FlushKit.printAsJSON(response, JSONFactory.createJSON(Arrays.asList(keys)));
|
|
|
|
response.setContentType("application/json;charset=" + ServerConfig.getInstance().getServerCharset());
|
|
|
|
}
|
|
|
|
}
|