英文:
Combine data from two post requests
问题
我有一个接收POST请求的Rest API,数据和图片分别在两个不同的请求中传输。
/v1/photo # multipart/form-data
/v1/data # json
我正在尝试将值合并到Redis中。
# 保存照片
HSET photo:1.jpg file_name 9f7a6775-3815-4d20-affa-e81bc9c4293b
SADD have:uuid photo:1.jpg
HSET photo:2.jpg file_name fcb7db2d-159e-4d0e-b884-ca455bd6f4a5
SADD have:uuid photo:2.jpg
# 保存数据
HSET photo:1.jpg data JSONsring
SADD have:data photo:1.jpg
HSET photo:2.jpg data JSONsring
SADD have:data photo:2.jpg
现在我需要获取所有合并的数据(以便将它们保存到另一个数据库)。我可以使用sinter
获取键。
SINTER have:uuid have:data
但是我需要JSON和UUID。
如何快速地并且使用最少的资源完成这个任务?
英文:
I have a Rest API that gets the POST requests, data and images comes in two different requests.
/v1/photo # multipart/form-data
/v1/data # json
I'm trying to merge values into Redis
# Save photo
HSET photo:1.jpg file_name 9f7a6775-3815-4d20-affa-e81bc9c4293b
SADD have:uuid photo:1.jpg
HSET photo:2.jpg file_name fcb7db2d-159e-4d0e-b884-ca455bd6f4a5
SADD have:uuid photo:2.jpg
# Save data
HSET photo:1.jpg data JSONsring
SADD have:data photo:1.jpg
HSET photo:2.jpg data JSONsring
SADD have:data photo:2.jpg
Now I need to get all the combined data (In order to save them to another database).
I can use sinter
to get keys.
SINTER have:uuid have:data
But i need JSON and UUID.
How to make it as quickly and with the minimum spent resources?
答案1
得分: 0
为了确保这有一个明确的答案,我会采纳@reticentroot的建议,并将评论格式化为答案。
为了更符合习惯用法,您的POST端点应该接受请求,无论是否已创建相应的/v1/photo或/v1/data条目。与这些数据片段进行交互的过程可以轻松地检查是否具有这两个数据片段,并相应地采取行动。
英文:
For the sake of ensuring this has a marked answer, I'll take the advice of @reticentroot and format the comment into an answer.
It would be more idiomatic for your POST endpoint to accept the request regardless of whether a corresponding /v1/photo or /v1/data entry has been created. The process that's interfacing with these pieces of data could easily check whether it has both pieces of data, and act accordingly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论