any alternative solution to create SQL type table in Redis using Redisson in java

108 views
Skip to first unread message

Ravi Desai

unread,
Mar 28, 2021, 9:20:24 AM3/28/21
to Redis DB

Any alternative solution to create a SQL table structure in Redis using Redisson in java app. For example a table of say Products.

The standard flow would be to instantiate a RMapCache and add the products to that - something like this


        // save the prod to ProdTableCache

        final RMapCache<String, Product> prodMap;

        String prodMapKey = "ProductTable";

        final TypedJsonJacksonCodec prodCodec = new TypedJsonJacksonCodec(String.class, Product.class, new ObjectMapper());

        prodMap = redisson.getMapCache(prodMapKey, prodCodec);


        Product prod1 = new Product("Prod101", "Mobile", 1000);

        Product prod2 = new Product("Prod102", "Tablet", 2000);

        

        prodMap.put(prod1.id, prod1, 2, TimeUnit.DAYS);

        prodMap.put(prod2.id, prod2, 2, TimeUnit.DAYS);


and this in Redis would result in something like this

hscan "ProductTable" 0 1) "0" 2) 1) "\"Prod101\"" 2) "\x00\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00{\"id\":\"Prod101\",\"name\":\"Mobile\",\"price\":1000}" 3) "\"Prod102\"" 4) "\x00\x00\x00\x00\x00\x00\x00\x00-\x00\x00\x00\x00\x00\x00\x00{\"id\":\"Prod102\",\"name\":\"Tablet\",\"price\":2000}"

While this solves the immediate problem, 2 or 3 questions arise

  1. when doing the get command - prodRet = prodMap.get("Prod101"); - does Redis need to do a 2 step lookup - first to find the "ProductTable" and then to find the prod key within that ? is this not expensive?
  2. in a Redis cluster environment the whole "ProductTable" will end up in 1 SLOT in 1 node. So whats the use of sharding across cluster ? Yes there may be other tables that may go to other nodes but no guarantees.

If someone has a better solution or better insight into this can you please share. Or am i missing something here?

appreciate your help...

Reply all
Reply to author
Forward
0 new messages