2012-05-29 49 views
0

我需要將Redis用於我的iOS應用,並且我從https://github.com/lp/ObjCHiredis下載了這些庫,並在我的計算機上安裝了Redis。然後我創建了一個小程序,看看它是否可行。這裏是我得到的輸出,你可以在http://pastebin.com/uduB92cf閱讀代碼。在Redis上使用ObjCHiredis for ios

2012-05-29 10:32:34.186 RedisVideo[19023:707] loaded 
2012-05-29 10:32:34.262 RedisVideo[19023:707] redis created 
2012-05-29 10:32:34.276 RedisVideo[19023:707] __NSCFString 
2012-05-29 10:32:34.277 RedisVideo[19023:707] subscribe 
2012-05-29 10:32:34.280 RedisVideo[19023:707] __NSCFString 
2012-05-29 10:32:34.281 RedisVideo[19023:707] CHANNELZ 
2012-05-29 10:32:34.283 RedisVideo[19023:707] __NSCFNumber 
2012-05-29 10:32:34.284 RedisVideo[19023:707] 1 
2012-05-29 10:32:34.290 RedisVideo[19023:707] command sent 
2012-05-29 10:32:34.291 RedisVideo[19023:707] ERR only (P)SUBSCRIBE/(P)UNSUBSCRIBE/QUIT allowed in this context 
2012-05-29 10:32:34.320 RedisVideo[19023:707] command sent 
2012-05-29 10:32:34.321 RedisVideo[19023:707] there was a response 
2012-05-29 10:32:34.323 RedisVideo[19023:707] ERR only (P)SUBSCRIBE/(P)UNSUBSCRIBE/QUIT allowed in this context 
2012-05-29 10:32:34.325 RedisVideo[19023:707] command time over 

回答

0

我不得不刪除調用以訂閱lazy子方法中的頻道。

-(ObjCHiredis*) redis 
{ 
    if(!redis) 
    { 
     redis = [ObjCHiredis redis:@"10.0.0.5" on:[NSNumber numberWithInt:6379] db:[NSNumber numberWithInt:0]]; 
     NSLog(@"redis created"); 
//  [redis command:@"SUBSCRIBE CHANNELZ"]; 
//  id retVal = [redis command:@"SUBSCRIBE CHANNELZ"]; 
//  if([retVal isKindOfClass:[NSString class]]) 
//  { 
//   NSLog(@"%@",(NSString*)retVal); 
//  } 
//  else if([retVal isKindOfClass:[NSArray class]]) 
//  { 
//   for (id foo in retVal) 
//   { 
//    NSLog(@"%@",[foo class]); 
//    if([foo isKindOfClass:[NSString class]]) 
//    { 
//     NSLog(@"%@",(NSString*)foo); 
//    } 
//    else if([foo isKindOfClass:[NSNumber class]]) 
//    { 
//     NSLog(@"%d",[(NSNumber*) foo intValue]); 
//    } 
//   } 
//  } 
    } 
    return redis; 
}