应用场景:
公司项目中需要实时更新位置坐标点,从iPhone手机客户端用redis将坐标点实时传输给redis服务端。
实现步骤:
1.从github上下载RedisKit,眼已插好,请传送:https://github.com/dizzus/RedisKit。
2.在本地新建项目newProject,将github上下载的RedisKit文件中的三个子文件夹Hiredis、PromiseKit、RedisKit拖拽到newProject中

- 编译newProject工程(command + B),报错提示修改,将CocoaPromise.h文件中的#import <Cocoa/Cocoa.h> 改为#import <Foundation/Foundation.h>

4.newProject代码配置,直接在Viewcontroller.m中替换如下代码
#import "ViewController.h"
#import "CocoaRedis.h"
@interface ViewController ()
//主机
@property(nonatomic,strong)NSString * host;
//端口号
@property(nonatomic,assign)int port;
//连接密码
@property(nonatomic,strong)NSString * yourPassword;
@property(nonatomic,strong)NSString * key;
@property(nonatomic,strong)NSString * value;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CocoaRedis *redis = [CocoaRedis new];
// Connect to server
[[[[redis connectWithHost:_host port:_port] then:^id(id value) {
return [redis auth: _yourPassword];
}] then:^id(id value) {
// 关于rpush方法是试出来的 看服务端的需要 这个其实也没弄明白
// 关于参数 公司项目用的是key是一个字符串@"order_1234" value是@"[114.00000,22.00000]" 这样的格式
return [redis rpush:_key value:_value];
}] catch:^id(NSError *err) {
NSLog(@"Error: %@", err);
return nil;
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
5.关于redis具体的介绍:http://www.redis.com.cn/
最终要感谢iOS组长大力支持和最终突破,感谢github贡献者написал(а) Дмитрий Бахвалов给我问题的及时回复。
网友评论