Jedis not thread-safe , so why not use thread-safety problems?
Tell me what network directly to: Jedis Wiki
To guarantee thread safety and achieve better performance. It can be used JedisPool. JedisPool is a connection pool, both to ensure thread safety, but also to ensure high efficiency.
JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");
JedisPool obtained using a method such as the following example Jedis:
/// Jedis implements Closeable. Hence, the jedis instance will be auto-closed after the last statement.
try (Jedis jedis = pool.getResource()) {
/// ... do stuff here ... for example
jedis.set("foo", "bar");
String foobar = jedis.get("foo");
jedis.zadd("sose", 0, "car"); jedis.zadd("sose", 0, "bike");
Set<String> sose = jedis.zrange("sose", 0, -1);
}
/// ... when closing your application:
pool.close();
The above procedure by first pool.getResource()
obtaining a Jedis example. Then use this example Jedis transmission instruction operation to Redisserver, Jedis last call class close
method. Examples of this Jedis returned to JedisPool.