Skip to content

RedisClient is not initialized when the server is restarted. #185

@Seyun

Description

@Seyun

If a redis server restarts, the client connection is not initialized.

When the redis server restarts, the socket connection between the server and the client is lost. So the value of 'connected' in the following code gets to be false, which lets 'connect' method invoked.

https://github.com/debasishg/scala-redis/blob/master/src/main/scala/com/redis/IO.scala#L68

The problem is that 'connect' does not invoke 'initialize' method in it compared to 'reconnect'.

In my case, this makes problems such as

  • 'auth' is not invoked because 'initialize' is not invoked
  • the overridden 'reconnect' is not invoked, which is for re-subscribing channels when reconnected.

FYI, the following is an inherited class from RedisClient for taking a function of 'onReconnect'

class ResilientRedisClient(override val host: String, override val port: Int,
                           override val database: Int = 0, override val secret: Option[Any] = None, override val timeout : Int = 0)
                          (onReconnect:RedisClient => Any) extends RedisClient {
  override def reconnect: Boolean = {
    val result = super.reconnect

    if (result) onReconnect(this)

    result
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions