question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot open Redis connection due invalid URI

See original GitHub issue

We integrated Jedis with Spring in our project, tried to use Redis as our message queue to send mails. But today, I met something so weird when starting up my mail service–this “InvalidURIException” came up casually and seemed there were no patterns to reproduce the problem.

Details

There is a main method to get my redis configuration.Here is the main

public static void main(String[] args) throws Exception{
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath*:spring/*.xml");
        context.start();
    }

and applicationContext-redis.xml here:

 <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
      <property name="maxTotal" value="${redis.maxTotal}"/>
      <property name="maxIdle" value="${redis.maxIdle}"/>
      <property name="maxWaitMillis" value="${redis.maxWaitMillis}"/>
      <property name="testOnBorrow" value="${redis.testOnBorrow}"/>
      <property name="testOnReturn" value="${redis.testOnReturn}"/>
      <property name="testWhileIdle" value="${redis.testWhileIdle}"/>
      <property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}"/>
      <property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}"/>
      <property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}"/>
    </bean>

    <bean id = "jedisPool" class="redis.clients.jedis.JedisPool">
      <constructor-arg index="0" ref="jedisPoolConfig"/>
      <constructor-arg index="1" value="${redis.ip}"/>
      <constructor-arg index="2" value="${redis.port}" type="int"/>
      <constructor-arg index="3" value="${redis.timeout}" type="int"/>
      <!-- <constructor-arg index="4" value="${redis.password}"/> -->
    </bean>
# redis configuration
redis.ip=my ip address
redis.port=my port
redis.timeout=60000
redis.maxTotal=5000
redis.maxIdle=256
redis.maxWaitMillis=5000
redis.testOnBorrow=true
redis.testOnReturn=true
redis.testWhileIdle=true
redis.minEvictableIdleTimeMillis=60000
redis.timeBetweenEvictionRunsMillis=3000
redis.numTestsPerEvictionRun=-1

Where running this main method, I noticed there is a NPE here in redis.clients.util.JedisURIHelper.isValid(URI) Line 31 which uri.getScheme() is null.

Weird thing is that InvalidURIExceptionshow up randomly when running main method several times. Is there something wrong with configuration *.xml or initializing JedisPool or JedisPoolConfig?

Temporary solution

We changed Jedis into Spring-data-redis in out *.xml, it worked well.

Is anyone aware of what’s going on?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
mkantecommented, Aug 7, 2016

After reading the source code I figured it out. You must change your URI to: redis.url= redis://{ip_address}:{port}/{database} example: redis.url= redis://localhost:6379/3

2reactions
workchengcommented, Sep 26, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot open Redis connection due invalid URI #1161 - GitHub
Where running this main method, I noticed there is a NPE here in redis.clients.util.JedisURIHelper.isValid(URI) Line 31 which uri.getScheme() is ...
Read more >
Cannot open Redis connection due invalid URI in Linux
I developed it under windows, and there was no problem with redis . I started to prompt Cannot open Redis connection due invalid...
Read more >
JedisPool Connection Refused Spring Boot - Stack Overflow
I am able to connect to the Redis Server via redis-cli but not from my spring boot app. Any ideas on how to...
Read more >
Invalid URI error while connecting to Redis backend
Issue. Current configuration has no authentication to backend redis. Below is the existing string. redis://backend-redis:6379/1.
Read more >
Java Examples for redis.clients.jedis.exceptions ... - Javatips.net
isValid(uri)) { throw new InvalidURIException(String.format("Cannot open Redis connection due invalid URI. %s", uri.toString())); } client = new Client(uri.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found