Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

spring boot - How can I structure the following mongo collection into the redis cache?

I am using redis template and Jedis:

Let's say I have the following sample document of a mongo collection:

_id:
5fd9e0568564939bc4fb947c
field1: "value"
field2: "value"
field3: "value"
field4: "value"
field5: "value"
field6: "value"
field7: "value"
field8: "value"
field9: "value"
field10: "value"

The size of the collection is just 3mb so I can persist the entire collection into the redis cache even with redundancies. I have an API that fetches documents based on different key sets. Example [(field1, field2), (field1, field3)) etc. How can you persist data efficiently into redis cache for the purpose of this API. I know I can come up with all the possible request combinations and attach all the documents associated to every combination but that would result in the redis cache being too large. That is feasible if I implement a book directory mechanism in which I just persist every document just once into the redis cache and attach a reference to it. The problem is that I would have to make two calls to redis, one for getting the indexes/looukps of the specified input configuration and another one for actually getting the objects. MongoDB in this case would be faster than sending two queries to redis I think (Not sure here as all hash operations are run in O(1). Perhaps keep the book directory in memory?). What is the best way to do this?

Let's try to see first if there an efficient way we can do this by using just jedis else we look further into lua and redisson.

update: I've been reading about the spring data repositories and how I can achieve db query behavior by using it. Will it efficiently store my objects in Redis?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...