My question is very simple; should I create a redis
instance the moment I need it, like inside a function, or create it once globally and reuse it?
My question is very simple; should I create a redis
instance the moment I need it, like inside a function, or create it once globally and reuse it?
2
Answers
Better way is to create it once and inject it wherever you need it.
Since you want lowest latency from Redis, you don’t want to depend on connection times but instead only round trip command processing times. It’s best to create a persistent connection then reuse that connection over a prolonged period of time to communicate with your Redis server.