Search in sources :

Example 6 with RedisInputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) RedisInputStream(redis.clients.util.RedisInputStream) Test(org.junit.Test)

Example 7 with RedisInputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) RedisInputStream(redis.clients.util.RedisInputStream) Test(org.junit.Test)

Example 8 with RedisInputStream

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RedisInputStream(redis.clients.util.RedisInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RedisInputStream(redis.clients.util.RedisInputStream) Test(org.junit.Test)

Example 9 with RedisInputStream

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);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket) RedisOutputStream(redis.clients.util.RedisOutputStream) RedisInputStream(redis.clients.util.RedisInputStream) IOException(java.io.IOException) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 10 with RedisInputStream

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);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) RedisOutputStream(redis.clients.util.RedisOutputStream) RedisInputStream(redis.clients.util.RedisInputStream) IOException(java.io.IOException) Socket(java.net.Socket) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Aggregations

RedisInputStream (redis.clients.util.RedisInputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)17 InputStream (java.io.InputStream)17 BufferedInputStream (java.io.BufferedInputStream)13 PipedInputStream (java.io.PipedInputStream)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)4 List (java.util.List)4 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)2 RedisOutputStream (redis.clients.util.RedisOutputStream)2 SSLSocket (javax.net.ssl.SSLSocket)1 JedisBusyException (redis.clients.jedis.exceptions.JedisBusyException)1