Redis cache bulk readwritedelete helpers use cases
When you take a look at Fallback::Cache file, you will see bunch of helpers which allows you to read/write and delete cache in bulk.
read_multiwrite_multidelete_matched
Here is how you can use them:-
read_multiwill help you access multiple key/value at once:- Eg: `Fallback::Cache.read_multi('hello', 'world', 'test')- Similarly, write_multi will help you write multiple keys to redis store. Eg:
Fallback::Cache.write_multi({hello: 'world', one: 1, two: 2}) - And
delete_matchedwill help you delete multiple key/values, but you will need to pass pattern instead of keys. Eg:Fallback::Cache.delete_matched('*default_sc*')
These are the use cases, but some of the things you will need to keen an eye on:-​
- Make sure you are not adding these to frequently accessed endpoints and transactions, these read/write and scans (while deleting) will take some time and our app will slow down.
- Make sure when you are deleting with
delete_matched, make sure it deletes just the one you want. For example:Fallback::Cache.delete_matched('*simple_copy*')will delete all the keys containingsimple_copy, which usually times out because these are thousands in number, and our app will crash. - If you really need to access these methods, make sure you async them so the app does not crash.