Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is updating a part of a value possible in Redis?

Tags:

redis

jedis

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 ?

like image 961
SebVb Avatar asked Sep 05 '25 03:09

SebVb


1 Answers

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))
like image 51
Karthikeyan Gopall Avatar answered Sep 07 '25 23:09

Karthikeyan Gopall