Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis - Approach for Storing Data Into Redis :: JSON String OR Serialized pojo

I have a class like below:

   public class Person
      {
         public String name;
         public String age;
      }

I am a bit confused over the approach of saving a Map of Perons into Redis:

Should I go for java serialized/deserialized object approach or should i try converting to JSON and then storing and vice versa.

Any thoughts on below mentioned points:

  • Cost of serialization and deserialization VS cost of mapping to Java and to JSON
  • memory Requirement for JSON and serialized object for Redis
  • Compression : Stream vs Data

    Which compression should we go for Though DATA compression seems a bit difficult(not much benificial) as we are using Redish Hash

Some of the assumptions are:

  • The pojo contain many instancd variables
  • will be using Redis hash to store object
like image 714
Santosh Joshi Avatar asked Nov 09 '13 05:11

Santosh Joshi


People also ask

Can JSON be stored in Redis?

The RedisJSON module provides JSON support for Redis. RedisJSON lets you store, update, and retrieve JSON values in a Redis database, similar to any other Redis data type. RedisJSON also works seamlessly with RediSearch to let you index and query JSON documents.

What is Redis JSON?

RedisJSON is a high-performance NoSQL document store that allows developers to build modern applications. It provides native APIs to ingest, index, query, and run full-text search on JSON documents both on-premises and as a managed service in the cloud.

Is Redis serialized?

Serialization/Deserializarion with Spring Data Redis(SDR)There are several prepared implemented classes responsible for serialization/deserialization for some kind of types provided by RedisTemplate by default. In case of specific requirement you can implement your custom serializer.


1 Answers

You should consider using MessagePack as it is full compatible with Redis and Lua, it is a great compression on JSON: http://msgpack.org/

It implies some Lua code to compress and uncompress, but the cost should be small. Here is an example: http://gists.fritzy.io/2013/11/06/store-json-as-msgpack

There is a small benchmark which lacks data: https://gist.github.com/muga/1119814

Still it should be a great option for you, as you can use it in different languages, fully supported on redis, and it is based on JSON.

like image 148
zenbeni Avatar answered Oct 02 '22 02:10

zenbeni