1

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?

Fernando
  • 381
  • 1
  • 5
  • 20
  • Can you not store the entire thing as simple key:value pair? When you get a request say [(field1, field2)], get the value of 'field1' key, then get the value of 'field2' key and then fetch the document. Or is this what you meant when you say you don't want to query redis 2 times? – Ankit Sahay Dec 30 '20 at 14:15
  • What I am trying to do here is persist all the collection from mongo into Redis in a way in which it can be easily retrieved by the API. – Fernando Dec 30 '20 at 23:48

0 Answers0