List of usage examples for org.springframework.data.redis.connection RedisConnection ping
@Nullable String ping();
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Test connection./*from w ww . jav a 2 s . co m*/ * <p> * See http://redis.io/commands/ping * * @return Server response message - usually {@literal PONG}. */ public static String ping() { return redisTemplate.execute(new RedisCallback<String>() { @Override public String doInRedis(RedisConnection redis) throws DataAccessException { return redis.ping(); } }); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Test connection./*from w ww.j a v a 2 s. com*/ * <p> * See http://redis.io/commands/ping * * @return Server response message - usually {@literal PONG}. */ public String ping() { return redisTemplate.execute(new RedisCallback<String>() { @Override public String doInRedis(RedisConnection redis) throws DataAccessException { return redis.ping(); } }); }
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();// ww w . j a va 2 s. c om conn2.ping(); }
From source file:org.springframework.data.redis.connection.jredis.JRedisConnectionIntegrationTests.java
@Test public void testConnectionNotReturnedOnException() { GenericObjectPoolConfig config = new GenericObjectPoolConfig(); config.setMaxTotal(1);/*from w w w . j a v a2s. co m*/ 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
@Ignore("Redis must have requirepass set to run this test") @Test//from w w w. j ava2s.co m 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(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-687 public void connectsThroughRedisSocket() { assumeTrue(EpollProvider.isAvailable() || KqueueProvider.isAvailable()); assumeTrue(new File(SettingsUtils.getSocket()).exists()); LettuceClientConfiguration configuration = LettuceTestClientConfiguration.create(); LettuceConnectionFactory factory = new LettuceConnectionFactory(SettingsUtils.socketConfiguration(), configuration);/*from ww w . java 2 s . c om*/ factory.setShareNativeConnection(false); factory.afterPropertiesSet(); RedisConnection connection = factory.getConnection(); assertThat(connection.ping(), is(equalTo("PONG"))); connection.close(); factory.destroy(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-762, DATAREDIS-869 public void factoryUsesElastiCacheMasterReplicaConnections() { assumeThat(String.format("No slaves connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()), connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true)); LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE) .build();/* w w w . j a va2 s. com*/ RedisStaticMasterReplicaConfiguration elastiCache = new RedisStaticMasterReplicaConfiguration( SettingsUtils.getHost()).node(SettingsUtils.getHost(), SettingsUtils.getPort() + 1); LettuceConnectionFactory factory = new LettuceConnectionFactory(elastiCache, configuration); factory.afterPropertiesSet(); RedisConnection connection = factory.getConnection(); try { assertThat(connection.ping(), is(equalTo("PONG"))); assertThat(connection.info().getProperty("role"), is(equalTo("slave"))); } finally { connection.close(); } factory.destroy(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-762, DATAREDIS-869 public void factoryUsesElastiCacheMasterWithoutMaster() { assumeThat(//from ww w .j av a 2s .com String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()), connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true)); LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder() .readFrom(ReadFrom.MASTER).build(); RedisStaticMasterReplicaConfiguration elastiCache = new RedisStaticMasterReplicaConfiguration( SettingsUtils.getHost(), SettingsUtils.getPort() + 1); LettuceConnectionFactory factory = new LettuceConnectionFactory(elastiCache, configuration); factory.afterPropertiesSet(); RedisConnection connection = factory.getConnection(); try { connection.ping(); fail("Expected RedisException: Master is currently unknown"); } catch (RedisSystemException e) { assertThat(e.getCause(), is(instanceOf(RedisException.class))); assertThat(e.getCause().getMessage(), containsString("Master is currently unknown")); } finally { connection.close(); } factory.destroy(); }
From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java
@Test // DATAREDIS-580, DATAREDIS-869 public void factoryUsesMasterReplicaConnections() { assumeThat(//w w w . ja v a2s.c o m String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()), connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true)); LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE) .build(); LettuceConnectionFactory factory = new LettuceConnectionFactory(SettingsUtils.standaloneConfiguration(), configuration); factory.afterPropertiesSet(); RedisConnection connection = factory.getConnection(); try { assertThat(connection.ping(), is(equalTo("PONG"))); assertThat(connection.info().getProperty("role"), is(equalTo("slave"))); } finally { connection.close(); } factory.destroy(); }