本文整理汇总了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;
}
示例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);
}
}
}
示例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;
}
示例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() {
}
};
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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();
}
示例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());
}
}
示例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.
}
}
示例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");
}
示例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;
}