I'm working on web app using nestJs/postgres/redis.
What is the best way (best data structure) to cache following postgres table (hierarchy) to Redis ?
space:
folders:
files:
I already tried to cache this using key-value where the key is hashed from request and value is response of say getAllMyFiles but there will be some problem Say i want to cache The route:
/my-files
key: users:[USER_ID]:documents:[QUERY-HASH]
the problem is that:
I think that the best solution is to use Redis graph
Could this be a good candidate for RedisJSON? You could store the entire space and all its hierarchy in a single key as JSON using JSON.SET and then query portions of it using JSON.GET.
JSON.SET space:1234 $ '{
"name": "foo",
"users": [ "alice", "bob" ],
"folders": [
{
"id": "5678",
"files": [
{
"name": "bar"
},
...other files...
]
},
...other folders...
}'
JSON.GET space:1234 $. # returns the entire space
JSON.GET space:1234 $.folders # returns the folders for the space
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With