本文整理了Java中redis.clients.jedis.Jedis.ping()
方法的一些代码示例,展示了Jedis.ping()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.ping()
方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:ping
[英]Works same as ping() but returns argument message instead of PONG.
[中]工作原理与ping()相同,但返回参数消息而不是PONG。
代码示例来源:origin: sohutv/cachecloud
private Jedis getRunningJedis(){
Jedis jedis = null;
for (JedisPool jp : cache.getNodes().values()) {
try {
jedis = jp.getResource();
if (jedis.ping().equalsIgnoreCase("PONG")) {
return jedis;
}
} catch (Exception e) {
//ignore
}
}
return jedis;
}
}
代码示例来源:origin: sohutv/cachecloud
@Override
public boolean validateObject(PooledObject<ShardedJedis> pooledShardedJedis) {
try {
ShardedJedis jedis = pooledShardedJedis.getObject();
for (Jedis shard : jedis.getAllShards()) {
if (!shard.ping().equals("PONG")) {
return false;
}
}
return true;
} catch (Exception ex) {
return false;
}
}
代码示例来源:origin: jfinal/jfinal
/**
* 使用客户端向 Redis 服务器发送一个 PING ,如果服务器运作正常的话,会返回一个 PONG 。
* 通常用于测试与服务器的连接是否仍然生效,或者用于测量延迟值。
*/
public String ping() {
Jedis jedis = getJedis();
try {
return jedis.ping();
}
finally {close(jedis);}
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Jedis getConnection() {
// In antirez's redis-rb-cluster implementation,
// getRandomConnection always return valid connection (able to
// ping-pong)
// or exception if all connections are invalid
List<JedisPool> pools = getShuffledNodesPool();
for (JedisPool pool : pools) {
Jedis jedis = null;
try {
jedis = pool.getResource();
if (jedis == null) {
continue;
}
String result = jedis.ping();
if (result.equalsIgnoreCase("pong")) return jedis;
pool.returnBrokenResource(jedis);
} catch (JedisConnectionException ex) {
if (jedis != null) {
pool.returnBrokenResource(jedis);
}
}
}
throw new JedisConnectionException("no reachable node in cluster");
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
protected boolean isActive(RedisNode node) {
Jedis temp = null;
try {
temp = getJedis(node);
temp.connect();
return temp.ping().equalsIgnoreCase("pong");
} catch (Exception e) {
return false;
} finally {
if (temp != null) {
temp.disconnect();
temp.close();
}
}
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testPing() throws Exception {
try (Jedis jedis = pool.getResource()) {
Assert.assertEquals("PONG", jedis.ping());
}
}
代码示例来源:origin: spring-projects/spring-data-redis
private Jedis getActiveSentinel() {
Assert.isTrue(RedisConfiguration.isSentinelConfiguration(configuration), "SentinelConfig must not be null!");
for (RedisNode node : ((SentinelConfiguration) configuration).getSentinels()) {
Jedis jedis = new Jedis(node.getHost(), node.getPort(), getConnectTimeout(), getReadTimeout());
if (jedis.ping().equalsIgnoreCase("pong")) {
potentiallySetClientName(jedis);
return jedis;
}
}
throw new InvalidDataAccessResourceUsageException("No Sentinel found");
}
代码示例来源:origin: sohutv/cachecloud
public Jedis getNewJedis(String channel, int timeout) {
Jedis jedis = getJedis(channel);
try {
String host = jedis.getClient().getHost();
int port = jedis.getClient().getPort();
Jedis newJedis = new Jedis(host, port, timeout);
String pong = newJedis.ping();
if (pong == null || !pong.equals("PONG")) {
throw new JedisException("SubPubCluster:jedis is not ping !");
}
return newJedis;
} finally {
releaseConnection(jedis);
}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public String ping() {
try {
if (isPipelined()) {
pipeline(newJedisResult(getRequiredPipeline().ping()));
return null;
}
if (isQueueing()) {
transaction(newJedisResult(getRequiredTransaction().ping()));
return null;
}
return jedis.ping();
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}
代码示例来源:origin: uber/chaperone
public void open(Jedis jedis) {
this.jedis = jedis;
logger.info("Deduplicator={} connected to Redis server host={}, port={}, ping={}", identity, "testMode", -1,
jedis.ping());
}
代码示例来源:origin: uber/chaperone
public void open() {
jedis = new Jedis(redisHost, redisPort);
logger.info("Deduplicator={} connected to Redis server host={}, port={}, ping={}", identity, redisHost, redisPort,
jedis.ping());
}
代码示例来源:origin: uber/chaperone
public RedisMonitor(long checkIntervalInSec, String redisHost, int redisPort, long maxMemBytes, String maxMemPolicy) {
this.checkIntervalInSec = checkIntervalInSec;
jedis = new Jedis(redisHost, redisPort);
logger.info("RedisMonitor connected to Redis server: {}", jedis.ping());
setRedisConfig("maxmemory", maxMemBytes + "");
setRedisConfig("maxmemory-policy", maxMemPolicy);
cronExecutor =
Executors
.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("redis-monitor-%d").build());
}
代码示例来源:origin: spinnaker/kayenta
@Bean
HealthIndicator redisHealth(JedisPool jedisPool) {
return () -> {
Jedis jedis = null;
Health.Builder health = null;
try {
jedis = jedisPool.getResource();
if ("PONG".equals(jedis.ping())) {
health = Health.up();
} else {
health = Health.down();
}
} catch (Exception ex) {
health = Health.down(ex);
} finally {
if (jedis != null) {
jedis.close();
}
}
return health.build();
};
}
}
代码示例来源:origin: com.netflix.dyno/dyno-jedis
@Override
public void execPing() {
final String result;
try {
result = jedisClient.ping();
} catch (JedisConnectionException e) {
throw new DynoConnectException("Unsuccessful ping", e);
}
if (result == null || result.isEmpty()) {
throw new DynoConnectException("Unsuccessful ping, got empty result");
}
}
代码示例来源:origin: UncleCatMySelf/InChat
private RedisConfig(){
if (ConfigFactory.initNetty.getDistributed()){
this.jedis = new Jedis(ConfigFactory.RedisIP);
log.info(LogConstant.REDIS_START + jedis.ping());
}
}
代码示例来源:origin: yangfuhai/jboot
/**
* 使用客户端向 JbootRedis 服务器发送一个 PING ,如果服务器运作正常的话,会返回一个 PONG 。
* 通常用于测试与服务器的连接是否仍然生效,或者用于测量延迟值。
*/
public String ping() {
Jedis jedis = getJedis();
try {
return jedis.ping();
} finally {
returnResource(jedis);
}
}
代码示例来源:origin: com.jfinal/jfinal
/**
* 使用客户端向 Redis 服务器发送一个 PING ,如果服务器运作正常的话,会返回一个 PONG 。
* 通常用于测试与服务器的连接是否仍然生效,或者用于测量延迟值。
*/
public String ping() {
Jedis jedis = getJedis();
try {
return jedis.ping();
}
finally {close(jedis);}
}
代码示例来源:origin: org.nutz/nutz-integration-jedis
public String ping() {
Jedis jedis = getJedis();
try {
return jedis.ping();
} finally {Streams.safeClose(jedis);}
}
代码示例来源:origin: com.github.sogyf/goja-jfinal
/**
* 使用客户端向 Redis 服务器发送一个 PING ,如果服务器运作正常的话,会返回一个 PONG 。
* 通常用于测试与服务器的连接是否仍然生效,或者用于测量延迟值。
*/
public String ping() {
Jedis jedis = getJedis();
try {
return jedis.ping();
}
finally {close(jedis);}
}
代码示例来源:origin: org.springframework.data/spring-data-redis
private Jedis getActiveSentinel() {
Assert.isTrue(RedisConfiguration.isSentinelConfiguration(configuration), "SentinelConfig must not be null!");
for (RedisNode node : ((SentinelConfiguration) configuration).getSentinels()) {
Jedis jedis = new Jedis(node.getHost(), node.getPort(), getConnectTimeout(), getReadTimeout());
if (jedis.ping().equalsIgnoreCase("pong")) {
potentiallySetClientName(jedis);
return jedis;
}
}
throw new InvalidDataAccessResourceUsageException("No Sentinel found");
}
内容来源于网络,如有侵权,请联系作者删除!