Skip to content

Add support for ping command in Pub/Sub mode #454

@sagaxu

Description

@sagaxu

It's nice to use ping command to check if the connection is still alive.

  • It almost works currently, except
  • RedisConnection.toReceiveChannel is broken.

if ((reply != null && reply.type() == ResponseType.PUSH) || empty) {

  1. run in pubsub mode
  2. call conn.toReceiveChannel, it will pause the stream first, then call ReadStream.fetch(1)
  3. run ping command and redis server reply with pong
  4. the handle in RedisStandaloneConnection didn't dispatch the reply of ping to onMessage
  5. so nobody will call stream.fetch(1), the stream can't receive any more
private class ChannelReadStream<T>(val stream: ReadStream<T>,
                                   val channel: Channel<T>,
                                   context: Context) : Channel<T> by channel, CoroutineScope {

  override val coroutineContext: CoroutineContext = context.dispatcher()

  fun subscribe() {
    stream.endHandler {
      close()
    }
    stream.exceptionHandler { err ->
      close(err)
    }
    stream.handler { event ->
      launch {
        send(event)
        stream.fetch(1)
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions