python - Should a connection to Redis cluster be made on each Flask request? -


i have flask api, connects redis cluster caching purposes. should creating , tearing down redis connection on each flask api call? or, should try , maintain connection across requests?

my argument against second option should try , keep api stateless possible, , don't know if keeping persistent across request might causes threads race conditions or other side effects.

however, if want persist connection, should saved on session or on application context?

this performance , scale. 2 buzzwords buzzing you'll in fact need persistent connections.

eventual race conditions no different reconnect on every request shouldn't problem. rcs depend on how you're using redis, if it's caching there's not room error.

i understand desired stateless-ness of api client sides pov, not sure mean server side.

i'd suggest put them in application context, not sessions (those become numerous) whereas app context gives optimal 1 connection per process (and created @ startup). scaling way becomes easy-peasy: you'll never have worry hitting max connection counts on redis box (and less multiplexing better).


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -