Permalink
Browse files

Added ->cli coercion that mimics output of redis-cli

  • Loading branch information...
1 parent 6508b13 commit 7ef7206d26ccc4111e15831e349233fbfd1ea786 @wallrat committed Oct 1, 2012
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/labs/redis/core.clj
@@ -6,7 +6,7 @@
[clojure.pprint :only (pprint)]
[clojure.java.io :only (resource)])
(:require [clojure.data.json :as json])
- (:import [labs.redis Client ClientPool Reply BulkReply StatusReply MultiBulkReply LinkedReplyFuture]))
+ (:import [labs.redis Client ClientPool Reply ErrorReply IntegerReply BulkReply StatusReply MultiBulkReply LinkedReplyFuture]))
(set! *warn-on-reflection* true)
@@ -82,6 +82,25 @@
Reply (->>str (value r))
java.lang.Object (->str r))))
+(defn ->cli [r]
+ (println (class r))
+ (if (nil? r) "(nil)"
+ (apply str
+ (condp instance? r
+ LinkedReplyFuture (->cli @r)
+ (Class/forName "[B") (->str r)
+
+ BulkReply (->cli @r)
+ StatusReply (->str @r)
+ ErrorReply (str "(error) " (value r))
+ MultiBulkReply (if-let [values (seq (value r))]
+ (interpose "\n" (map #(str "(" %1 ") " (->str %2))
+ (iterate inc 0)
+ values))
+ "(empty list or set)")
+ IntegerReply (str "(integer)" (value r))
+ (->str r)))))
+
;; low level redis protocol fns
(defn- cmd-arg-convert

0 comments on commit 7ef7206

Please sign in to comment.