vseloved / cl-redis

Redis client for Common Lisp
Other
188 stars 38 forks source link

How get get replay of cmds in 'with-pipelining' #31

Closed cuichaox closed 6 years ago

cuichaox commented 6 years ago

Hello: Can i register a function will be called on each replay after end of pipelining (Wait to get all returned results) .

vseloved commented 6 years ago

Hi, can you provide a more specific example? I guess, the general answer would be to define your own with-pipelining-callback macro similar to the provided with-pipelining one. Something alone these lines:

(defmacro with-pipelining-callback (callback &body body)
  (with-gensyms (type rez)
    `(if *pipelined*
         (progn
           (warn "Already in a pipeline.")
           ,@body)
         (with-reconnect-restart
             (let (*pipeline*)
               (let ((*pipelined* t))
                 ,@body)
               (mapcar (lambda (,type)
                         (let ((,rez (expect ,type)))
                           (funcall ,callback ,rez)
                           ,rez))
                       (reverse *pipeline*)))))))