I am building a POC Rest API project for my understanding and this is what I want to achieve.
- One end point receives some information about a
User
(User class). - Save that information about user in
Redis
. - Another end point that takes a search term (email) and finds from the users we inserted in our Redis in step 2.
I built this requirement with the basic and simple code. Now, I wanted to include "Protobuf" in this mix to be fault tolerant.
If I remove a property later on from this User
class that saves data in Redis, then it'll throw serialization exception because of old data still having that field.
Suppose User class looks like this:
class User { String name; String email; String phoneNumber; String deviceId;}
Currently I can make email
as an Id
column and find the item by that Id
. This is pretty much straightforward.
I want to use Protobuf
in this now. When I save the object, I want to save it in Redis (wither of JSON or byte[] is fine) and also be able to retrieve it. All while being serialization safe.
If tomorrow I want to remove deviceId
from the class, I should still be able to get the object from existing data in Redis and also still be able to save the new ones without deviceId
.
This can be achieved by creating Proto like this:
message User { string name = 1; string email = 2; string phoneNumber = 3; string deviceId = 4 [default = 0];}
I'm stuck at integrating "Protobuf" to automatically serialize and deserialize the objects and I'm not sure at which point I can do that.
I tried looking for some existing examples, but couldn't find anything that shows with Redis. Every other blog is just mocking dataset by creating the object from classes Protobuf generated. Which is simple enough.
Can anyone please guide me for the same.
I am using Java and pretty much new to it.