Example usage for org.springframework.data.redis.connection DefaultStringRedisConnection close

List of usage examples for org.springframework.data.redis.connection DefaultStringRedisConnection close

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection DefaultStringRedisConnection close.

Prototype

@Override
    public void close() throws RedisSystemException 

Source Link

Usage

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@SuppressWarnings("rawtypes")
@Test// w  ww.j  a v a  2 s. c om
public void testGetNewConnectionOnError() throws Exception {
    factory.setValidateConnection(true);
    connection.lPush("alist", "baz");
    RedisAsyncCommands nativeConn = (RedisAsyncCommands) connection.getNativeConnection();
    nativeConn.getStatefulConnection().close();
    // Give some time for async channel close
    Thread.sleep(500);
    connection.bLPop(1, "alist".getBytes());
    try {
        connection.get("test3");
        fail("Expected exception using natively closed conn");
    } catch (RedisSystemException e) {
        // expected, shared conn is closed
    }
    DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection());
    assertNotSame(nativeConn, conn2.getNativeConnection());
    conn2.set("anotherkey", "anothervalue");
    assertEquals("anothervalue", conn2.get("anotherkey"));
    conn2.close();
}

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@SuppressWarnings("rawtypes")
@Test//from  ww w .  j  ava  2s  .c o m
public void testConnectionErrorNoValidate() throws Exception {
    connection.lPush("ablist", "baz");
    ((RedisAsyncCommands) connection.getNativeConnection()).getStatefulConnection().close();
    // Give some time for async channel close
    Thread.sleep(500);
    DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory.getConnection());
    try {
        conn2.set("anotherkey", "anothervalue");
        fail("Expected exception using natively closed conn");
    } catch (RedisSystemException e) {
        // expected, as we are re-using the natively closed conn
    } finally {
        conn2.close();
    }
}