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

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

Introduction

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

Prototype

@Override
    public Object getNativeConnection() 

Source Link

Usage

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

@SuppressWarnings("rawtypes")
@Test/*from  w  w  w  .  ja va2 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();
}