Connect to redis using jedis2.8.0 and connect to redis using jedis2.8.0
Download the latest jedis client jedis2.8.0 and find the tool class for using the connection pool of jedis on the Internet. It is found that the jedis is of a lower version:
ReturnResource ();
ReturnBrokenResource ();
The two methods have expired ~, Unable to find the latest version, force Installation failed ~~
So I looked at the source code and found that the comments of the source code were clearly written:
/** * @deprecated starting from Jedis 3.0 this method will not be exposed. * Resource cleanup should be done using @see {@link redis.clients.jedis.Jedis#close()} */ @Override @Deprecated public void returnResource(final Jedis resource) { if (resource != null) { try { resource.resetState(); returnResourceObject(resource); } catch (Exception e) { returnBrokenResource(resource); throw new JedisException("Could not return the resource to the pool", e); } } }
You can use the close () method to trace the close () method:
@Override public void close() { if (dataSource != null) { if (client.isBroken()) { this.dataSource.returnBrokenResource(this); } else { this.dataSource.returnResource(this); } } else { client.close(); } }
DataSource is the defined connection pool. If the connection pool is not empty, perform some restore operations. The jedis connection pool is designed based on org. apache. commons. pool2, these two methods are not followed, but the connection property value is changed to available and so on.
If the connection pool is empty, the connection to the redis service will be disconnected ~
So when writing some basic classes, it should look like this:
public <T> void set(T item) { Jedis jedis =null; try { jedis = JedisClient.getJedis(); String v = cacheKeyUtil.getDefaultKey(item); jedis.set(v, iserializer.serialize(item)); } catch (Exception e) { logger.warn("set", item, e); } finally {
if(null != jsdis){
jedis.close();
} } }
If you borrow from someone else, you must pay it back ~~~