Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.09 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (in-package :redis)
  2.  
  3. (def-cmd WATCH (key) :status "Watch a key.")
  4. (def-cmd UNWATCH () :status "Unwatch any watched keys.")
  5.  
  6. ;; Better support for bulk-multi bodies, more stable
  7. (def-expect-method :multi
  8.   (let ((n (parse-integer reply)))
  9.     (unless (= n -1)
  10.       (loop :repeat n
  11.          :collect (expect :anything)))))
  12.  
  13. ;; HACK: Using this expectation for now until a cleaner pass
  14. (def-cmd UNSUBSCRIBE (&rest chans) :unsubscribe
  15.   "Drain the channel messages then return the list of unsubscriptions.")
  16.  
  17. (defmethod expect ((type (eql :unsubscribe)))
  18.   "Override the unsubscribe return to drain the pending messages,
  19. then read all of the unsubscriptions until zero rather than panic
  20. and fall down crying. >:["
  21.   (let (unsubs (discarded 0))
  22.     (do ((current (redis:expect :multi) (redis:expect :multi)))
  23.         ((and (string-equal (first current) :unsubscribe)
  24.               (= 0 (parse-integer (car (last current)))))
  25.          (progn (push current unsubs)
  26.                 (values unsubs discarded)))
  27.       (if (string-equal (first current) :unsubscribe)
  28.         (push current unsubs)
  29.         (incf discarded)))))