Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Redis performance

I'm working on fetching huge amount of data(millions of records) and plan is to keep frequent records in cache and fetch from cache for quick responses. I'm using NoSQL database and have around 35k records in the cache. I'm using this piece of code to check if its cached,

redistemplate.opsForHash().entries("key").size() == 0, 

if the condition satifies,

redistemplate.opsForHash().put("key", "KeyValue", List);

if not,

(List) redistemplate.opsForHash().entries("Key").get("KeyValue");

But when I'm checking the performance, fetching from DB is faster than fetching from cache. I'm just trying the basic redis caching, not sure if it is recommended. Please provide inputs.

like image 831
ashK Avatar asked Sep 20 '26 17:09

ashK


2 Answers

You are dealing with entries.. why !? You can use template function directly to access keys or values.

To check the condition:

redisTemplate.hasKey("key");

if doesn't satisfy:

redistemplate.opsForHash().put("key", "hashKey", List);

else

redisTemplate.opsForHash().get("key", "hashKey");

I think this will enhance the performance.

on the other hand, try to find where the delay exactly is. ie. which call is causing the delay?

like image 139
Nebras Avatar answered Sep 24 '26 02:09

Nebras


I made another way of resolving it, instead of OpsForHash, I tried OpsForList which is much faster.

like image 21
ashK Avatar answered Sep 24 '26 00:09

ashK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!