javaredisredisjson

How to connect to RedisJson with JReJSON package in java?


Recently, I started working with RedisJson with node, but I also have to work with Java version of it.

I'm trying to create a connection as it is mentioned in this github repo: https://github.com/RedisJSON/JRedisJSON

The repo shows connection with "localhost", but I want to connect to my remote Redis server instance which has the URL like redis://:password@host:port.

I'm trying to pass the host and port like the following: JReJSON jsonClient = new JReJSON("redis://:password@host", port);

But I'm getting the following error saying 'Failed to create socket' and 'UnknownHostException': enter image description here

enter image description here

But, I'm able to connect to the same host from command line. Could someone point out what is the issue or what is the actual way to connect to remote instance with RedisJSON in java?

Note: I'm using Jedis - jedis-4.3.1.jar and Rejson - jrejson-1.4.0.jar


Solution

  • Part 1: About the library

    Check what the JRedisJSON home page says:

    As of Jedis 4.0.0 this library is deprecated.

    Since Jedis 4.0.0, you won't need jrejson/JRedisJSON separately. As you're already using jedis-4.3.1, you're good to go only with Jedis.

    Check their quick start.

    Part 2: About the constructor

    You want to create client object from host, post and password. Check following two constructors:

    1. new JedisPooled("redis://:password@host:port")
    2. new JedisPooled(host, port, user, password) -> new JedisPooled(host, port, null, password)