Xcode 使用hiredis连接redis

Xcode 使用hiredis连接redis

1. 去https://github.com/redis/redis 下载redis源码

cd hiredis

make

make install

 2. 打开xcode 创建一个xcode command line 工程

连接代码如下

#include <stdio.h>
#include <hiredis/hiredis.h>
  
int main(){
    redisContext* conn = redisConnect("127.0.0.1", 6379);
    if(conn->err)
        printf("connection error:%s\n", conn->errstr);

    redisReply* reply = (redisReply*) redisCommand(conn, "set hello world");
    freeReplyObject(reply);
  
    reply = (redisReply*) redisCommand(conn, "get hello");
  
    printf("%s\n", reply->str);
    freeReplyObject(reply);
  
    redisFree(conn);
    return 0;
}

此时没有配置头文件,和链接库会报错。

3. 打开工程的配置文件,对TARGETS进行配置(.xcodeproj)配置如下

 

在右边搜索框中搜索search

在Header Search Paths Debug中 添加 /usr/local/include/

在Library Search Paths Debug中添加/usr/local/lib/

此时依然不能运行,找不到库

4. 添加库

在工程配置文件中点击Build Phrases

在第三个Link Binary With Libraries中添加动态链接库

 在Finder中按Command+Shift+G定位到/usr/local/lib

 添加libhiredis静态或者动态链接库

ok,此时大功告成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

顾文繁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值