update 优化 Redis缓存监控接口 手动归还连接给连接池 提高效率
This commit is contained in:
parent
682d8b0099
commit
3f9919fbee
@ -6,6 +6,7 @@ import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.redisson.spring.data.connection.RedissonConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.RedisConnectionUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -31,9 +32,9 @@ public class CacheController {
|
||||
@GetMapping()
|
||||
public R<CacheListInfoVo> getInfo() throws Exception {
|
||||
RedisConnection connection = connectionFactory.getConnection();
|
||||
Properties commandStats = connection.commands().info("commandstats");
|
||||
|
||||
List<Map<String, String>> pieList = new ArrayList<>();
|
||||
try {
|
||||
Properties commandStats = connection.commands().info("commandstats");
|
||||
List<Map<String, String>> pieList = new ArrayList<>();
|
||||
if (commandStats != null) {
|
||||
commandStats.stringPropertyNames().forEach(key -> {
|
||||
Map<String, String> data = new HashMap<>(2);
|
||||
@ -43,10 +44,13 @@ public class CacheController {
|
||||
pieList.add(data);
|
||||
});
|
||||
}
|
||||
|
||||
return R.ok(new CacheListInfoVo(
|
||||
connection.commands().info(),
|
||||
connection.commands().dbSize(), pieList));
|
||||
} finally {
|
||||
// 归还连接给连接池
|
||||
RedisConnectionUtils.releaseConnection(connection, connectionFactory);
|
||||
}
|
||||
}
|
||||
|
||||
public record CacheListInfoVo(Properties info, Long dbSize, List<Map<String, String>> commandStats) {}
|
||||
|
Loading…
Reference in New Issue
Block a user