Reputation: 119
What is the best way to store a nested and complex java object in Redis. The way we are doing is as follows.
We are using Redisson java client library for Redis interactions. Please see the code below :
try{
Config conf = new Config();
conf.useSingleServer().setTimeout(3600000);
conf.useSingleServer().setRetryInterval(3600000);
conf.useSingleServer().setAddress("redis://127.0.0.1:6379");
RedissonClient redisson = Redisson.create(conf);
RMap<String,Object> map = redisson.getMap("myCache");
MyClass myObject; // This is the big complex object.
map.put("key", myObject);
redisson.shutdown();
}catch (Exception ex) {
ex.printStackTrace();
}
Similarly, instead of put, we are using get to fill our myObject from redis.
We have increased the timeouts because of big size data being stored in redis, We were getting following exception :
Command execution timeout for command: (EVAL) with params...
Please answer the following questions as well :
Thanks.
Upvotes: 3
Views: 10196
Reputation: 1032
I think your problem is actually two problems put together: Complex object and Huge object.
So let me break it down and talk about them one by one:
myObject.getField1()
if would only fetch one field from Redis instead of the entire object like shown in your example. There are two articles on DZone which can help you understand Redisson Live Object a bit more: Introducing Redisson Live Objects (Object Hash Mapping)(written by myself) and A Look at the Java Distributed In-Memory Data Model (Powered by Redis)(written by Nikita Koksharov)
Redisson binary stream is achieved by mapping the data to a Redis string object and it will split the data into chunks when necessary. You can find the usage of Redisson binary stream at the project wiki page.
Upvotes: 7