Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added connection timeout argument to Client.

  • Loading branch information...
commit c9d4d7268f2c5244f36a61cc0208eb52ecfe4b79 1 parent b428511
@wallrat authored
View
7 java/labs/redis/Client.java
@@ -35,6 +35,13 @@ public Client(String host, int port)
protocol = new Connection(SocketFactory.newSocket(host, port));
}
+
+ public Client(String host, int port, int timeout)
+ throws IOException
+ {
+ protocol = new Connection(SocketFactory.newSocket(host, port, timeout));
+ }
+
public Client()
throws IOException
{
View
8 java/labs/redis/SocketFactory.java
@@ -10,11 +10,17 @@
public class SocketFactory
{
- public static final int timeout = 10000;
+ public static final int TIMEOUT = 10000;
public static Socket newSocket(String host, int port)
throws IOException
{
+ return newSocket(host,port,SocketFactory.TIMEOUT);
+ }
+
+ public static Socket newSocket(String host, int port, int timeout)
+ throws IOException
+ {
final Socket socket = new Socket();
socket.setReuseAddress(true);
View
10 src/labs/redis/core.clj
@@ -23,9 +23,11 @@
(defn client
"Creates and returns an Redis client"
- ([] (Client.))
- ([{:keys [host port] :as opts}]
- (Client. ^String host ^int port)))
+ ([] (client {}))
+ ([{:keys [host port timeout]
+ :or {host "localhost" port 6379 timeout 10000}
+ :as opts}]
+ (Client. ^String host ^int port ^int timeout)))
(defn pool
"Creates and returns a pool of Redis clients"
@@ -65,7 +67,7 @@
(when reply
(condp instance? reply
byte-array-class (String. ^bytes reply)
- BulkReply (String. (.bytes ^BulkReply reply))
+ BulkReply (let [bs (.bytes ^BulkReply reply)] (when bs (String. bs)))
java.lang.Object (.toString ^java.lang.Object reply))))
(defn ->strs [reply]
Please sign in to comment.
Something went wrong with that request. Please try again.