 
           done  (fn [mid & [backoff-ms]] (wcar conn
                                            (hset-backoff mid backoff-ms)
-                                           (car/sadd (qk :recently-done) mid)))
+                                           (car/sadd (qk :gc) mid)))
 
           retry (fn [mid & [backoff-ms]] (wcar conn
                                            (hset-backoff mid backoff-ms)

    redis.call('lpush', _:qk-mid-circle, _:mid)
    return {_:mid} -- Wrap to distinguish from error replies
    "
    {:qk-messages      (qkey qname :messages)
     :qk-locks         (qkey qname :locks)
     :qk-backoffs      (qkey qname :backoffs)
     :qk-mid-circle    (qkey qname :mid-circle)
     :qk-recently-done (qkey qname :recently-done)}
    {:now           (System/currentTimeMillis)
     :mid           (or unique-message-id (str (java.util.UUID/randomUUID)))
     :mcontent      (car/freeze message)})

    local lock_exp    = tonumber(redis.call('hget', _:qk-locks,    _:mid) or 0)
    local backoff_exp = tonumber(redis.call('hget', _:qk-backoffs, _:mid) or 0)

    if redis.call('hexists', _:qk-msgs, _:mid) ~= 1 then
      if (now < backoff_exp) then return 'done-with-backoff' end
      return nil
    else
      if redis.call('sismember', _:qk-gc, _:mid) == 1 then
        if (now < backoff_exp) then return 'done-with-backoff' end
        return 'done-awaiting-gc'
      else
        if     (now < lock_exp)    then return 'locked'
        elseif (now < backoff_exp) then return 'retry-backoff' end
        return 'queued'
      end
    end"
    {:qk-msgs     (qkey qname :msgs)
     :qk-locks    (qkey qname :locks)
     :qk-backoffs (qkey qname :backoffs)
     :qk-gc       (qkey qname :gc)}
    {:now (System/currentTimeMillis)
     :mid mid})))

