Examples of RedisConnection


Examples of org.springframework.data.redis.connection.RedisConnection

    GenericObjectPoolConfig config = new GenericObjectPoolConfig();
    config.setMaxTotal(1);
    config.setMaxWaitMillis(1);
    JredisConnectionFactory factory2 = new JredisConnectionFactory(new JredisPool(SettingsUtils.getHost(),
        SettingsUtils.getPort(), config));
    RedisConnection conn2 = factory2.getConnection();
    ((JRedis) conn2.getNativeConnection()).quit();
    try {
      conn2.ping();
      fail("Expected RedisConnectionFailureException trying to use a closed connection");
    } catch (RedisConnectionFailureException e) {}
    conn2.close();
    // Verify we get a new connection from the pool and not the broken one
    RedisConnection conn3 = factory2.getConnection();
    conn3.ping();
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

  }

  @Test
  public void testValidateNoError() {
    factory.setValidateConnection(true);
    RedisConnection conn2 = factory.getConnection();
    assertSame(connection.getNativeConnection(), conn2.getNativeConnection());
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

  @SuppressWarnings("unchecked")
  @Test
  public void testDisableSharedConnection() throws Exception {
    factory.setShareNativeConnection(false);
    RedisConnection conn2 = factory.getConnection();
    assertNotSame(connection.getNativeConnection(), conn2.getNativeConnection());
    // Give some time for native connection to asynchronously initialize, else close doesn't work
    Thread.sleep(100);
    conn2.close();
    assertTrue(conn2.isClosed());
    // Give some time for native connection to asynchronously close
    Thread.sleep(100);
    try {
      ((RedisAsyncConnection<byte[], byte[]>) conn2.getNativeConnection()).ping();
      fail("The native connection should be closed");
    } catch (RedisException e) {
      // expected
    }
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

  @Test
  public void testInitConnection() {
    RedisAsyncConnection<byte[], byte[]> nativeConn = (RedisAsyncConnection<byte[], byte[]>) connection
        .getNativeConnection();
    factory.initConnection();
    RedisConnection newConnection = factory.getConnection();
    assertNotSame(nativeConn, newConnection.getNativeConnection());
    newConnection.close();
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

  public void testResetAndInitConnection() {
    RedisAsyncConnection<byte[], byte[]> nativeConn = (RedisAsyncConnection<byte[], byte[]>) connection
        .getNativeConnection();
    factory.resetConnection();
    factory.initConnection();
    RedisConnection newConnection = factory.getConnection();
    assertNotSame(nativeConn, newConnection.getNativeConnection());
    newConnection.close();
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

  public void testCreateFactoryWithPool() {
    DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.afterPropertiesSet();
    LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
    factory2.afterPropertiesSet();
    RedisConnection conn2 = factory2.getConnection();
    conn2.close();
    factory2.destroy();
    pool.destroy();
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

  @Ignore("Redis must have requirepass set to run this test")
  @Test
  public void testConnectWithPassword() {
    factory.setPassword("foo");
    factory.afterPropertiesSet();
    RedisConnection conn = factory.getConnection();
    // Test shared and dedicated conns
    conn.ping();
    conn.bLPop(1, "key".getBytes());
    conn.close();
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

  public void testClosePooledConnectionWithShared() {
    DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.afterPropertiesSet();
    LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
    factory2.afterPropertiesSet();
    RedisConnection connection = factory2.getConnection();
    // Use the connection to make sure the channel is initialized, else nothing happens on close
    connection.ping();
    connection.close();
    // The shared connection should not be closed
    connection.ping();

    // The dedicated connection should not be closed b/c it's part of a pool
    connection.multi();
    connection.close();
    factory2.destroy();
    pool.destroy();
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

    DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
    pool.afterPropertiesSet();
    LettuceConnectionFactory factory2 = new LettuceConnectionFactory(pool);
    factory2.setShareNativeConnection(false);
    factory2.afterPropertiesSet();
    RedisConnection connection = factory2.getConnection();
    // Use the connection to make sure the channel is initialized, else nothing happens on close
    connection.ping();
    connection.close();
    // The dedicated connection should not be closed
    connection.ping();

    connection.close();
    factory2.destroy();
    pool.destroy();
  }
View Full Code Here

Examples of org.springframework.data.redis.connection.RedisConnection

  @Test
  public void testCloseNonPooledConnectionNotShared() {
    LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
    factory2.setShareNativeConnection(false);
    factory2.afterPropertiesSet();
    RedisConnection connection = factory2.getConnection();
    // Use the connection to make sure the channel is initialized, else nothing happens on close
    connection.ping();
    connection.close();
    // The dedicated connection should be closed
    try {
      connection.set("foo".getBytes(), "bar".getBytes());
      fail("Exception should be thrown trying to use a closed connection");
    } catch (RedisSystemException e) {}
    factory2.destroy();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.