Commits

Nikhil Marathe  committed 47bffd4

Implemented multi-bulk reply handling

  • Participants
  • Parent commits 254f48b

Comments (0)

Files changed (1)

     (setf (r 2) ((reply 1) (r 2)))
     (reply 0)))
 
+(define (redis:handle-unknown-reply r)
+  (throw-error "Unknown reply type " (first (r 2))))
+
 (define (redis:handle-single-reply r)
   (letn ((trimm (chop (r 2) 2))
          (message (1 trimm)))
         (reply-len (int (1 (parts 0)))))  ;<-^
     (begin 
       (if (= -1 reply-len)
-        (list '() (+ (length (parts 0)) (length (parts 1)) (length redis:CRLF))) ; length of $-1 + remnant
+        (list "" (+ (length (parts 0)) (length (parts 1)) (length redis:CRLF))) ; length of $-1 + remnant
         (begin
           (if (<= reply-len (length (parts 1))) ; if we don't need to read more
                 (begin
                     (list replystring read-len)))
             (redis:read r)))))))
 
+(define (redis:handle-multi-bulk-reply r)
+  (letn ( (crlf-index (find redis:CRLF (r 2)))
+          (num (1 (- crlf-index 1) (r 2))) )
+    (case (int num)
+      (-1 (list '() (+ crlf-index (length redis:CRLF))))
+      (nil (redis:read r))
+      (true (begin
+        (setf (r 2) ((+ crlf-index (length redis:CRLF)) (r 2)))
+        (let ((byte-count (+ crlf-index (length redis:CRLF)))
+              (results '()))
+            (dotimes (x (int num))
+              (let (result (redis:handle-bulk-reply r))
+                (setf (r 2) ((result 1) (r 2)))
+                (push (result 0) results -1)
+                (inc byte-count (result 1))))
+            (list results byte-count)))))))
+
 (define (redis:handle-error r)
   (throw-error (1 (chop (r 2) 2))))