I have a grpc project and I want to send request between multi server with grpc. so, I want to cache grpcChannels to use every times. How can i save grpcChannels into redis with one key?
Cache grpc channel into Redis Database
I have a grpc project and I want to send request between multi server with grpc. so, I want to cache grpcChannels to use every times. How can i save grpcChannels into redis with one key?
Cache grpc channel into Redis Database
2
Answers
Unfortunately, it is not possible to store and load a grpc channel from Redis. The main resource of a grpc channel is opened connection(s) to the other side (client/server) which are like file descriptors for your app and that is why it can't be load from redis. But this is not a problem: just reuse a channel as much as possible in your app, i.e., do not close a channel after every RPC call (more on this here https://learn.microsoft.com/en-us/aspnet/core/grpc/performance?view=aspnetcore-6.0#reuse-grpc-channels). But it is ok for the app process to create a channel on startup
Refer to this doc from Microsoft about the best practice for using gRPC. A quote from the doc: