etaty / rediscala

Non-blocking, Reactive Redis driver for Scala (with Sentinel support)
Apache License 2.0
790 stars 143 forks source link

Persistent connections via connection pool to a single redis server? #42

Open gsastry opened 10 years ago

gsastry commented 10 years ago

Hi,

How can I have this client maintain a persistent connection (via a connection pool) to a redis server? Is this possible? I looked at the RedisClientPool but that looks like it round robins requests to a set of servers.

etaty commented 10 years ago

Any redis clients will try to reconnect to the server every 2s if the connection is lost.

gsastry commented 10 years ago

The client opens a connection per request, right? Is there any way to have it open a few connections that serve all the request, and keep the connections persistent?

etaty commented 10 years ago

No the client is always connected to the server. If you use a pool you can dispatch the connexion on many redis server, (or put the same server multiple times in the Seq of redis servers). If you only have one server, and don't need many connexion then you can use a RedisClient.

gsastry commented 10 years ago

Thanks for your prompt and helpful replies. I wasn't aware that the connection is keep-alived. Is there any advantage to putting the same server multiple times in the Seq of redis servers? Will that round robin the request to different connections to the same server (essentially using a connection pool)?

BTW, do you mind pointing me to the code where it's specified as a keep-alive connection?

etaty commented 10 years ago

Yes it will round robin the connections. if your CPU is not already overloaded with just one you can add more for more throughput

gsastry commented 10 years ago

Thanks. Just to confirm, the connections are set as keep-alive=true by default?

kajmagnus commented 8 years ago

Thanks for posting these questions & answers :- ) It wasn't clear to me when & why to use the connection pool, and when not to — so I searched all GitHub issues for "connection" and then I found this topic.

I think it'd make sense to rewrite & include the stuff in this topic in the main readme.

(Some stuff from this topic: https://github.com/etaty/rediscala/issues/22 about how to avoid bad performance when writing async requests, could also be in the main docs perhaps)