List of usage examples for org.springframework.data.redis.connection RedisConnection close
void close() throws DataAccessException;
From source file:stormy.pythian.service.topology.TopologyRepositoryIntegrationTest.java
@After @Before/*from w ww . ja v a2 s . c om*/ public void cleanRedisDB() { RedisConnection connection = redisTemplate.getConnectionFactory().getConnection(); connection.flushDb(); connection.close(); }
From source file:com.miko.demo.mongo.service.RedisPublishSubscribeTest.java
@Test public void testRedisSubNoConversation() { RedisConnection redis = connectionFactory.getConnection(); try {/* w w w.j a va2s . co m*/ redis.publish(DUMP_CHANNEL.getBytes(), "Hello World!".getBytes()); } finally { redis.close(); } }
From source file:com.gopivotal.cloudfoundry.test.core.RedisUtils.java
public String checkAccess(RedisConnectionFactory redisConnectionFactory) { RedisConnection connection = null; try {// ww w . ja v a 2 s. c o m connection = redisConnectionFactory.getConnection(); connection.echo("hello".getBytes()); return "ok"; } catch (Exception e) { return "failed with " + e.getMessage(); } finally { try { if (connection != null) { connection.close(); } } catch (Exception e) { return "Redis connection close failed with " + e.getMessage(); } } }
From source file:com.hurence.logisland.redis.service.RedisKeyValueCacheService.java
private <T> T withConnection(final RedisAction<T> action) throws IOException { RedisConnection redisConnection = null; try {/* w w w .j a v a 2 s . com*/ redisConnection = redisConnectionPool.getConnection(); return action.execute(redisConnection); } finally { if (redisConnection != null) { try { redisConnection.close(); } catch (Exception e) { getLogger().warn("Error closing connection: " + e.getMessage(), e); } } } }
From source file:com.miko.demo.mongo.service.RedisPublishSubscribeTest.java
@Test public void testPubSubWithConversion() { RedisConnection redis = connectionFactory.getConnection(); RedisMessageListenerContainer listeners = new RedisMessageListenerContainer(); listeners.setConnectionFactory(connectionFactory); MessageListenerAdapter listener = new MessageListenerAdapter(new BeanMessageListener()); listener.setSerializer(new BeanMessageSerializer()); listener.afterPropertiesSet();//w w w. j a va 2 s.c o m listeners.addMessageListener(listener, new ChannelTopic(DUMP_CHANNEL)); listeners.afterPropertiesSet(); listeners.start(); try { redis.publish(DUMP_CHANNEL.getBytes(), "Hello World!".getBytes()); } finally { redis.close(); listeners.stop(); } }
From source file:org.springframework.data.redis.connection.jredis.JRedisConnectionIntegrationTests.java
@Test public void testConnectionStaysOpenWhenPooled() { JredisConnectionFactory factory2 = new JredisConnectionFactory( new JredisPool(SettingsUtils.getHost(), SettingsUtils.getPort())); RedisConnection conn2 = factory2.getConnection(); conn2.close(); conn2.ping();/*from w w w .j a va 2 s . c o m*/ }
From source file:org.springframework.data.redis.connection.jredis.JRedisConnectionIntegrationTests.java
@Test public void testConnectionNotReturnedOnException() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1);// ww w . j a v a 2s.c om 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(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@SuppressWarnings("unchecked") @Test/*from w w w . j av a2 s. c om*/ 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 { ((RedisAsyncCommands<byte[], byte[]>) conn2.getNativeConnection()).ping(); fail("The native connection should be closed"); } catch (RedisException e) { // expected } }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@SuppressWarnings("unchecked") @Test//from w ww . j a v a 2 s .c o m public void testInitConnection() { RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection .getNativeConnection(); factory.initConnection(); RedisConnection newConnection = factory.getConnection(); assertNotSame(nativeConn, newConnection.getNativeConnection()); newConnection.close(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@SuppressWarnings("unchecked") @Test//from w w w. j a v a 2s . com public void testResetAndInitConnection() { RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection .getNativeConnection(); factory.resetConnection(); factory.initConnection(); RedisConnection newConnection = factory.getConnection(); assertNotSame(nativeConn, newConnection.getNativeConnection()); newConnection.close(); }