debasishg / scala-redis

A scala library for connecting to a redis server, or a cluster of redis nodes using consistent hashing on the client side.
1.02k stars 219 forks source link

Does disconnect really close connection ? #159

Open prvn opened 8 years ago

prvn commented 8 years ago

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 ?

coldfire-x commented 8 years ago

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 }`

edwardyoon commented 5 years ago

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