1

I'm having difficulties figuring out how to access map keys using the redisson redis library. I want to be able to (with redisson) access keys that are created by a system that is not using redisson. Say I use redis-cli...

sasus:16379> hset user fname "Nancy"
(integer) 1
sasus:16379> hset user lname "Schmancy"
(integer) 1
sasus:16379> hset user email "nanc@example.org"
(integer) 1
sasus:16379> hset user system "none"
(integer) 1
sasus:16379> hgetall user
1) "fname"
2) "Nancy"
3) "lname"
4) "Schmancy"
5) "email"
6) "nanc@example.org"
7) "system"
8) "none"

Now a simple java method to retrieve...

public static void getNancy() {
    Config config = new Config();
    config.useSingleServer().setAddress("redis://sasus:16379");
    RedissonClient redisson = Redisson.create(config);
    RMap user = redisson.getMap("user");
    System.out.println("user: " + user);
    redisson.shutdown();
}

This throws a JacksonParseException...

Unrecognized token 'fname': was expecting 'null', 'true', 'false' or Nan

...on the call to getMap("user")

I see some discussion of Codecs but it's not clear to me if that is the solution. Can someone point me in the right direction? This seems like it should be a common use case.

stand
  • 3,054
  • 1
  • 24
  • 27
  • Ugh! My question got mangled. Can someone edit it to read "How do I do an HGETALL using redisson?" – stand Sep 26 '17 at 18:43

1 Answers1

0

The exception is telling you that the data Redisson has retrieved is NOT a valid JSON formatted string. You can either change the data format or use StringCodec instead of a JSON based codec.

Redisson_RuiGu
  • 1,012
  • 10
  • 13
  • It can't be the `StringCodec`. That just returns the `toString()` value of the `Map` object (e.g. `org.redisson.RedissonMap@67fe2a5a`). Is there another codec I should use? – stand Sep 27 '17 at 18:39
  • I am afraid that's exactly what you code is trying to do: To print the reference value of the `Map` object. If you want to show the content of a Map, try iterate through it and then print the key/value, or use one of the readAll methods. – Redisson_RuiGu Oct 02 '17 at 12:53