Why does this same piece of code have different results?
I'm using Jedis 2.1.0 to create connections to Redis.
METHOD A:
private static Jedis getNewJedis() {
return new Jedis(hostname,port);
}
.....
public static main(String[] args){
getNewJedis().ping();
}
METHOD B:
public static main(String[] args){
new Jedis(hostname,port).ping();
}
I'm thinking the difference is Method A has been tucked away in a static method for ease of reuse, and hence should have the same effect as Method B when invoked.
Instead, I get an exception when I use Method A. Method B works fine!
METHOD A Exception:
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect at redis.clients.jedis.Connection.connect(Connection.java:134) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:69) at redis.clients.jedis.Connection.sendCommand(Connection.java:86) at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:82) at redis.clients.jedis.Jedis.ping(Jedis.java:34) at org.tripodwire.esme.receiver.ReceiverProducer.produceTestJedis(ReceiverProducer.java:168) at org.tripodwire.esme.entry.Entry.main(Entry.java:25)