当前位置: 首页>>代码示例>>Java>>正文


Java JedisConnectionException类代码示例

本文整理汇总了Java中redis.clients.jedis.exceptions.JedisConnectionException的典型用法代码示例。如果您正苦于以下问题:Java JedisConnectionException类的具体用法?Java JedisConnectionException怎么用?Java JedisConnectionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JedisConnectionException类属于redis.clients.jedis.exceptions包,在下文中一共展示了JedisConnectionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAvailable

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
public boolean isAvailable() {
    for (JedisPool jedisPool : jedisPools.values()) {
        Jedis jedis = jedisPool.getResource();
        boolean isBroken = false;
        try {
            if (jedis.isConnected()) {
                return true; // 至少需单台机器可用
            }
        } catch (JedisConnectionException e) {
            isBroken = true;
        } finally {
            if (isBroken) {
                jedisPool.returnBrokenResource(jedis);
            } else {
                jedisPool.returnResource(jedis);
            }
        }
    }
    return false;
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:21,代码来源:RedisRegistry.java

示例2: onMessage

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
@Override
public void onMessage(String key, String msg) {
    if (logger.isInfoEnabled()) {
        logger.info("redis event: " + key + " = " + msg);
    }
    if (msg.equals(Constants.REGISTER)
            || msg.equals(Constants.UNREGISTER)) {
        try {
            Jedis jedis = jedisPool.getResource();
            boolean isBroken = false;
            try {
                doNotify(jedis, key);
            } catch (JedisConnectionException e){
                isBroken = true;
            } finally {
                if(isBroken){
                    jedisPool.returnBrokenResource(jedis);
                } else {
                    jedisPool.returnResource(jedis);
                }
            }
        } catch (Throwable t) { // TODO 通知失败没有恢复机制保障
            logger.error(t.getMessage(), t);
        }
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:27,代码来源:RedisRegistry.java

示例3: rpop

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
public String rpop(String key) {
    Jedis jedis = null;
    try {
        jedis = getJedis();
        if (jedis == null) {
            logger.error("get jedis failed.");
            return null;
        }
        return jedis.rpop(key);
    } catch (JedisConnectionException e) {
        if (jedis != null) {
            jedis.close();
            jedis = null;
        }
        logger.error("increame connect error:", e);
    } finally {
        returnJedisResource(jedis);
    }
    return null;
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:21,代码来源:JedisUtil.java

示例4: toJedisPool0

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
private JedisPool toJedisPool0() {
    return new JedisPool(new GenericObjectPoolConfig(), this.getHost(), this.getPort(), this.getTimeout(), this.getPassword(), this.getDatabase()) {
        @Override
        public Jedis getResource() {
            try {
                return super.getResource();
            } catch (JedisConnectionException var2) {
                RedisConfig.LOGGER.error(RedisConfig.this.toString(), var2);
                throw new JedisConnectionException(RedisConfig.this.toString(), var2);
            }
        }

        @Override
        public void close() {
        }
    };
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:18,代码来源:RedisConfig.java

示例5: available

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
@Override
public boolean available() {
    for (JedisPool jedisPool : jedisPools.values()) {
        Jedis jedis = jedisPool.getResource();
        try {
            if (jedis.isConnected()) {
                return true; // 至少需单台机器可用
            }
        } catch (JedisConnectionException e) {
        	logger.error("Jedis Connection Exception", e);
        } finally {
        	if(jedis != null){
            	jedis.close();
            }
        }
    }
    return false;
}
 
开发者ID:yu120,项目名称:coon,代码行数:19,代码来源:RedisMreg.java

示例6: disconnect

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
@SuppressWarnings("finally")
public boolean disconnect() {
	if (isConnected()) {
		try {
			outputStream.flush();
			socket.close();
			return true;
		} catch (IOException ex) {
			broken = true;
			throw new JedisConnectionException(ex);
		} finally {
			closeQuietly(socket);
			return true;
		}
	}
	return false;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:18,代码来源:Connection.java

示例7: sendCommand

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
private static void sendCommand(final RedisOutputStream os, final byte[] command, final byte[]... args) {
	try {
		os.write(ASTERISK_BYTE);
		os.writeIntCrLf(args.length + 1);
		os.write(DOLLAR_BYTE);
		os.writeIntCrLf(command.length);
		os.write(command);
		os.writeCrLf();

		for (final byte[] arg : args) {
			os.write(DOLLAR_BYTE);
			os.writeIntCrLf(arg.length);
			os.write(arg);
			os.writeCrLf();
		}
	} catch (IOException e) {
		throw new JedisConnectionException(e);
	}
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:Protocol.java

示例8: process

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
private static Object process(final RedisInputStream is) {

		final byte b = is.readByte();
		if (b == PLUS_BYTE) {
			return processStatusCodeReply(is);
		} else if (b == DOLLAR_BYTE) {
			return processBulkReply(is);
		} else if (b == ASTERISK_BYTE) {
			return processMultiBulkReply(is);
		} else if (b == COLON_BYTE) {
			return processInteger(is);
		} else if (b == MINUS_BYTE) {
			processError(is);
			return null;
		} else {
			throw new JedisConnectionException("Unknown reply: " + (char) b);
		}
	}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:19,代码来源:Protocol.java

示例9: processBulkReply

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
private static byte[] processBulkReply(final RedisInputStream is) {
	final int len = is.readIntCrLf();
	if (len == -1) {
		return null;
	}

	final byte[] read = new byte[len];
	int offset = 0;
	while (offset < len) {
		final int size = is.read(read, offset, (len - offset));
		if (size == -1)
			throw new JedisConnectionException("It seems like server has closed the connection.");
		offset += size;
	}

	// read 2 more bytes for the command delimiter
	is.readByte();
	is.readByte();

	return read;
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:Protocol.java

示例10: process

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
private static Object process(final RedisInputStream is) {

    final byte b = is.readByte();
    if (b == PLUS_BYTE) {
      return processStatusCodeReply(is);
    } else if (b == DOLLAR_BYTE) {
      return processBulkReply(is);
    } else if (b == ASTERISK_BYTE) {
      return processMultiBulkReply(is);
    } else if (b == COLON_BYTE) {
      return processInteger(is);
    } else if (b == MINUS_BYTE) {
      processError(is);
      return null;
    } else {
      throw new JedisConnectionException("Unknown reply: " + (char) b);
    }
  }
 
开发者ID:x7-framework,项目名称:x7,代码行数:19,代码来源:Protocol.java

示例11: scriptExistsWithBrokenConnection

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
@Test
public void scriptExistsWithBrokenConnection() {
  Jedis deadClient = new Jedis(jedis.getClient().getHost(), jedis.getClient().getPort());
  deadClient.auth("foobared");

  deadClient.clientSetname("DEAD");

  ClientKillerUtil.killClient(deadClient, "DEAD");

  // sure, script doesn't exist, but it's just for checking connection
  try {
    deadClient.scriptExists("abcdefg");
  } catch (JedisConnectionException e) {
    // ignore it
  }

  assertEquals(true, deadClient.getClient().isBroken());

  deadClient.close();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:ScriptingCommandsTest.java

示例12: getErrorAfterConnectionReset

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
@Test
public void getErrorAfterConnectionReset() throws Exception {
  class TestConnection extends Connection {
    public TestConnection() {
      super("localhost", 6379);
    }

    protected boolean sendCommand(Command cmd, byte[]... args) {
      return super.sendCommand(cmd, args);
    }
  }

  TestConnection conn = new TestConnection();

  try {
    conn.sendCommand(Command.HMSET, new byte[1024 * 1024 + 1][0]);
    fail("Should throw exception");
  } catch (JedisConnectionException jce) {
    assertEquals("ERR Protocol error: invalid multibulk length", jce.getMessage());
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:ConnectionTest.java

示例13: connectWithShardInfoAndCustomHostnameVerifierByIpAddress

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
/**
 * Tests opening an SSL/TLS connection to redis with a custom hostname
 * verifier. This test should fail because "127.0.0.1" does not match the
 * certificate subject common name and there are no subject alternative names
 * in the certificate.
 */
@Test
public void connectWithShardInfoAndCustomHostnameVerifierByIpAddress() {
  final URI uri = URI.create("rediss://127.0.0.1:6390");
  final SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
  final SSLParameters sslParameters = new SSLParameters();

  HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
  JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
  shardInfo.setPassword("foobared");

  Jedis jedis = new Jedis(shardInfo);
  try {
    jedis.get("foo");
    Assert.fail("The code did not throw the expected JedisConnectionException.");
  } catch (JedisConnectionException e) {
    Assert.assertEquals("The JedisConnectionException does not contain the expected message.",
        "The connection to '127.0.0.1' failed ssl/tls hostname verification.", e.getMessage());
  }

  try {
    jedis.close();
  } catch (Throwable e1) {
    // Expected.
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:32,代码来源:SSLJedisTest.java

示例14: timeoutConnection

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
@Test(expected = JedisConnectionException.class)
public void timeoutConnection() throws Exception {
  jedis = new Jedis("localhost", 6379, 15000);
  jedis.auth("foobared");
  jedis.configSet("timeout", "1");
  Thread.sleep(2000);
  jedis.hmget("foobar", "foo");
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:9,代码来源:JedisTest.java

示例15: get

import redis.clients.jedis.exceptions.JedisConnectionException; //导入依赖的package包/类
public String get(String key) {
    Jedis jedis = null;
    String result = "";
    try {
        jedis = getJedis();
        if (jedis != null) {
            result = jedis.get(key);
        } else {
            logger.error("get opt connection null error!");
        }
    } catch (JedisConnectionException e) {
        if (jedis != null) {
            jedis.close();
            jedis = null;
        }
        logger.error("get value connect error:", e);
    } finally {
        returnJedisResource(jedis);
    }
    return result;
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:22,代码来源:JedisUtil.java


注:本文中的redis.clients.jedis.exceptions.JedisConnectionException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。