use of redis.clients.util.RedisInputStream in project jedis by xetorthio.
the class ProtocolTest method nullMultiBulkReply.
@SuppressWarnings("unchecked")
@Test
public void nullMultiBulkReply() {
InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes());
List<String> response = (List<String>) Protocol.read(new RedisInputStream(is));
assertNull(response);
}
use of redis.clients.util.RedisInputStream in project jedis by xetorthio.
the class ProtocolTest method integerReply.
@Test
public void integerReply() {
InputStream is = new ByteArrayInputStream(":123\r\n".getBytes());
long response = (Long) Protocol.read(new RedisInputStream(is));
assertEquals(123, response);
}
use of redis.clients.util.RedisInputStream in project jedis by xetorthio.
the class ProtocolTest method multiBulkReply.
@SuppressWarnings("unchecked")
@Test
public void multiBulkReply() {
InputStream is = new ByteArrayInputStream("*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n".getBytes());
List<byte[]> response = (List<byte[]>) Protocol.read(new RedisInputStream(is));
List<byte[]> expected = new ArrayList<byte[]>();
expected.add(SafeEncoder.encode("foo"));
expected.add(SafeEncoder.encode("bar"));
expected.add(SafeEncoder.encode("Hello"));
expected.add(SafeEncoder.encode("World"));
assertByteArrayListEquals(expected, response);
}
use of redis.clients.util.RedisInputStream in project jedis by xetorthio.
the class Connection method connect.
public void connect() {
if (!isConnected()) {
try {
socket = new Socket();
// ->@wjw_add
socket.setReuseAddress(true);
// Will monitor the TCP connection is
socket.setKeepAlive(true);
// valid
// Socket buffer Whetherclosed, to
socket.setTcpNoDelay(true);
// ensure timely delivery of data
// Control calls close () method,
socket.setSoLinger(true, 0);
// the underlying socket is closed
// immediately
// <-@wjw_add
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
socket.setSoTimeout(soTimeout);
if (ssl) {
if (null == sslSocketFactory) {
sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
socket = (SSLSocket) sslSocketFactory.createSocket(socket, host, port, true);
if (null != sslParameters) {
((SSLSocket) socket).setSSLParameters(sslParameters);
}
if ((null != hostnameVerifier) && (!hostnameVerifier.verify(host, ((SSLSocket) socket).getSession()))) {
String message = String.format("The connection to '%s' failed ssl/tls hostname verification.", host);
throw new JedisConnectionException(message);
}
}
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
broken = true;
throw new JedisConnectionException("Failed connecting to host " + host + ":" + port, ex);
}
}
}
use of redis.clients.util.RedisInputStream in project cachecloud by sohutv.
the class Connection method connect.
public void connect() {
if (!isConnected()) {
try {
socket = new Socket();
// ->@wjw_add
socket.setReuseAddress(true);
// Will monitor the TCP connection is
socket.setKeepAlive(true);
// valid
// Socket buffer Whetherclosed, to
socket.setTcpNoDelay(true);
// ensure timely delivery of data
// Control calls close () method,
socket.setSoLinger(true, 0);
// the underlying socket is closed
// immediately
// <-@wjw_add
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
socket.setSoTimeout(soTimeout);
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
broken = true;
throw new JedisConnectionException(ex);
}
}
}
Aggregations