优化国标设备点播的信息的Redis缓存策略

This commit is contained in:
648540858
2024-10-25 14:46:51 +08:00
parent 193f80963d
commit 34cc8251e2
5 changed files with 122 additions and 88 deletions

View File

@@ -1,16 +1,21 @@
package com.genersoft.iot.vmp.vmanager;
import com.genersoft.iot.vmp.conf.security.JwtUtils;
import com.genersoft.iot.vmp.common.InviteInfo;
import com.genersoft.iot.vmp.common.InviteSessionType;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.media.event.hook.Hook;
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/test")
@@ -19,13 +24,42 @@ public class TestController {
@Autowired
private HookSubscribe subscribe;
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
@GetMapping("/hook/list")
@Operation(summary = "查询角色", security = @SecurityRequirement(name = JwtUtils.HEADER))
public List<Hook> all(){
return subscribe.getAll();
}
@GetMapping("/redis")
public List<InviteInfo> redis(){
InviteSessionType type = InviteSessionType.PLAY;
String channelId = null;
String stream = null;
String key = VideoManagerConstants.INVITE_PREFIX;
String keyPattern = (type != null ? type : "*") +
":" + (channelId != null ? channelId : "*") +
":" + (stream != null ? stream : "*")
+ ":*";
ScanOptions options = ScanOptions.scanOptions().match(keyPattern).count(20).build();
Cursor<Map.Entry<Object, Object>> cursor = redisTemplate.opsForHash().scan(key, options);
List<InviteInfo> result = new ArrayList<>();
try {
while (cursor.hasNext()) {
System.out.println(cursor.next().getKey());
result.add((InviteInfo) cursor.next().getValue());
}
}catch (Exception e) {
}finally {
cursor.close();
}
return result;
}
// @Bean
// public ServletRegistrationBean<StatViewServlet> druidStatViewServlet() {
// ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");