rediscala icon indicating copy to clipboard operation
rediscala copied to clipboard

Persistent connections via connection pool to a single redis server?

Open gsastry opened this issue 11 years ago • 7 comments

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.

gsastry avatar Jul 28 '14 20:07 gsastry

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

etaty avatar Jul 28 '14 20:07 etaty

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?

gsastry avatar Jul 28 '14 22:07 gsastry

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.

etaty avatar Jul 28 '14 22:07 etaty

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?

gsastry avatar Jul 29 '14 00:07 gsastry

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

etaty avatar Jul 29 '14 10:07 etaty

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

gsastry avatar Jul 29 '14 18:07 gsastry

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)

kajmagnus avatar Apr 12 '16 06:04 kajmagnus