scala-redis icon indicating copy to clipboard operation
scala-redis copied to clipboard

Does disconnect really close connection ?

Open prvn opened this issue 9 years ago • 2 comments
trafficstars

I am having trouble trying to disconnect from Redis. Here is what I am doing

scala> import com.redis._
import com.redis._

scala> val r = new RedisClient("localhost", 4518)
r: com.redis.RedisClient = localhost:4518

scala> r.get("test")
res5: Option[String] = None

scala> r.set("test", "value")
res6: Boolean = true

scala> r.disconnect
res8: Boolean = true

scala> r.get("test")
res9: Option[String] = Some(value)

Even after the disconnect, the client still works ?

prvn avatar Dec 22 '15 21:12 prvn

actually, it willl close the socket, but when you issue another redis command, it will try to reconnect.

`def send[A](command: String, args: Seq[Any])(result: => A)(implicit format: Format): A = try { write(Commands.multiBulk(command.getBytes("UTF-8") +: (args map (format.apply)))) result } catch { case e: RedisConnectionException => if (reconnect) send(command, args)(result) else throw e case e: SocketException => if (reconnect) send(command, args)(result) else throw e }

def send[A](command: String)(result: => A): A = try { write(Commands.multiBulk(List(command.getBytes("UTF-8")))) result } catch { case e: RedisConnectionException => if (reconnect) send(command)(result) else throw e case e: SocketException => if (reconnect) send(command)(result) else throw e }`

coldfire-x avatar Mar 02 '16 07:03 coldfire-x

So, how to disable reconnect option or can I force disconnect?

edwardyoon avatar Jan 03 '19 13:01 edwardyoon