 (defmethod dispatch :shutdown [connections {:keys [seeds ^Selector selector] :as client} _]
   (throw shutdown-exception))
 
-(defn- register! [{:keys [^SocketChannel channel ^InetSocketAddress address] :as conn} ^Selector selector]
-  (if (.connect channel address)
-    (do (debug address "can be established immediately, registering" channel "with" (ops->str OP_READ))
-        (.register channel selector OP_READ conn))
-    (do (debug address "cannot be established immediately, registering" channel "with" (ops->str OP_CONNECT))
-        (.register channel selector OP_CONNECT conn))))
-
 (defn resolve-connection [{:keys [seeds ^Selector selector connections] :as client} address]
   (or (get @connections address)
-      (let [conn (socket-connection address)]
-        (register! conn selector)
+      (let [{:keys [^SocketChannel channel ^InetSocketAddress address] :as conn} (socket-connection address)]
+        (if (.connect channel address)
+          (do (debug address "can be established immediately, registering" channel "with" (ops->str OP_READ))
+              (.register channel selector OP_READ conn))
+          (do (debug address "cannot be established immediately, registering" channel "with" (ops->str OP_CONNECT))
+              (.register channel selector OP_CONNECT conn)))
         (swap! connections assoc address conn)
         conn)))
 

                          (do (error "parse error" outcome)
                              (fail-connection client conn (ex-info "Error parsing Redis Reply" {})))))))))))

(defn write! [client ^SelectionKey k]
  (let [^SocketChannel channel (.channel k)
        {:keys [^SocketChannel channel ^ConcurrentLinkedDeque read-queue ^LinkedBlockingDeque write-queue] :as conn} (.attachment k)]
    (loop []
      (if-let [op (.pollFirst write-queue)]
        (let [n (.write channel ^ByteBuffer (.payload op))

              (.addFirst dispatch-queue [:resolve (ask op slot) address]))))
      (op reply))))

(defn handle-read! [client ^SelectionKey k]
  (let [^SocketChannel channel (.channel k)
        {:keys [^ConcurrentLinkedDeque read-queue ^ByteBuffer read-buffer] :as conn} (.attachment k)]
    (loop [n (.read channel (doto read-buffer
