4

I have to use Redis and Jedis in a project, in order to access quickly to some data from generated keys. The value stored will be some complex Java objects.

Is it possible to update only a part of this value, without getting it before ?

For exemple, if I serialize an object of a classe like that

public class MyObject {

    private MySubObject1 myObj1;
    private MySubObject2 myObj2;
    private MySubObject3 myObj3;

}

If MyObject is associated with a key in Redis, can I from that key only update the myObj2 field ? Or have I to get the value first, update the field and put it again in Redis ?

SebVb
  • 187
  • 1
  • 3
  • 14

1 Answers1

5

If you want to update like this. You can use a hash instead of flat key value store.

Here is the snippet

    hset("MyObject","myObj1",(serialized value of myobj1))
hset("MyObject","myObj2",(serialized value of myobj2)) ...

If you want to change myObj2 alone 

do hset("MyObject","myObj2",(new value))
Karthikeyan Gopall
  • 5,469
  • 2
  • 19
  • 35