1

I have an aiohttp application(back-end). And I'm using Redis for storing some data. What's the best way to manage Redis connection:

  • Create one when application starts and use it everywhere I need it, so just create one, place it globally and use it in the all methods I need it
  • Every time I need to do something in Redis(insert/read/delete and so on) create a connection, do an action, close the connection.

What's the best one and why? Could you provide some arguments. Thanks in advance.

picKit
  • 412
  • 1
  • 4
  • 14
  • 1
    I would use option 1. That concept is called `database pooling`. You can check much more great answers than mine [here](https://stackoverflow.com/questions/4041114/what-is-database-pooling) – usuario Jan 03 '22 at 14:02
  • Check out some of the demos, tutorials etc. Redis is no different to any other database connection: https://demos.aiohttp.org/en/latest/tutorial.html#creating-connection-engine – Sam Bull Jan 03 '22 at 20:11

0 Answers0