|
@@ -6,6 +6,7 @@ import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.redisson.spring.data.connection.RedissonConnectionFactory;
|
|
import org.redisson.spring.data.connection.RedissonConnectionFactory;
|
|
|
import org.springframework.data.redis.connection.RedisConnection;
|
|
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.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
@@ -31,21 +32,25 @@ public class CacheController {
|
|
|
@GetMapping()
|
|
@GetMapping()
|
|
|
public R<CacheListInfoVo> getInfo() throws Exception {
|
|
public R<CacheListInfoVo> getInfo() throws Exception {
|
|
|
RedisConnection connection = connectionFactory.getConnection();
|
|
RedisConnection connection = connectionFactory.getConnection();
|
|
|
- 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);
|
|
|
|
|
- String property = commandStats.getProperty(key);
|
|
|
|
|
- data.put("name", StringUtils.removeStart(key, "cmdstat_"));
|
|
|
|
|
- data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
|
|
|
|
|
- pieList.add(data);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ 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);
|
|
|
|
|
+ String property = commandStats.getProperty(key);
|
|
|
|
|
+ data.put("name", StringUtils.removeStart(key, "cmdstat_"));
|
|
|
|
|
+ data.put("value", StringUtils.substringBetween(property, "calls=", ",usec"));
|
|
|
|
|
+ pieList.add(data);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok(new CacheListInfoVo(
|
|
|
|
|
+ connection.commands().info(),
|
|
|
|
|
+ connection.commands().dbSize(), pieList));
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // 归还连接给连接池
|
|
|
|
|
+ RedisConnectionUtils.releaseConnection(connection, connectionFactory);
|
|
|
}
|
|
}
|
|
|
- return R.ok(new CacheListInfoVo(
|
|
|
|
|
- connection.commands().info(),
|
|
|
|
|
- connection.commands().dbSize(), pieList));
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public record CacheListInfoVo(Properties info, Long dbSize, List<Map<String, String>> commandStats) {}
|
|
public record CacheListInfoVo(Properties info, Long dbSize, List<Map<String, String>> commandStats) {}
|