1

I'm using Jedis to store some documents on Redis. I have the following class:

public class Document{
      public String id;
      public String title;
      public Map<String, Keyword> keywords = new HashMap<>();
  }

I used sadd to add a set to Redis. I tried the following code:

Document d = new Document();
jedis.sadd(d.id,d.title);

But I don't know how to add the map in the set.

Cyber
  • 49
  • 1
  • 13

1 Answers1

1

The basic approach, afaik, is to serialize the map before adding it to the set. Note that Redis' sets are made of unique members, where each member is a string value (byte stream in the Java world iirc).

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • what do you mean by serializing? – Cyber Feb 27 '18 at 13:24
  • I mean converting to some representation that can be stored as a Redis string - it can be a text-only (e.g. JSON) value or any other encoding whether ready-made (e.g. MessagePack), handmade or if the language/framework offers this as a capability (idk about Java). – Itamar Haber Feb 27 '18 at 14:46
  • :) java.io.serializable as per https://stackoverflow.com/questions/49067689/how-to-serialize-a-map-in-java-to-store-on-redis – Itamar Haber Mar 02 '18 at 11:17