0

I'm using redisson (3.11.4) with spring boot (2.1.5) to store java objects.

My POJO looks like this.

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@REntity
public class ParentRecord {

    @RId
    private String id;

    private String type;

    private String root;

    private Map<String, String> children;
}

And then I go on to store my data using merge.

liveObjectService.merge(parentRecord);
messageKeyCache.put(parentRecord.getId(), parentRecord.getId(), 60, TimeUnit.SECONDS);

Once I merge I see two keys one is the actual data. redisson_live_object:{223334343322}:com.memorystore.schema.ParentRecord:id:java.lang.String and the other is redisson_live_object_field:{223334343322}:com.memorystore.schema.ParentRecord:children:org.redisson.RedissonMap

I can delete the first key by doing liveObjectService.delete(ParentRecord.class, someId); but that doesn't delete the second key. Shouldn't it be deleted when I delete the first key? If not then how do I delete it?

afzal
  • 33
  • 4

1 Answers1

0

1) Add @RCascade annotation:

@RCascade(RCascadeType.ALL)
private Map<String, String> children;

2) Delete object:

public void deleteByKey(K key) {
    T object = findByKey(key);
    liveObjectService.delete(object);
}

private T findByKey(K key) {
    return liveObjectService.get(type, key);
}

where type - some class(ParentRecord.class).

Andr
  • 16
  • 1