scala-redis
scala-redis copied to clipboard
RedisClient is not initialized when the server is restarted.
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
}
}
Thanks for reporting .. I will look into it .. and in case u have fixed it already, a PR will be welcome :-)
Thanks for your quick response.
I tried but a quick solution did not come up. :(
I've run into this problem in production, after redis server restarts - all operations are performed against database 0, causing loss of data