Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement