ios - 在 redis 上使用 ObjCHiredis for ios

标签 ios redis

我的 iOS 应用程序需要使用 Redis,我从 https://github.com/lp/ObjCHiredis 下载了库并在我的电脑上安装了 Redis。然后我创建了一个小程序,看看它是否可行。这是我在下面得到的输出,您可以在 http://pastebin.com/uduB92cf 阅读代码.

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

最佳答案

我不得不在惰性实体化方法中删除订阅 channel 的调用。

-(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;
}

关于ios - 在 redis 上使用 ObjCHiredis for ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10794928/

相关文章:

google-cloud-platform - Cloud Memorystore Redis 高 CPU 使用率

iphone - 使用不同的 XIB 启动应用程序

iphone - 拍摄 iPhone 中视频图标内的视频

python - redis - 使用哈希

amazon-web-services - FIlebeat-Redis-Logstash : Filebeat fast and Logstah slow, logstash 线程?

python - 利用 Redis 进行负载转移

node.js - Nodejs为Redis请求设置超时

ios - 将 RPPreviewController 中的视频保存到特定位置而不是保存到相机胶卷?

ios - 在 Core Data 中加载 csv 文件

ios - 管理以编程方式实例化的 View Controller 的实例