Nikhil Marathe  committed 75d3321

Added macro to generate bulk commands. Also added a post processing stage.

Bulk commands have the last argument length prefixed.
Post processing is required to allow certain commands to interpret the string
reply into something more useful.

  • Participants
  • Parent commits ce1059b

Comments (0)

Files changed (1)

               (command-string (join (cons (upper-case cmd) args-as-strings) " ")) )
           (postprocess cmd (:query r (append command-string redis:CRLF)))))))
+(define (make-bulk-command command)
+  (letex ((fname (sym command)) (cmd command))
+    (define (fname r)
+      (letn ((args-as-strings (map (fn (x) (string x)) (args)))
+            (all-but-last (0 -1 args-as-strings))
+            (last-arg (last args-as-strings))
+            (len-last-arg (string (length last-arg)))
+            (first-line (flat (list (upper-case cmd) all-but-last len-last-arg)))
+            (command-string (join first-line " ")))
+        (postprocess cmd (:query r (join (list command-string last-arg "") redis:CRLF)))))))
+; any replies are always returned as strings
+; certain commands might need to convert them
+(define (postprocess cmd reply)
+  (cond
+    ((= cmd "keys") (parse reply " "))
+    (true reply)))
 (context MAIN)