javaredispojoredis-cache

How to create single java domain class which will serve for both Redis cache(NoSQL) and Sybase ASE (Relational database)?


We are going to use Redis cache for faster performance. We require that we want to create single java domain class (for example Employee.java) which we can use for both Redis and Sybase ASE but the problem is Redis is NoSql database and Sybase ASE is a relational database. If we store Employee object as key-value pair in Redis and then if we want to store it in the database (Sybase ASE) from extracting it from Redis cache then it will create a problem. So, in short, we require a single java domain class. How can we achieve this?


Solution

  • Just serialize your Employee into a C-String value to put in Redis, for instance thanks to Kryo library. Then you just have to deserialize it from Redis to rebuild your Java instance and use it with Sybase (the other way works too).

    Any process of java serialization into a C-String (bytearray) or classic string can be used, so you can look at Jackson (JSON serialization from and to Java), JSON-schema (that generates JSON serializable java classes), MessagePack (JSON serialization with compression), FlatBuffers... Even vanilla traditional Java serialization can be used.