[英]Can't get correct value from Redis through Spring
I'm stuck on this for quite some time.我坚持了很长一段时间。 For token management, I'm using Redis.
对于令牌管理,我使用的是 Redis。 On the Redis, each token keeps a list of all the invoices my customers can see.
在 Redis 上,每个令牌都会保存我的客户可以看到的所有发票的列表。
For my example, my customer X can view the invoice Y. But the information Y doesn't make it once it goes through Java.在我的示例中,我的客户 X 可以查看发票 Y。但是信息 Y 一旦通过 Java 就无法生成。
For instance, on redis, the command例如,在 redis 上,命令
hget TokenDocumentsEntity:[UUID key] metadata.documents.source.elementData[0]
give me back Y. This is what I want and need.把 Y 还给我。这就是我想要和需要的。 Overall, every information I can see using
总的来说,我可以看到的每个信息都使用
hgetall
are correct.是正确的。 This means my code properly writes what I want.
这意味着我的代码正确地编写了我想要的东西。 But when I try to get the info from the redis (using @Repository and findById) It gives me back :
但是当我尝试从 redis 获取信息时(使用 @Repository 和 findById)它给了我:
tokenDocuments(owner=Id_of_the_customer, documents={name_of_source=[49]})
I have no clue where is this 49 coming from, what it is related to or what it represents.我不知道这个 49 来自哪里,它与什么有关或它代表什么。 But that's the place where my Y should be.
但这就是我的 Y 应该在的地方。
Any clue why this happen?任何线索为什么会发生这种情况?
EDIT : here is the code where this happens: on the controller :编辑:这是发生这种情况的代码:在控制器上:
@PostMapping("/base64")
public ResponseEntity<byte[]> getDocument(@Valid @RequestBody FileRequest fileRequest, @RequestHeader HttpHeaders header) {
TokenClaims tokenClaims = validateHeaderAndGetTokenClaims(header);
TokenDocuments tokenDocuments = newTokenService.getTokenDocuments(tokenClaims.getTokenDocumentsId());
Audit auditDao = iAuditService.getBackBone(Bill, "listBills", Customer, String.valueOf(tokenClaims.getSubject()));
.
.
.
And on the NewTokenService Implementation :在 NewTokenService 实现上:
@Override
public TokenDocuments getTokenDocuments(UUID uuid) {
Optional<TokenDocumentsEntity> optional = tokenDocumentsRepository.findById(uuid);
if (optional.isPresent()) {
logger.debug("optional : " + optional);
return optional.get().getMetadata();
}
throw new EntityNotFoundException("entity with uuid " + uuid + " not found on token db");
}
the debugging tool shows me that调试工具告诉我
uuid = 18906e40-9156-457e-9069-9e849ec663e2
which is a key found on my redis, thus fine.这是在我的 redis 上找到的一个键,因此很好。 but also
但是也
optional = Optional[TokenDocumentsEntity(id=18906e40-9156-457e-9069-9e849ec663e2, metadata=TokenDocuments(owner=1041403, documents={SWS=[49]}))]
All I send is a FileRequest fileRequest of the form :我发送的只是以下形式的 FileRequest fileRequest :
{
"fileId": 101520529,
"fileExtension": "PDF",
"fileName": "2019-FLN-1000003001",
"fileSource": "SWS"
}
Thank you!谢谢!
I found the problem.我发现了问题。
In my在我的
tokenDocuments
the variable documents
was a HashMap
which are not supported by Redis.变量
documents
是 Redis 不支持的HashMap
。 I fixed this by using converters instead.我改用转换器解决了这个问题。
Thank you to anyone who tried to help.感谢任何试图提供帮助的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.