Last active
September 27, 2019 19:57
-
-
Save kevsmith/3bb4ca74830d8ee329c3f015292d2c7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Foo { | |
private RedisConnection _connection; | |
public void doSomething() { | |
// get connection from existing pool | |
// store ref to connection in object state | |
_connection = RedisConnectionPool.get().checkout(); | |
try { | |
// write or read data from Redis here | |
} | |
finally { | |
// release connection back to pool | |
// retain connection ref in object state (whoops!) | |
RedisConnectionPool.get().checkin(_connection); | |
} | |
} | |
public void cleanUp() { | |
// close connection when cleaning up object instance | |
// even though the connection is owned by pool (double whoops!) | |
if (_connection) { | |
_connection.close(); | |
_connection = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment