Skip to content

Instantly share code, notes, and snippets.

@kevsmith
Last active September 27, 2019 19:57
Show Gist options
  • Save kevsmith/3bb4ca74830d8ee329c3f015292d2c7a to your computer and use it in GitHub Desktop.
Save kevsmith/3bb4ca74830d8ee329c3f015292d2c7a to your computer and use it in GitHub Desktop.
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