Commits

Nikhil Marathe committed 9784af0

Implemented bulk reply handler

Comments (0)

Files changed (1)

     (list message (length (r 2)))))
 
 (define (redis:handle-bulk-reply r)
-  (list (r 2) (length (r 2))))
+  (letn ((parts (parse (r 2) redis:CRLF)) ; $n\r\n.*\r\n
+        (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
+        (begin
+          (if (<= reply-len (length (parts 1))) ; if we don't need to read more
+                (begin
+                  (letn ((replystring (0 reply-len (parts 1))) ; the .* part on the next line onwards
+                        (read-len (+ (length (parts 0))
+                                    reply-len
+                                    (* 2 (length redis:CRLF))))) ; 2 times because \r\n on each line
+                    (list replystring read-len)))
+            (redis:read r)))))))
 
 (define (redis:handle-error r)
   (throw-error (1 (chop (r 2) 2))))