Cannot open Redis connection due invalid URI
See original GitHub issueWe 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 InvalidURIException
show 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:
- Created 8 years ago
- Comments:6
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
I fix it,by do this: http://blog.csdn.net/running_snail_/article/details/51679538