When I use ObjCHiredis redis to connect to a invalid IP and Port, it will blocked.
How to set it to nonblock mode? Thx
- (void)setUp {
NSLog(@"begin setUp");
NSString *ip = @"125.124.125.125";
self.redis = [ObjCHiredis redis:ip on:[NSNumber numberWithInt:123] db:[NSNumber numberWithInt:0]];
if(self.redis == nil)
{
NSLog(@"init redis error.");
return ;
}
NSLog(@"end setUp");
}
The easiest way to do this is probably going to be by running the connection on a separate thread and using a block to handle the response back on the main thread.
This is a helper method I regularly use to do any sort of async tasks.
I’ve adapted it so it should work for what you’re trying do: