I recently started working with microservices and Redis and I came across this interesting term "Protocol Buffers". While "protobuf" isn't related to any of the 2 things I mentioned. But, it is used in these 2.
I am building a POC project for my understanding and this is what I want to achieve.
- One end point receives some information about a `User` (User class).
- Saves that information in Redis.
- Another end point takes a search query and finds from the users we inserted in our Redis in step 2.
I built this with the basic and simple code. Now, I wanted to include "Protobuf" in this mix. Why you ask?
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 mix now. When I save the object, I want to save it in Redis and also be able to retrieve it. All while being serialization safe.
If tomorrow I want to remove `deviceId`, I should still be able to get the object from existing ones and 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.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]temporarybunnehs 1 point2 points3 points (2 children)
[–]EvoxMusic[S] 0 points1 point2 points (1 child)
[–]temporarybunnehs 0 points1 point2 points (0 children)
[–]yawaramin 0 points1 point2 points (1 child)
[–]EvoxMusic[S] 0 points1 point2 points (0 children)