View difference between Paste ID: uduB92cf and 7tG8Mq4e
SHOW: | | - or go back to the newest paste.
1
// ----------- Header --------------
2
#import <UIKit/UIKit.h>
3
#ifdef __APPLE__
4
#include "TargetConditionals.h"
5
#endif
6
#if TARGET_IPHONE_SIMULATOR
7
#import "ObjCHiredis_Simulator.h"
8
#else
9
#import "ObjCHiredis.h"
10
#endif
11
12
@interface MainViewController : UIViewController
13
@property (strong,nonatomic) ObjCHiredis* redis;
14
@end
15
16
// ------------ Body -----------------
17
18
19
//
20
//  MainViewController.m
21
//  RedisVideo
22
//
23
//  Created by Corey Werner on 5/28/12.
24
//  Copyright (c) 2012 appSTUDIO. All rights reserved.
25
//
26
27
#import "MainViewController.h"
28
29
@interface MainViewController ()
30
31
@end
32
33
@implementation MainViewController
34
@synthesize redis;
35
36
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
37
{
38
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
39
    if (self) {
40
        // Custom initialization
41
    }
42
    return self;
43
}
44
45
- (void)viewDidLoad
46
{
47
    [super viewDidLoad];
48
    NSLog(@"loaded");
49
    
50
    // Do any additional setup after loading the view from its nib.
51
    NSString* command = @"hset users:goku powerlevel 9000";
52
    id retVal = [self.redis command:command];
53
    NSLog(@"command sent");
54
    if( [[retVal class] isSubclassOfClass:[NSString class]] )
55
    {
56
        NSLog(@"%@",(NSString*)retVal);
57
    }
58
    else if( [retVal isKindOfClass:[NSArray class]] )
59
    {
60
        for( id foo in retVal )
61
        {
62
            if( [foo isKindOfClass:[NSString class]] )
63
            {
64
                NSLog(@"%@",(NSString*)foo);
65
            }
66
            else if( [foo isKindOfClass:[NSNumber class]] )
67
            {
68
                NSLog(@"%d",[(NSNumber*) foo intValue]);
69
            }
70
        }
71
    }
72
    retVal = [self.redis command:@"hget users:goku powerlevel"];
73
    
74
    NSLog(@"command sent");
75
    
76
    if( !retVal )
77
    {
78
        NSLog(@"no response");
79
    }
80
    else 
81
    {
82
        NSLog(@"there was a response");
83
        if( [retVal isKindOfClass:[NSString class]] )
84
        {
85
            NSLog(@"%@",(NSString*)retVal);
86
        }
87
    }
88
    NSLog(@"command time over");
89
}
90
91
-(ObjCHiredis*) redis
92
{
93
    if(!redis)
94
    {
95
        redis = [ObjCHiredis redis:@"10.0.0.5" on:[NSNumber numberWithInt:6379] db:[NSNumber numberWithInt:0]];
96
        NSLog(@"redis created");
97
        [redis command:@"SUBSCRIBE CHANNELZ"];
98
        id retVal =  [redis command:@"SUBSCRIBE CHANNELZ"];
99
        if( [retVal isKindOfClass:[NSString class]] )
100
        {
101
            NSLog(@"%@",(NSString*)retVal);
102
        }
103
        else if( [retVal isKindOfClass:[NSArray class]] )
104
        {
105
            for (id foo in retVal)
106
            {
107
                NSLog(@"%@",[foo class]);
108
                if( [foo isKindOfClass:[NSString class]] )
109
                {
110
                    NSLog(@"%@",(NSString*)foo);
111
                }
112
                else if( [foo isKindOfClass:[NSNumber class]] )
113
                {
114
                    NSLog(@"%d",[(NSNumber*) foo intValue]);
115
                }
116
            }
117
        }
118
    }
119
    return redis;
120
}
121
122
- (void)viewDidUnload
123
{
124
    [super viewDidUnload];
125
    // Release any retained subviews of the main view.
126
    // e.g. self.myOutlet = nil;
127
}
128
129
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
130
{
131
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
132
}
133
134
@end