SGiux
SGiux

Reputation: 839

Store directly JSON documents instead of String with RedisJSON improve reading performance?

I'm using Spring Data Redis and using Redis as Cache where I'm storing java objects. Currently I'm using the Redis Template (https://docs.spring.io/spring-data/redis/reference/redis/template.html). Objects are serialized/deserialized by the template and I'm using this Serializer (https://github.com/EsotericSoftware/kryo). The bytes, output of the serialization, are stored in Redis (as Redis String type I guess). When reading from cache, the byte will be deserialized into a java object.

I attended the ru204 course and I'm wondering: if I store JSON Documents, theoretically, would the retrieval of the document from the cache faster from a final client prospective (latency + running application code)? What it is written in the course is

" The traditional approach to storing JSON documents in Redis has been to serialize them to Strings. Serialization happens in application code, with the resulting String value saved in Redis using the SET command. Reading or updating JSON documents stored in this way can be a costly operation. The entire document needs to be deserialized back, a process that usually happens in your application's code. "

But anyway, the JSON document has to be deserialize into the java object. So deserialization happens anyway in the application even if Redis stores a JSON Document as JSON type. So from what I understood JSON Document type make sense if you don't need to retrieve the entire document all the times. Is that right? In case the full document is always needed, storing a String or a JSON Document don't make any difference...

So in my use case RedisJSON doesn't give any benefits.

Upvotes: 0

Views: 311

Answers (0)

Related Questions