Download the latest Jedis client jedis2.8.0, found on the internet to find Jedis use the connection Pool tool class, get to find are the lower version of the Jedis notation:
Returnresource ();
Returnbrokenresource ();
These two methods expired ~, can not find the latest version of the wording, pretending to be attempted ~ ~
So went to see the source code, found that the source of comments written very clearly:
/** * @deprecatedstarting from Jedis 3.0 This method won't be exposed. * Resource cleanup should is done using@see {@linkredis.clients.jedis.jedis#close ()}*/@Override @Deprecated Public voidReturnresource (FinalJedis Resource) { if(Resource! =NULL) { Try{resource.resetstate (); Returnresourceobject (Resource); } Catch(Exception e) {Returnbrokenresource (Resource); Throw NewJedisexception ("Could not return the resource to the pool", E); } } }
With the close () method, you can follow the close () method:
@Override public void close () { if (dataSource! = Span style= "color: #0000ff;" >null if (Client.isbroken ()) { this . Datasource.returnbrokenresource (this ); else { this . Datasource.returnresource (this ); }} else {client.close (); } }
DataSource for the definition of the connection pool, if the connection pool is not empty, do some return connection operation, Jedis connection pool design is based on Org.apache.commons.pool2, these two methods are not followed, but is to change the value of the connection property to be available.
If the connection pool is empty, disconnect from the Redis service directly
So when it comes to 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 ( /span> "Set" , item, e); finally {
if (null! = Jsdis) {
"/ span> jedis.close ();
} } }
Borrow someone else's, must also ~ ~ ~
Using jedis2.8.0 to connect to Redis