I need to use Redis as data source in Java, so I decide to use the code:
public class RedisService {
private static final Jedis jedis = new Jedis("host",6400);;
public static Device getDevice(String key) {
// Do something use redis.
return null;
}
}
I thought the server will automatically init Jedis(Redis API for Java), it this a good way to use Jedis ?
Have a look at how we are using Jedis:
Create a singleton
org.springframework.data.redis.connection.jedis.JedisConnectionFactory
instance by passing host and port infoCreate singleton
org.springframework.data.redis.core.RedisTemplate
instance by passing the connection factory to itJust for your reference, here's the spring code that does the same, you can use if your are using spring else you can create the same using java code