Nordix / hiredis-cluster

C client library for Valkey/Redis Cluster. This project is used and sponsored by Ericsson. It is a fork of the now unmaintained hiredis-vip.
BSD 3-Clause "New" or "Revised" License
88 stars 43 forks source link

redisClusterAsyncConnect() timeout option #92

Closed SS-TruMinds closed 2 years ago

SS-TruMinds commented 2 years ago

We have noticed that redisClusterAsyncConnect() blocks if the server is unavailable/unreachable. We understand that the timeout option is available for commands only after context creation, but is there a way to make redisClusterAsyncConnect() return error if the connection creation has not succeeded after a certain amount of time?

Thank you.

bjosv commented 2 years ago

Setting the option redisClusterSetOptionConnectTimeout() should work for connection timeouts. There is a testcase which uses an alternative connect API, but should work in a similar fashion. https://github.com/Nordix/hiredis-cluster/blob/6c0aecfcf1df378494e81fa69f2645eb4c5e6de1/tests/ct_connection.c#L498-L521

SS-TruMinds commented 2 years ago

Great, we will try this out. Thank you for the support.

SS-TruMinds commented 2 years ago

We have tried as in the example you mentioned & async connection timeout works with redisClusterConnect2(). But doesn't work with redisClusterAsyncConnect(). Could you please let us know if that is expected? Thank you.

bjosv commented 2 years ago

Since redisClusterAsyncConnect() both creates the context and perform a connection attempt you will not be able to configure the timeout for this attempt. So this is currently expected and the above example is your way forward I believe.

SS-TruMinds commented 2 years ago

Ok, the example works for us. Thank you.