My team is using Redis for caching and I want to cache the following structure:
inbox --(1 to many)-> folders --(1 to many)-> messages
It's just a simple tree with no nesting, and each inbox/folder/message is just a single int
/long
. I more often need to get all messages in a single folder, but sometimes also need to get all messages in a whole inbox (all the folders).
For the Redis data structure, I'm considering the following 2:
Storing messages in a list & using SCAN
key = "inbox_id:folder_id"
value = [message_ids]
fetch_folder(): GET inbox_id:folder_id
fetch_inbox(): SCAN inbox_id:* | GET resulting_ids
// I'm not sure how to do fetch_inbox in just Redis yet, so pipe for now
Having a hashmap per inbox
inbox_id = hashmap { key = folder_id, value = "message_ids_as_string" }
fetch_folder(): HMGET inbox_id folder_id
fetch_inbox(): HVALS inbox_id
Which storage & access pattern would be more performant, assuming 10-100 folders per inbox & 100-10_000 messages per folder?
Asked by ChocolateOverflow
(99 rep)
Sep 30, 2023, 02:38 PM
Last activity: Jan 13, 2024, 01:58 PM
Last activity: Jan 13, 2024, 01:58 PM