I want to initiate the Redis connection as a background task, so that the user need not await for the Redis connection to get established. If Redis connection is not setup or if Redis is unavailable then data shall be fetched from the source, without impacting the user.
The application is an AWS Lambda Web API project. I want to avoid connection delays in individual requests but I don't want to increase the cold startup time by waiting to connect at startup either.
I'm using the StackExchange Redis Client library.
In order to accomplish this, I want to initiate the Redis connection in background task.
the user need not await for the Redis connection to get established
mean? For desktop apps, it means the UI doesn't freeze. Web apps don't freeze while waiting. And what doesin thread safe manner
mean for your code? If you don't modify global state, there's no risk, and a simpleawait myClient.ConnectAsync()
would do, assuming your Redis library has async methods – Panagiotis Kanavos