com.lambdaworks.redis
Class RedisClient

java.lang.Object
  extended by com.lambdaworks.redis.RedisClient

public class RedisClient
extends Object

A scalable thread-safe Redis client. Multiple threads may share one connection provided they avoid blocking and transactional operations such as BLPOP and MULTI/EXEC.

Author:
Will Glozer

Constructor Summary
RedisClient(String host)
          Create a new client that connects to the supplied host on the default port.
RedisClient(String host, int port)
          Create a new client that connects to the supplied host and port.
 
Method Summary
 RedisConnection<String,String> connect()
          Open a new synchronous connection to the redis server that treats keys and values as UTF-8 strings.
<K,V> RedisConnection<K,V>
connect(RedisCodec<K,V> codec)
          Open a new synchronous connection to the redis server.
 RedisAsyncConnection<String,String> connectAsync()
          Open a new asynchronous connection to the redis server that treats keys and values as UTF-8 strings.
<K,V> RedisAsyncConnection<K,V>
connectAsync(RedisCodec<K,V> codec)
          Open a new asynchronous connection to the redis server.
 RedisPubSubConnection<String,String> connectPubSub()
          Open a new pub/sub connection to the redis server that treats keys and values as UTF-8 strings.
<K,V> RedisPubSubConnection<K,V>
connectPubSub(RedisCodec<K,V> codec)
          Open a new pub/sub connection to the redis server.
 void setDefaultTimeout(long timeout, TimeUnit unit)
          Set the default timeout for connections created by this client.
 void shutdown()
          Shutdown this client and close all open connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RedisClient

public RedisClient(String host)
Create a new client that connects to the supplied host on the default port.

Parameters:
host - Server hostname.

RedisClient

public RedisClient(String host,
                   int port)
Create a new client that connects to the supplied host and port. Connection attempts and non-blocking commands will timeout after 60 seconds.

Parameters:
host - Server hostname.
port - Server port.
Method Detail

setDefaultTimeout

public void setDefaultTimeout(long timeout,
                              TimeUnit unit)
Set the default timeout for connections created by this client. The timeout applies to connection attempts and non-blocking commands.

Parameters:
timeout - Default connection timeout.
unit - Unit of time for the timeout.

connect

public RedisConnection<String,String> connect()
Open a new synchronous connection to the redis server that treats keys and values as UTF-8 strings.

Returns:
A new connection.

connectAsync

public RedisAsyncConnection<String,String> connectAsync()
Open a new asynchronous connection to the redis server that treats keys and values as UTF-8 strings.

Returns:
A new connection.

connectPubSub

public RedisPubSubConnection<String,String> connectPubSub()
Open a new pub/sub connection to the redis server that treats keys and values as UTF-8 strings.

Returns:
A new connection.

connect

public <K,V> RedisConnection<K,V> connect(RedisCodec<K,V> codec)
Open a new synchronous connection to the redis server. Use the supplied codec to encode/decode keys and values.

Parameters:
codec - Use this codec to encode/decode keys and values.
Returns:
A new connection.

connectAsync

public <K,V> RedisAsyncConnection<K,V> connectAsync(RedisCodec<K,V> codec)
Open a new asynchronous connection to the redis server. Use the supplied codec to encode/decode keys and values.

Parameters:
codec - Use this codec to encode/decode keys and values.
Returns:
A new connection.

connectPubSub

public <K,V> RedisPubSubConnection<K,V> connectPubSub(RedisCodec<K,V> codec)
Open a new pub/sub connection to the redis server. Use the supplied codec to encode/decode keys and values.

Parameters:
codec - Use this codec to encode/decode keys and values.
Returns:
A new pub/sub connection.

shutdown

public void shutdown()
Shutdown this client and close all open connections. The client should be discarded after calling shutdown.



Copyright © 2013. All Rights Reserved.