Skip to content

feature request: allow UNBLOCKing a blocking call before cancelling it to reuse the connection later for better performance #897

Open

Description

@davidxia

👋 My team enables pipelining for specific requests by using ToPipe when building the command object. This gives us the following behavior when a blocking request is made.

This solves the problem of ensuring we don’t open too many connections, but has the downside that every time we cancel a blocking call, the connection is closed. It would be more performant to issue an UNBLOCK command (which tells Redis to stop blocking), and then we can reuse the connection.

Is this a reasonable feature request? If so, are you open to contributions?

Activity

  1. rueian commented on Sep 12, 2025

    @rueian
    Collaborator

    Hi @davidxia, nice to meet you here!

    I think that is a worthwhile optimization! We are open to contributions for sure.

    So, I think the optimization for the blocking .Do() should be done inside this block:

    rueidis/mux.go

    Lines 269 to 271 in 5b78011

    if resp.NonRedisError() != nil { // abort the wire if blocking command return early (ex. context.DeadlineExceeded)
    wire.Close()
    }

    And it should look like the following:

    1. Check whether the cmd is a blocking command or not; If not, then we should close the wire and return it to the pool directly and skip all the following procedures.
    2. Check whether the resp.NonRedisError() is a context error; If not, then we should close the wire and return it to the pool directly and skip all the following procedures.
    3. Check whether wire.Error() is nil or not; if not, then the wire is already closed. We should return the wire to the pool directly and skip all the following procedures.
    4. Now, we can do the UNBLOCK: We don't close the wire and don't return it to the pool in the current m.blocking function. Instead, we need to create another goroutine to send the UNBLOCK command with m.pipeline(context.Background(), unblock) and only return the wire to the pool without closing it when the UNBLOCK command gets a response saying that the wire is unblocked successfully; Otherwise, we still close the wire before returning it to the pool.
  2. davidxia commented on Sep 12, 2025

    @davidxia
    Author

    @rueian yes, I was glad to see you're the maintainer of this project! Thanks so much for the guidance. I'll make a PR soon. 🙏

  3. rueian commented on Oct 3, 2025

    @rueian
    Collaborator

    Hi @davidxia, do you need any help?

  4. davidxia commented on Oct 3, 2025

    @davidxia
    Author

    Hi @davidxia, do you need any help?

    I haven't gotten around to this yet. Will take a look today or early next week!

  5. KartikYZ commented on Oct 6, 2026

    @KartikYZ
    Contributor

    Hi! I've opened a PR that implements the guidance above, #1030.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions