Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ----------- Header --------------
- #import <UIKit/UIKit.h>
- #ifdef __APPLE__
- #include "TargetConditionals.h"
- #endif
- #if TARGET_IPHONE_SIMULATOR
- #import "ObjCHiredis_Simulator.h"
- #else
- #import "ObjCHiredis.h"
- #endif
- @interface MainViewController : UIViewController
- @property (strong,nonatomic) ObjCHiredis* redis;
- @end
- // ------------ Body -----------------
- //
- // MainViewController.m
- // RedisVideo
- //
- // Created by Corey Werner on 5/28/12.
- // Copyright (c) 2012 appSTUDIO. All rights reserved.
- //
- #import "MainViewController.h"
- @interface MainViewController ()
- @end
- @implementation MainViewController
- @synthesize redis;
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSLog(@"loaded");
- // Do any additional setup after loading the view from its nib.
- NSString* command = @"hset users:goku powerlevel 9000";
- id retVal = [self.redis command:command];
- NSLog(@"command sent");
- if( [[retVal class] isSubclassOfClass:[NSString class]] )
- {
- NSLog(@"%@",(NSString*)retVal);
- }
- else if( [retVal isKindOfClass:[NSArray class]] )
- {
- for( id foo in retVal )
- {
- if( [foo isKindOfClass:[NSString class]] )
- {
- NSLog(@"%@",(NSString*)foo);
- }
- else if( [foo isKindOfClass:[NSNumber class]] )
- {
- NSLog(@"%d",[(NSNumber*) foo intValue]);
- }
- }
- }
- retVal = [self.redis command:@"hget users:goku powerlevel"];
- NSLog(@"command sent");
- if( !retVal )
- {
- NSLog(@"no response");
- }
- else
- {
- NSLog(@"there was a response");
- if( [retVal isKindOfClass:[NSString class]] )
- {
- NSLog(@"%@",(NSString*)retVal);
- }
- }
- NSLog(@"command time over");
- }
- -(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;
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement